Skip to content

Commit

Permalink
BREAKING: remove deprecated apple pay methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Jul 31, 2023
1 parent bc2fceb commit 80449d9
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 349 deletions.
74 changes: 0 additions & 74 deletions packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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<bool> get isPlatformPaySupportedListenable {
Expand All @@ -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<bool> 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.
///
Expand Down Expand Up @@ -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<void> presentApplePay({
required ApplePayPresentParams params,
OnDidSetShippingContact? onDidSetShippingContact,
OnDidSetShippingMethod? onDidSetShippingMethod,
}) async {
await _awaitForSettings();
if (!isApplePaySupported.value) {
//throw StripeError<ApplePayError>
//(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<void> confirmApplePayPayment(
String clientSecret,
) async {
await _awaitForSettings();
if (!isApplePaySupported.value) {
//throw StripeError<ApplePayError>
//(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<bool> handleURLCallback(String url) async {
try {
Expand Down Expand Up @@ -718,7 +645,6 @@ class Stripe {
);
}

ValueNotifier<bool>? _isApplePaySupported;
ValueNotifier<bool>? _isPlatformPaySupported;

// Internal use only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -79,13 +78,6 @@ class MethodChannelStripe extends StripePlatform {
.parse(result: result!, successResultKey: 'paymentMethod');
}

@override
Future<void> confirmApplePayPayment(String clientSecret) async {
await _methodChannel.invokeMethod('confirmApplePayPayment', {
'clientSecret': clientSecret,
});
}

@override
Future<PaymentIntent> confirmPayment(
String paymentIntentClientSecret,
Expand Down Expand Up @@ -146,16 +138,6 @@ class MethodChannelStripe extends StripePlatform {
.parse(result: result!, successResultKey: 'paymentIntent');
}

@override
Future<bool> isApplePaySupported() async {
if (!_platformIsIos) {
return false;
}
final isSupported =
await _methodChannel.invokeMethod('isApplePaySupported');
return isSupported ?? false;
}

@override
Future<void> openApplePaySetup() async {
if (!_platformIsIos) {
Expand All @@ -164,55 +146,6 @@ class MethodChannelStripe extends StripePlatform {
await _methodChannel.invokeMethod('openApplePaySetup');
}

@override
Future<void> 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', <String, dynamic>{
'summaryItems': paramsJson['cartItems'],
});
onDidSetShippingContact?.call(contact);
} else if (call.method == 'onDidSetShippingMethod') {
final method =
ApplePayShippingMethod.fromJson(call.arguments['shippingMethod']);
_methodChannel
.invokeMethod('updateApplePaySummaryItems', <String, dynamic>{
'summaryItems': paramsJson['cartItems'],
});
onDidSetShippingMethod?.call(method);
}
});

await _methodChannel.invokeMethod('presentApplePay', paramsJson);
}

@override
Future<void> updateApplePaySummaryItems({
required List<ApplePayCartSummaryItem> summaryItems,
List<ApplePayErrorAddressField>? errorAddressFields,
}) async {
if (!_platformIsIos) {
throw UnsupportedError('Apple Pay is only available for iOS devices');
}
await _methodChannel
.invokeMapMethod<String, dynamic>('updateApplePaySummaryItems', {
'summaryItems': summaryItems.map((e) => e.toJson()).toList(),
'errorAddressFields': errorAddressFields?.map((e) => e.toJson()).toList(),
});
}

@override
Future<PaymentIntent> retrievePaymentIntent(String clientSecret) async {
final result = await _methodChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ abstract class StripePlatform extends PlatformInterface {
PaymentMethodOptions? options,
);

@Deprecated('This method is deprecated use [isPlatformPaySupported] instead')
Future<bool> isApplePaySupported() async => false;

/// Configure the payment sheet using [SetupPaymentSheetParameters] as config.
Future<PaymentSheetPaymentOption?> initPaymentSheet(SetupPaymentSheetParameters params);
Future<PaymentSheetPaymentOption?> initPaymentSheet(
SetupPaymentSheetParameters params);

/// Display the payment sheet.
Future<PaymentSheetPaymentOption?> presentPaymentSheet({
Expand All @@ -67,17 +65,8 @@ abstract class StripePlatform extends PlatformInterface {
Future<void> confirmPaymentSheetPayment();

Future<void> openApplePaySetup();
Future<void> presentApplePay(
ApplePayPresentParams params,
OnDidSetShippingContact? onDidSetShippingContact,
OnDidSetShippingMethod? onDidSetShippingMethod,
);
Future<void> confirmApplePayPayment(String clientSecret);

Future<TokenData> createApplePayToken(Map<String, dynamic> payment);
Future<void> updateApplePaySummaryItems({
required List<ApplePayCartSummaryItem> summaryItems,
List<ApplePayErrorAddressField>? errorAddressFields,
});

Future<bool> handleURLCallback(String url);

Expand Down
Loading

0 comments on commit 80449d9

Please sign in to comment.