Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web support #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions example/.metadata
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.
# This file should be version controlled and should not be manually edited.

version:
revision: eb6d86ee27deecba4a83536aa20f366a6044895c
channel: stable
revision: "9e1c857886f07d342cf106f2cd588bcd5e031bb2"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
- platform: android
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
- platform: ios
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
- platform: linux
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
- platform: macos
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
create_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2
base_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2
- platform: web
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
- platform: windows
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
create_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2
base_revision: 9e1c857886f07d342cf106f2cd588bcd5e031bb2

# User provided section

Expand Down
75 changes: 62 additions & 13 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:coffee_flutter/widgets/payment.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:moyasar/moyasar.dart';

import 'widgets/coffee.dart';
Expand Down Expand Up @@ -29,11 +31,14 @@ class CoffeeShop extends StatefulWidget {

class _CoffeeShopState extends State<CoffeeShop> {
final paymentConfig = PaymentConfig(
publishableApiKey: 'pk_test_r6eZg85QyduWZ7PNTHT56BFvZpxJgNJ2PqPMDoXA',
publishableApiKey: 'pk_test_KjYR9npiw3UJJpwXpvaADS3ut5bKtyC6ip18FeDC',
amount: 100, // SAR 1
description: 'order #1324',
callbackUrl: 'http://localhost:13404/auth.html',
metadata: {'size': '250g'},
creditCard: CreditCardConfig(saveCard: false, manual: false),


applePay: ApplePayConfig(
merchantId: 'merchant.mysr.fghurayri',
label: 'Blue Coffee Beans',
Expand Down Expand Up @@ -70,21 +75,64 @@ class _CoffeeShopState extends State<CoffeeShop> {
backgroundColor: Colors.white,
resizeToAvoidBottomInset: true,
body: Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: ListView(
children: [
const CoffeeImage(),
PaymentMethods(
paymentConfig: paymentConfig,
onPaymentResult: onPaymentResult,
),
],
),
child:
TextButton(
onPressed: onSubmitCcForm,
child: const Text('Pay'),
),
));
}
}


void onSubmitCcForm() async {
final source = CardPaymentRequestSource(

creditCardData: CardFormModel(
name: 'John Doe',
number: '4201320111111010',
month: '05',
year: '2025',cvc:
'100'),
tokenizeCard: (paymentConfig.creditCard as CreditCardConfig).saveCard,
manualPayment: (paymentConfig.creditCard as CreditCardConfig).manual);

final paymentRequest = PaymentRequest(paymentConfig, source);

final result = await Moyasar.pay(
apiKey: paymentConfig.publishableApiKey,
paymentRequest: paymentRequest);



final String transactionUrl =
(result.source as CardPaymentResponseSource).transactionUrl;

if (kIsWeb) {


try {
final result = await FlutterWebAuth2.authenticate(
url: transactionUrl,
callbackUrlScheme: 'auth',

);
final uri = Uri.parse(result);

final status = PaymentStatus.values.byName(uri.queryParameters['status']!);

showToast(context, status);

} on PlatformException catch (e) {
print('PlatformException ${e}');
// setState(() {
// _status = 'Got error: $e';
// });
}
}



}

void showToast(context, status) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
Expand All @@ -94,3 +142,4 @@ void showToast(context, status) {
),
));
}
}
121 changes: 107 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -96,6 +96,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_auth_2:
dependency: transitive
description:
name: flutter_web_auth_2
sha256: ea57000909d0002824179f1e4907c074f39538e86a9e4d93a74b7c37dbaee242
url: "https://pub.dev"
source: hosted
version: "3.0.4"
flutter_web_auth_2_platform_interface:
dependency: transitive
description:
name: flutter_web_auth_2_platform_interface
sha256: "9124824cbd21e12680bf58190e27b77f251c897e80ec81cd557ec1fde9aecabf"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -148,10 +169,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
moyasar:
dependency: "direct main"
description:
Expand Down Expand Up @@ -240,18 +261,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -272,10 +293,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand All @@ -284,6 +305,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
url_launcher:
dependency: transitive
description:
name: url_launcher
sha256: b1c9e98774adf8820c96fbc7ae3601231d324a7d5ebd8babe27b6dfac91357ba
url: "https://pub.dev"
source: hosted
version: "6.2.1"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "31222ffb0063171b526d3e569079cf1f8b294075ba323443fdc690842bfd4def"
url: "https://pub.dev"
source: hosted
version: "6.2.0"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: bba3373219b7abb6b5e0d071b0fe66dfbe005d07517a68e38d4fc3638f35c6d3
url: "https://pub.dev"
source: hosted
version: "6.2.1"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: "9f2d390e096fdbe1e6e6256f97851e51afc2d9c423d3432f1d6a02a8a9a8b9fd"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
url: "https://pub.dev"
source: hosted
version: "3.1.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "980e8d9af422f477be6948bdfb68df8433be71f5743a188968b0c1b887807e50"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "138bd45b3a456dcfafc46d1a146787424f8d2edfbf2809c9324361e58f851cf7"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "7754a1ad30ee896b265f8d14078b0513a4dba28d358eabb9d5f339886f4a1adc"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
vector_graphics:
dependency: transitive
description:
Expand Down Expand Up @@ -320,10 +405,10 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
webview_flutter:
dependency: transitive
description:
Expand Down Expand Up @@ -356,6 +441,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.9.4"
window_to_front:
dependency: transitive
description:
name: window_to_front
sha256: "7aef379752b7190c10479e12b5fd7c0b9d92adc96817d9e96c59937929512aee"
url: "https://pub.dev"
source: hosted
version: "0.0.3"
xml:
dependency: transitive
description:
Expand All @@ -373,5 +466,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.7.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"
17 changes: 17 additions & 0 deletions example/web/auth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<title>Authentication complete</title>
<p>Authentication is complete. If this does not happen automatically, please close the window.</p>
<script>
if (window.opener) {

console.log(window.location.href, window.location.origin);
window.opener.postMessage({
'flutter-web-auth-2': window.location.href
}, window.location.origin);
} else {
localStorage.setItem('flutter-web-auth-2', window.location.href);


}
window.close();
</script>
Binary file added example/web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-maskable-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-maskable-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading