-
Notifications
You must be signed in to change notification settings - Fork 147
➕ Add the success/failure handling from Dart side for Apple Pay #200
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
base: main
Are you sure you want to change the base?
Changes from all commits
a3b1b81
78dfe7b
fcab163
0d8c189
23b63f8
cddc099
1323120
4a48cc8
a06e1ec
cd07e7c
87268b8
8e8e194
8d236bb
122d7ba
b09fd8c
73fa61c
747ff50
b39bddd
15fb1aa
7b64e53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,18 +35,19 @@ class PayMaterialApp extends StatelessWidget { | |
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return const MaterialApp( | ||
| return MaterialApp( | ||
| title: 'Pay for Flutter Demo', | ||
| localizationsDelegates: [ | ||
| localizationsDelegates: const [ | ||
| ...GlobalMaterialLocalizations.delegates, | ||
| GlobalWidgetsLocalizations.delegate, | ||
| ], | ||
| supportedLocales: [ | ||
| supportedLocales: const [ | ||
| Locale('en', ''), | ||
| Locale('es', ''), | ||
| Locale('de', ''), | ||
| ], | ||
| home: PaySampleApp(), | ||
| theme: ThemeData.light(), | ||
| home: const PaySampleApp(), | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -64,16 +65,23 @@ class _PaySampleAppState extends State<PaySampleApp> { | |
| @override | ||
| void initState() { | ||
| super.initState(); | ||
| _googlePayConfigFuture = | ||
| PaymentConfiguration.fromAsset('default_google_pay_config.json'); | ||
| _googlePayConfigFuture = PaymentConfiguration.fromAsset( | ||
| 'default_google_pay_config.json', | ||
| ); | ||
| } | ||
|
|
||
| void onGooglePayResult(paymentResult) { | ||
| debugPrint(paymentResult.toString()); | ||
| } | ||
|
|
||
| void onApplePayResult(paymentResult) { | ||
| void onApplePayResult(paymentResult, ApplePaymentConfirmation handler) async { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression that we decided to go with the alternative callback approach (see comment and let me know)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah okay, not sure why i did it with one method, but basically i need to keep the old method and have this new method also, right? just want to make sure 😁 |
||
| debugPrint(paymentResult.toString()); | ||
|
|
||
| // This is where the payment result is fetched from the backend, and the | ||
| // payment result is updated accordingly. | ||
| bool isPaymentSuccessfull = true; | ||
|
|
||
| await handler.updatePaymentResult(isPaymentSuccessfull); | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -128,23 +136,25 @@ class _PaySampleAppState extends State<PaySampleApp> { | |
| ), | ||
| // Example pay button configured using an asset | ||
| FutureBuilder<PaymentConfiguration>( | ||
| future: _googlePayConfigFuture, | ||
| builder: (context, snapshot) => snapshot.hasData | ||
| ? GooglePayButton( | ||
| paymentConfiguration: snapshot.data!, | ||
| paymentItems: _paymentItems, | ||
| type: GooglePayButtonType.buy, | ||
| margin: const EdgeInsets.only(top: 15.0), | ||
| onPaymentResult: onGooglePayResult, | ||
| loadingIndicator: const Center( | ||
| child: CircularProgressIndicator(), | ||
| ), | ||
| ) | ||
| : const SizedBox.shrink()), | ||
| future: _googlePayConfigFuture, | ||
| builder: (context, snapshot) => snapshot.hasData | ||
| ? GooglePayButton( | ||
| paymentConfiguration: snapshot.data!, | ||
| paymentItems: _paymentItems, | ||
| type: GooglePayButtonType.buy, | ||
| margin: const EdgeInsets.only(top: 15.0), | ||
| onPaymentResult: onGooglePayResult, | ||
| loadingIndicator: const Center( | ||
| child: CircularProgressIndicator(), | ||
| ), | ||
| ) | ||
| : const SizedBox.shrink(), | ||
| ), | ||
| // Example pay button configured using a string | ||
| ApplePayButton( | ||
| paymentConfiguration: PaymentConfiguration.fromJsonString( | ||
| payment_configurations.defaultApplePay), | ||
| payment_configurations.defaultApplePay, | ||
| ), | ||
| paymentItems: _paymentItems, | ||
| style: ApplePayButtonStyle.black, | ||
| type: ApplePayButtonType.buy, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.