From 1c75fe472a30a2843277b138aefc2199640a385a Mon Sep 17 00:00:00 2001 From: Dennis Cornwell Date: Wed, 25 Sep 2024 04:03:58 -0400 Subject: [PATCH 1/3] Fix a couple issues that arose in platform pay on web after the package:web upgrade (#1917) * Restore call to preventDefaul on payment request button * * Fix marshaling of paymentRequest complete function args * --- .../lib/src/js/payment_requests/payment_request.dart | 2 +- .../stripe_web/lib/src/widgets/platform_pay_button.dart | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/stripe_js/lib/src/js/payment_requests/payment_request.dart b/packages/stripe_js/lib/src/js/payment_requests/payment_request.dart index eb0190acd..fca5def37 100644 --- a/packages/stripe_js/lib/src/js/payment_requests/payment_request.dart +++ b/packages/stripe_js/lib/src/js/payment_requests/payment_request.dart @@ -62,7 +62,7 @@ extension type JsPaymentResponse._(JSObject o) { @JS('complete') external JSFunction get _complete; void Function(String) get complete { - return (String val) => _complete.callAsFunction(val.toJS); + return _complete.dartify() as void Function(String); } } diff --git a/packages/stripe_web/lib/src/widgets/platform_pay_button.dart b/packages/stripe_web/lib/src/widgets/platform_pay_button.dart index b169d64cd..fe811abeb 100644 --- a/packages/stripe_web/lib/src/widgets/platform_pay_button.dart +++ b/packages/stripe_web/lib/src/widgets/platform_pay_button.dart @@ -1,13 +1,11 @@ import 'dart:js_interop'; - -import 'package:web/web.dart' as web; import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:flutter_stripe_web/flutter_stripe_web.dart'; import 'package:flutter_stripe_web/src/parser/payment_request.dart'; - import 'package:stripe_js/stripe_js.dart'; +import 'package:web/web.dart' as web; const kPlatformPayButtonDefaultHeight = 40.0; @@ -76,7 +74,7 @@ class _WebPlatformPayButtonState extends State { height: '${constraints.maxHeight}px', )))) ..on('click', (event) { - //callMethod(event, 'preventDefault', []); + event.toDart['preventDefault'](); widget.onPressed(); }) ..mount('#platform-pay-button'.toJS); From 0b4469af1413c59ee7210634a91965aab4b7ad01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mon?= Date: Wed, 25 Sep 2024 09:04:16 +0100 Subject: [PATCH 2/3] Fix 1912 can add card to wallet (#1932) * fix: #1912 wallet parsing * chore(release): publish packages - stripe_platform_interface@11.1.1 --------- Co-authored-by: Remon --- CHANGELOG.md | 30 +++++ .../customer_sheet/customer_sheet_screen.dart | 3 +- .../others/can_add_to_wallet_screen.dart | 106 ++++++++++++++++++ example/lib/screens/screens.dart | 9 ++ .../macos/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- packages/stripe/pubspec.yaml | 2 +- .../stripe_platform_interface/CHANGELOG.md | 4 + .../lib/src/method_channel_stripe.dart | 20 ++-- .../stripe_platform_interface/pubspec.yaml | 2 +- packages/stripe_web/pubspec.yaml | 2 +- 11 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 example/lib/screens/others/can_add_to_wallet_screen.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d90f24d9..e70359aec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,36 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 2024-09-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`stripe_platform_interface` - `v11.1.1`](#stripe_platform_interface---v1111) + - [`flutter_stripe` - `v11.1.1`](#flutter_stripe---v1111) + - [`flutter_stripe_web` - `v6.1.1`](#flutter_stripe_web---v611) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_stripe` - `v11.1.1` + - `flutter_stripe_web` - `v6.1.1` + +--- + +#### `stripe_platform_interface` - `v11.1.1` + + - **FIX**: #1912 wallet parsing. + + ## 2024-09-18 ### Changes diff --git a/example/lib/screens/customer_sheet/customer_sheet_screen.dart b/example/lib/screens/customer_sheet/customer_sheet_screen.dart index 4410a98d6..d49262e23 100644 --- a/example/lib/screens/customer_sheet/customer_sheet_screen.dart +++ b/example/lib/screens/customer_sheet/customer_sheet_screen.dart @@ -87,8 +87,9 @@ class _CustomerSheetScreenState extends State { await Stripe.instance.initCustomerSheet( customerSheetInitParams: CustomerSheetInitParams( // Main params - setupIntentClientSecret: data['setupIntent'], + // setupIntentClientSecret: data['setupIntent'], merchantDisplayName: 'Flutter Stripe Store Demo', + allowsRemovalOfLastSavedPaymentMethod: true, // Customer params customerId: data['customer'], customerEphemeralKeySecret: data['ephemeralKeySecret'], diff --git a/example/lib/screens/others/can_add_to_wallet_screen.dart b/example/lib/screens/others/can_add_to_wallet_screen.dart new file mode 100644 index 000000000..96814f67b --- /dev/null +++ b/example/lib/screens/others/can_add_to_wallet_screen.dart @@ -0,0 +1,106 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_stripe/flutter_stripe.dart'; +import 'package:stripe_example/utils.dart'; +import 'package:stripe_example/widgets/example_scaffold.dart'; +import 'package:stripe_example/widgets/loading_button.dart'; +import 'package:stripe_example/widgets/response_card.dart'; + +class CanAddToWalletScreen extends StatefulWidget { + @override + _CanAddToWalletScreenState createState() => _CanAddToWalletScreenState(); +} + +class _CanAddToWalletScreenState extends State { + late TextEditingController _controller; + CanAddCardToWalletResult? canAddCardToWallet; + IsCardInWalletResult? isCardInWallet; + + @override + void initState() { + _controller = TextEditingController(); + super.initState(); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return ExampleScaffold( + title: 'Can add card to wallet', + tags: ['Provisioning'], + padding: EdgeInsets.all(16), + children: [ + TextField( + controller: _controller, + decoration: InputDecoration( + border: OutlineInputBorder(), + labelText: 'Last4', + ), + ), + SizedBox(height: 20), + LoadingButton( + onPressed: () async { + final tmp = await _handleCanAddToWallet(_controller.text); + setState(() { + canAddCardToWallet = tmp; + }); + }, + text: 'Can add card to Wallet', + ), + SizedBox(height: 20), + LoadingButton( + onPressed: () async { + final tmp = await _isCardInToWallet(_controller.text); + setState(() { + isCardInWallet = tmp; + }); + }, + text: 'Is card in Wallet', + ), + SizedBox(height: 20), + if (canAddCardToWallet != null || isCardInWallet != null) + ResponseCard( + response: canAddCardToWallet?.toJson().toPrettyString() ?? + isCardInWallet?.toJson().toPrettyString() ?? + '', + ) + ], + ); + } + + Future _handleCanAddToWallet(String last4) async { + try { + final result = await Stripe.instance.canAddCardToWallet( + CanAddCardToWalletParams( + cardLastFour: last4, + ), + ); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Can add card to wallet: ${result}')), + ); + return result; + } catch (e) { + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text('Error: $e'))); + rethrow; + } + } + + Future _isCardInToWallet(String last4) async { + try { + final result = await Stripe.instance.isCardInWallet(last4); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Can add card to wallet: ${result}')), + ); + return result; + } catch (e) { + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text('Error: $e'))); + rethrow; + } + } +} diff --git a/example/lib/screens/screens.dart b/example/lib/screens/screens.dart index 6fdf97ece..6743974db 100644 --- a/example/lib/screens/screens.dart +++ b/example/lib/screens/screens.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:stripe_example/screens/customer_sheet/customer_sheet_screen.dart'; +import 'package:stripe_example/screens/others/can_add_to_wallet_screen.dart'; import 'package:stripe_example/screens/payment_sheet/payment_element/payment_element.dart'; import 'package:stripe_example/screens/payment_sheet/payment_sheet_deffered_screen.dart'; import 'package:stripe_example/screens/payment_sheet/payment_sheet_screen.dart'; @@ -368,6 +369,14 @@ class Example extends StatelessWidget { DevicePlatform.web, ], ), + Example( + title: 'Can add card to wallet', + builder: (context) => CanAddToWalletScreen(), + platformsSupported: [ + DevicePlatform.android, + DevicePlatform.ios, + ], + ), ]), ]; } diff --git a/example/macos/Runner.xcodeproj/project.pbxproj b/example/macos/Runner.xcodeproj/project.pbxproj index 71c9c0fe7..bbce8f0ed 100644 --- a/example/macos/Runner.xcodeproj/project.pbxproj +++ b/example/macos/Runner.xcodeproj/project.pbxproj @@ -202,7 +202,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 33CC10EC2044A3C60003C045 = { diff --git a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 7fd7126b0..ec9aa6bb9 100644 --- a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ canAddCardToWallet( CanAddCardToWalletParams params) async { - final result = await _methodChannel.invokeMethod('canAddCardToWallet', { + final result = await _methodChannel + .invokeMapMethod('canAddCardToWallet', { 'params': params.toJson(), }); + if (result!['error'] != null) { + throw StripeException.fromJson(result); + } - return ResultParser( - parseJson: (json) => CanAddCardToWalletResult.fromJson(json)) - .parse(result: result!, successResultKey: 'canAddCardToWalletResult'); + return CanAddCardToWalletResult.fromJson(result); } @override Future isCardInWallet(String cardLastFour) async { - final result = await _methodChannel.invokeMethod('canAddCardToWallet', { + final result = await _methodChannel + .invokeMapMethod('isCardInWallet', { 'params': {'cardLastFour': cardLastFour}, }); + if (result!['error'] != null) { + throw StripeException.fromJson(result); + } - return ResultParser( - parseJson: (json) => IsCardInWalletResult.fromJson(json)) - .parse(result: result!, successResultKey: 'canAddCardToWalletResult'); + return IsCardInWalletResult.fromJson(result); } } diff --git a/packages/stripe_platform_interface/pubspec.yaml b/packages/stripe_platform_interface/pubspec.yaml index 4e7a21ca5..19ad4f90f 100644 --- a/packages/stripe_platform_interface/pubspec.yaml +++ b/packages/stripe_platform_interface/pubspec.yaml @@ -1,6 +1,6 @@ name: stripe_platform_interface description: Platform interface for stripe sdk -version: 11.1.0 +version: 11.1.1 repository: https://github.com/flutter-stripe/flutter_stripe homepage: https://pub.dev/packages/flutter_stripe diff --git a/packages/stripe_web/pubspec.yaml b/packages/stripe_web/pubspec.yaml index 27d7a9a20..f0d10e1c2 100644 --- a/packages/stripe_web/pubspec.yaml +++ b/packages/stripe_web/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: flutter_web_plugins: sdk: flutter freezed_annotation: ^2.0.3 - stripe_platform_interface: ^11.1.0 + stripe_platform_interface: ^11.1.1 stripe_js: ^6.1.0 web: ^1.0.0 From b1fe7117190ad9d9496cb888fc56faae348310d9 Mon Sep 17 00:00:00 2001 From: janakankathir <55894815+janakankathir@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:04:31 +0200 Subject: [PATCH 3/3] fixed automaticAsync parsing error (#1903) --- packages/stripe_web/lib/src/parser/payment_intent.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/stripe_web/lib/src/parser/payment_intent.dart b/packages/stripe_web/lib/src/parser/payment_intent.dart index d15ec1611..4d3bb9863 100644 --- a/packages/stripe_web/lib/src/parser/payment_intent.dart +++ b/packages/stripe_web/lib/src/parser/payment_intent.dart @@ -14,8 +14,7 @@ extension PaymentIntentExtension on js.PaymentIntent { latestCharge: latestCharge, //paymentMethodId: payment_method, captureMethod: CaptureMethodExtension.parse(captureMethod.name), - confirmationMethod: - ConfirmationMethodExtension.parse(confirmationMethod.name), + confirmationMethod: ConfirmationMethodExtension.parse(confirmationMethod.name), // description: description, // receiptEmail: receipt_email, @@ -75,6 +74,7 @@ extension CaptureMethodExtension on CaptureMethod { case 'automatic': return CaptureMethod.Automatic; case 'AutomaticAsync': + case 'automaticAsync': case 'automatic_async': return CaptureMethod.AutomaticAsync; case 'Manual':