From 80449d9e6298646e01b526502f1dd69db8f5d0d6 Mon Sep 17 00:00:00 2001 From: Remon <> Date: Mon, 31 Jul 2023 19:38:48 +0100 Subject: [PATCH] BREAKING: remove deprecated apple pay methods --- packages/stripe/lib/src/stripe.dart | 74 -------- .../lib/src/method_channel_stripe.dart | 67 ------- .../lib/src/stripe_platform_interface.dart | 17 +- .../test/method_channel_stripe_test.dart | 166 ------------------ packages/stripe_web/lib/src/web_stripe.dart | 30 +--- 5 files changed, 5 insertions(+), 349 deletions(-) diff --git a/packages/stripe/lib/src/stripe.dart b/packages/stripe/lib/src/stripe.dart index 297fb7676..859ceb6ff 100644 --- a/packages/stripe/lib/src/stripe.dart +++ b/packages/stripe/lib/src/stripe.dart @@ -110,19 +110,6 @@ class Stripe { setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid, ); - /// Exposes a [ValueListenable] whether or not Apple pay is supported for this - /// device. - /// - /// Always returns false on non Apple platforms. - @Deprecated('Use [isPlatformPaySupportedListenable] instead.') - ValueListenable get isApplePaySupported { - if (_isApplePaySupported == null) { - _isApplePaySupported = ValueNotifier(false); - checkApplePaySupport(); - } - return _isApplePaySupported!; - } - /// Exposes a [ValueListenable] whether or not GooglePay (on Android) or Apple Pay (on iOS) /// is supported for this device. ValueListenable get isPlatformPaySupportedListenable { @@ -133,18 +120,6 @@ class Stripe { return _isPlatformPaySupported!; } - ///Checks if Apple pay is supported on this device. - /// - /// Always returns false on non Apple devices. - @Deprecated('Use [isPlatformPaySupported] instead') - Future checkApplePaySupport() async { - await _awaitForSettings(); - final isSupported = await _platform.isApplePaySupported(); - _isApplePaySupported ??= ValueNotifier(false); - _isApplePaySupported?.value = isSupported; - return isSupported; - } - /// Check if the relevant native wallet (Apple Pay on iOS and Google Pay on Android) /// is supported. /// @@ -349,54 +324,6 @@ class Stripe { await _platform.openApplePaySetup(); } - /// Presents an Apple payment sheet using [params] for additional - /// configuration. See [ApplePayPresentParams] for more details. - /// - /// Throws an [StripeError] in case presenting the payment sheet fails. - @Deprecated( - 'Use either [confirmPlatformPaySetupIntent] or [confirmPlatformPayPaymentIntent].') - Future presentApplePay({ - required ApplePayPresentParams params, - OnDidSetShippingContact? onDidSetShippingContact, - OnDidSetShippingMethod? onDidSetShippingMethod, - }) async { - await _awaitForSettings(); - if (!isApplePaySupported.value) { - //throw StripeError - //(ApplePayError.canceled, 'APPLE_PAY_NOT_SUPPORTED_MESSAGE'); - } - try { - await _platform.presentApplePay( - params, - onDidSetShippingContact, - onDidSetShippingMethod, - ); - } on StripeError { - rethrow; - } - } - - /// Confirms the Apple pay payment using the provided [clientSecret]. - /// Use this method when the form is being submitted. - /// - /// Throws an [StripeError] in confirming the payment fails. - @Deprecated( - 'Use [confirmPlatformPaySetupIntent] or [confirmPlatformPayPaymentIntent].') - Future confirmApplePayPayment( - String clientSecret, - ) async { - await _awaitForSettings(); - if (!isApplePaySupported.value) { - //throw StripeError - //(ApplePayError.canceled, 'APPLE_PAY_NOT_SUPPORTED_MESSAGE'); - } - try { - await _platform.confirmApplePayPayment(clientSecret); - } on StripeError { - rethrow; - } - } - /// Handle URL callback from iDeal payment returnUrl to close iOS in-app webview Future handleURLCallback(String url) async { try { @@ -718,7 +645,6 @@ class Stripe { ); } - ValueNotifier? _isApplePaySupported; ValueNotifier? _isPlatformPaySupported; // Internal use only diff --git a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart index f8db5f149..a20806bd0 100644 --- a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart +++ b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart @@ -10,7 +10,6 @@ import 'package:stripe_platform_interface/src/models/wallet.dart'; import 'package:stripe_platform_interface/src/result_parser.dart'; import 'models/app_info.dart'; -import 'models/apple_pay.dart'; import 'models/card_details.dart'; import 'models/errors.dart'; import 'models/payment_intents.dart'; @@ -79,13 +78,6 @@ class MethodChannelStripe extends StripePlatform { .parse(result: result!, successResultKey: 'paymentMethod'); } - @override - Future confirmApplePayPayment(String clientSecret) async { - await _methodChannel.invokeMethod('confirmApplePayPayment', { - 'clientSecret': clientSecret, - }); - } - @override Future confirmPayment( String paymentIntentClientSecret, @@ -146,16 +138,6 @@ class MethodChannelStripe extends StripePlatform { .parse(result: result!, successResultKey: 'paymentIntent'); } - @override - Future isApplePaySupported() async { - if (!_platformIsIos) { - return false; - } - final isSupported = - await _methodChannel.invokeMethod('isApplePaySupported'); - return isSupported ?? false; - } - @override Future openApplePaySetup() async { if (!_platformIsIos) { @@ -164,55 +146,6 @@ class MethodChannelStripe extends StripePlatform { await _methodChannel.invokeMethod('openApplePaySetup'); } - @override - Future presentApplePay( - ApplePayPresentParams params, - OnDidSetShippingContact? onDidSetShippingContact, - OnDidSetShippingMethod? onDidSetShippingMethod, - ) async { - if (!_platformIsIos) { - throw UnsupportedError('Apple Pay is only available for iOS devices'); - } - final paramsJson = params.toJson(); - - _methodChannel.setMethodCallHandler((call) async { - if (call.method == 'onDidSetShippingContact') { - final contact = - ApplePayShippingContact.fromJson(call.arguments['shippingContact']); - _methodChannel - .invokeMethod('updateApplePaySummaryItems', { - 'summaryItems': paramsJson['cartItems'], - }); - onDidSetShippingContact?.call(contact); - } else if (call.method == 'onDidSetShippingMethod') { - final method = - ApplePayShippingMethod.fromJson(call.arguments['shippingMethod']); - _methodChannel - .invokeMethod('updateApplePaySummaryItems', { - 'summaryItems': paramsJson['cartItems'], - }); - onDidSetShippingMethod?.call(method); - } - }); - - await _methodChannel.invokeMethod('presentApplePay', paramsJson); - } - - @override - Future updateApplePaySummaryItems({ - required List summaryItems, - List? errorAddressFields, - }) async { - if (!_platformIsIos) { - throw UnsupportedError('Apple Pay is only available for iOS devices'); - } - await _methodChannel - .invokeMapMethod('updateApplePaySummaryItems', { - 'summaryItems': summaryItems.map((e) => e.toJson()).toList(), - 'errorAddressFields': errorAddressFields?.map((e) => e.toJson()).toList(), - }); - } - @override Future retrievePaymentIntent(String clientSecret) async { final result = await _methodChannel diff --git a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart index 3261f2c27..25b8cf470 100644 --- a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart +++ b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart @@ -49,11 +49,9 @@ abstract class StripePlatform extends PlatformInterface { PaymentMethodOptions? options, ); - @Deprecated('This method is deprecated use [isPlatformPaySupported] instead') - Future isApplePaySupported() async => false; - /// Configure the payment sheet using [SetupPaymentSheetParameters] as config. - Future initPaymentSheet(SetupPaymentSheetParameters params); + Future initPaymentSheet( + SetupPaymentSheetParameters params); /// Display the payment sheet. Future presentPaymentSheet({ @@ -67,17 +65,8 @@ abstract class StripePlatform extends PlatformInterface { Future confirmPaymentSheetPayment(); Future openApplePaySetup(); - Future presentApplePay( - ApplePayPresentParams params, - OnDidSetShippingContact? onDidSetShippingContact, - OnDidSetShippingMethod? onDidSetShippingMethod, - ); - Future confirmApplePayPayment(String clientSecret); + Future createApplePayToken(Map payment); - Future updateApplePaySummaryItems({ - required List summaryItems, - List? errorAddressFields, - }); Future handleURLCallback(String url); diff --git a/packages/stripe_platform_interface/test/method_channel_stripe_test.dart b/packages/stripe_platform_interface/test/method_channel_stripe_test.dart index 55e67698d..939622f43 100644 --- a/packages/stripe_platform_interface/test/method_channel_stripe_test.dart +++ b/packages/stripe_platform_interface/test/method_channel_stripe_test.dart @@ -86,28 +86,6 @@ void main() { }); }); - group('Confirm Apple Pay Payment', () { - setUp(() { - sut = MethodChannelStripe( - platformIsIos: true, - platformIsAndroid: false, - methodChannel: MethodChannelMock( - channelName: methodChannelName, - method: 'confirmApplePayPayment', - result: true, - ).methodChannel, - ); - }); - - test('It completetes successfully', () async { - final completer = Completer(); - await sut.confirmApplePayPayment('secret').then( - (_) => completer.complete(), - ); - expect(completer.isCompleted, true); - }); - }); - group('createApplePayToken', () { late TokenData result; @@ -292,150 +270,6 @@ void main() { }); }); }); - group('isApplePaySupported', () { - late bool result; - - setUp(() async { - sut = MethodChannelStripe( - platformIsIos: true, - platformIsAndroid: false, - methodChannel: MethodChannelMock( - channelName: methodChannelName, - method: 'isApplePaySupported', - result: true, - ).methodChannel, - ); - result = await sut.isApplePaySupported(); - }); - - test('It returns true', () { - expect(result, true); - }); - }); - - group('updateApple pay summary items', () { - group('When platform is ios', () { - late Completer completer; - setUp(() async { - completer = Completer(); - sut = MethodChannelStripe( - platformIsIos: true, - platformIsAndroid: false, - methodChannel: MethodChannelMock( - channelName: methodChannelName, - method: 'updateApplePaySummaryItems', - result: {}, - ).methodChannel, - ); - await sut.updateApplePaySummaryItems(summaryItems: const [ - ApplePayCartSummaryItem.immediate(label: '1', amount: '100'), - ], errorAddressFields: const [ - ApplePayErrorAddressField( - field: ApplePayContactFieldsType.name, - message: 'whoops', - ), - ]).then((_) => completer.complete()); - }); - - test('It completes operation', () { - expect(completer.isCompleted, true); - }); - }); - - group('When platform is not ios', () { - setUp(() async { - sut = MethodChannelStripe( - platformIsIos: false, - platformIsAndroid: true, - methodChannel: MethodChannelMock( - channelName: methodChannelName, - method: 'updateApplePaySummaryItems', - result: true, - ).methodChannel, - ); - }); - - test('It completes operation', () { - expect( - () => sut.updateApplePaySummaryItems(summaryItems: const [ - ApplePayCartSummaryItem.deferred( - label: '1', - amount: '100', - deferredDate: 1234, - ), - ], errorAddressFields: const [ - ApplePayErrorAddressField( - field: ApplePayContactFieldsType.name, - message: 'whoops', - ), - ]), - throwsA(const TypeMatcher()), - ); - }); - }); - }); - - group('presentApplePay', () { - group('When platform is ios', () { - late Completer completer; - setUp(() async { - completer = Completer(); - sut = MethodChannelStripe( - platformIsIos: true, - platformIsAndroid: false, - methodChannel: MethodChannelMock( - channelName: methodChannelName, - method: 'presentApplePay', - result: true, - ).methodChannel, - ); - await sut - .presentApplePay( - const ApplePayPresentParams( - cartItems: [], - country: 'country', - currency: 'currency', - ), - null, - null, - ) - .then((_) => completer.complete()); - }); - - test('It completes operation', () { - expect(completer.isCompleted, true); - }); - }); - - group('When platform is not ios', () { - setUp(() async { - sut = MethodChannelStripe( - platformIsIos: false, - platformIsAndroid: true, - methodChannel: MethodChannelMock( - channelName: methodChannelName, - method: 'presentApplePay', - result: true, - ).methodChannel, - ); - }); - - test('It completes operation', () { - expect( - () => sut.presentApplePay( - const ApplePayPresentParams( - cartItems: [], - country: 'country', - currency: 'currency', - ), - null, - null, - ), - throwsA(const TypeMatcher()), - ); - }); - }); - }); group('retrievePaymentIntent', () { group('When retrievePaymentIntent succeeds', () { diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 01daabab8..3904b66a6 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -315,25 +315,6 @@ class WebStripe extends StripePlatform { throw WebUnsupportedError.method('createTokenForCVCUpdate'); } - @override - Future isApplePaySupported() async { - throw WebUnsupportedError.method('presentApplePay'); - } - - @override - Future presentApplePay( - ApplePayPresentParams params, - OnDidSetShippingContact? onDidSetShippingContact, - OnDidSetShippingMethod? onDidSetShippingMethod, - ) async { - throw WebUnsupportedError.method('presentApplePay'); - } - - @override - Future confirmApplePayPayment(String clientSecret) async { - throw WebUnsupportedError.method('confirmApplePayPayment'); - } - @override Future createApplePayToken(Map payment) { throw WebUnsupportedError.method('createApplePayToken'); @@ -376,7 +357,8 @@ class WebStripe extends StripePlatform { } @override - Future initPaymentSheet(SetupPaymentSheetParameters params) { + Future initPaymentSheet( + SetupPaymentSheetParameters params) { throw WebUnsupportedError.method('initPaymentSheet'); } @@ -462,14 +444,6 @@ class WebStripe extends StripePlatform { throw UnimplementedError(); } - @override - Future updateApplePaySummaryItems({ - required List summaryItems, - List? errorAddressFields, - }) { - throw WebUnsupportedError.method('updateApplePaySummaryItems'); - } - @override Future canAddToWallet(String last4) { throw WebUnsupportedError.method('canAddToWallet');