requestGooglePayPayment method

Future<GooglePayResponse> requestGooglePayPayment({
  1. required String price,
  2. required String currencyCode,
  3. required String countryCode,
  4. required String merchantName,
  5. required String publicId,
})

Requests Apple Pay payment.

price - Total purchase price. The price must use '.' decimal separator, not ','. Fro example '199.99'

currencyCode - Currency code. For example 'RUB'.

countryCode - Country code. For example 'RU'.

merchantName - Your merchant name. Merchant name is rendered in the payment sheet. In TEST environment, or if a merchant isn't recognized, a “Pay Unverified Merchant” message is displayed in the payment sheet.

publicId - Your TipTopPay public id. You can obtain it in your TipTopPay account

Returns GooglePayResponse. You have to check whether response is success and if so, you can obtain payment token by response.token

if (response.isSuccess) {
  final token = response.token;
  // use token for payment by a cryptogram
} else if (response.isError) {
  // show error
} else if (response.isCanceled) {
  // google pay was canceled
}

Implementation

Future<GooglePayResponse> requestGooglePayPayment({
  required String price,
  required String currencyCode,
  required String countryCode,
  required String merchantName,
  required String publicId,
}) async {
  if (Platform.isAndroid) {
    try {
      final dynamic result =
      await _channel.invokeMethod<dynamic>('requestGooglePayPayment', {
        'price': price,
        'currencyCode': currencyCode,
        'countryCode': countryCode,
        'merchantName': merchantName,
        'publicId': publicId,
      });
      return GooglePayResponse.fromMap(result);
    } on PlatformException catch (e) {
      return GooglePayResponse.fromPlatformException(e);
    } catch (e) {
      return GooglePayResponse.fromException();
    }
  } else {
    throw Exception("Google Pay is allowed only on Android");
  }
}