requestApplePay method
Request Apple Pay
cartItems
is the list of items in the cart
currencyCode
is the currency code of the transaction
countryCode
is the country code of the transaction
return ApplePayResult
with value success
as true
if success.
return ApplePayResult
with value success
as false
if fail.
return ApplePayResult
with value message
as String if fail.
return ApplePayResult
with value prime
as String if success.
return null
if the request is incomplete
Implementation
@override
Future<TapPayPrime?> requestApplePay({
required List<CartItem> cartItems,
required String currencyCode,
required String countryCode,
}) async {
if (Platform.isIOS == false) {
return TapPayPrime(
success: false,
message: "Apple Pay is only available on iOS devices.");
}
if (cartItems.isEmpty) {
return TapPayPrime(
success: false, message: "The cart items cannot be empty.");
}
if (currencyCode.isEmpty || currencyCode.length != 3) {
return TapPayPrime(
success: false, message: "The currency code cannot be empty.");
}
if (countryCode.isEmpty || countryCode.length != 2) {
return TapPayPrime(
success: false, message: "The country code cannot be empty.");
}
final result = await methodChannel
.invokeMethod<Map<Object?, Object?>>('requestApplePay', {
'cartItems':
cartItems.map((CartItem cartItem) => cartItem.toMap()).toList(),
'currencyCode': currencyCode,
'countryCode': countryCode,
});
if (result == null) {
return TapPayPrime(
success: false,
message:
"Encountered an unidentified error while requesting Apple Pay.");
} else {
return TapPayPrime.fromMap(Map<String, dynamic>.from(result));
}
}