requestApplePayNonce static method

Future requestApplePayNonce({
  1. required String price,
  2. required String summaryLabel,
  3. required String countryCode,
  4. required String currencyCode,
  5. required ApplePayPaymentType paymentType,
  6. required ApplePayNonceRequestSuccessCallback onApplePayNonceRequestSuccess,
  7. required ApplePayNonceRequestFailureCallback onApplePayNonceRequestFailure,
  8. required ApplePayCompleteCallback onApplePayComplete,
})

Implementation

static Future requestApplePayNonce(
    {required String price,
    required String summaryLabel,
    required String countryCode,
    required String currencyCode,
    required ApplePayPaymentType paymentType,
    required ApplePayNonceRequestSuccessCallback
        onApplePayNonceRequestSuccess,
    required ApplePayNonceRequestFailureCallback
        onApplePayNonceRequestFailure,
    required ApplePayCompleteCallback onApplePayComplete}) async {
  assert(summaryLabel.isNotEmpty, 'summaryLabel should not be empty.');
  assert(price.isNotEmpty, 'price should not be empty.');
  assert(countryCode.isNotEmpty, 'countryCode should not be empty.');
  assert(currencyCode.isNotEmpty, 'currencyCode should not be empty.');

  _applePayNonceRequestSuccessCallback = onApplePayNonceRequestSuccess;
  _applePayNonceRequestFailureCallback = onApplePayNonceRequestFailure;
  _applePayCompleteCallback = onApplePayComplete;

  var paymentTypeString = _standardSerializers.serializeWith(
      ApplePayPaymentType.serializer, paymentType);
  try {
    var params = <String, dynamic>{
      'price': price,
      'summaryLabel': summaryLabel,
      'countryCode': countryCode,
      'currencyCode': currencyCode,
      'paymentType': paymentTypeString,
    };
    await _channel.invokeMethod('requestApplePayNonce', params);
  } on PlatformException catch (ex) {
    throw InAppPaymentsException(
        ex.code,
        ex.message,
        ex.details[InAppPaymentsException.debugCodeKey],
        ex.details[InAppPaymentsException.debugMessageKey]);
  }
}