initGooglePay method

  1. @override
Future<TapPaySdkCommonResult?> initGooglePay({
  1. required String merchantName,
  2. List<TapPayCardAuthMethod>? allowedAuthMethods = kDefaultTapPayAllowedCardAuthMethods,
  3. List<TapPayCardType>? allowedCardTypes = kDefaultTapPayAllowedCardTypes,
  4. bool? isPhoneNumberRequired = false,
  5. bool? isEmailRequired = false,
  6. bool? isBillingAddressRequired = false,
})
override

Initialize Google Pay

merchantName is the name of the merchant. (e.g., "Google Pay Merchant") allowedAuthMethods is the list of allowed authentication methods. Default value is TapPayCardAuthMethod.panOnly and TapPayCardAuthMethod.cryptogram3DS allowedCardTypes is the list of allowed card networks. Default value is TapPayCardType.visa, TapPayCardType.masterCard, TapPayCardType.americanExpress, TapPayCardType.jcb isPhoneNumberRequired is a boolean value to indicate whether to require phone number. Default value is false isEmailRequired is a boolean value to indicate whether to require email. Default value is false isBillingAddressRequired is a boolean value to indicate whether to require billing address. Default value is false

return GooglePayInitResult with value success as true if success. return GooglePayInitResult with value success as false if fail. return GooglePayInitResult with value message as String if fail. return null if the initialization is incomplete

Implementation

@override
Future<TapPaySdkCommonResult?> initGooglePay({
  required String merchantName,
  List<TapPayCardAuthMethod>? allowedAuthMethods =
      kDefaultTapPayAllowedCardAuthMethods,
  List<TapPayCardType>? allowedCardTypes = kDefaultTapPayAllowedCardTypes,
  bool? isPhoneNumberRequired = false,
  bool? isEmailRequired = false,
  bool? isBillingAddressRequired = false,
}) async {
  if (Platform.isAndroid == false) {
    return TapPaySdkCommonResult(
        success: false,
        message: "Google Pay is only available on Android devices.");
  }

  final result = await methodChannel
      .invokeMethod<Map<Object?, Object?>>('initGooglePay', {
    'merchantName': merchantName,
    'authMethods': allowedAuthMethods
            ?.map((TapPayCardAuthMethod authMethod) => authMethod.name)
            .toList() ??
        kDefaultTapPayAllowedCardAuthMethods
            .map((TapPayCardAuthMethod authMethod) => authMethod.name)
            .toList(),
    'cardTypes': allowedCardTypes
            ?.map((TapPayCardType cardType) => cardType.name)
            .toList() ??
        kDefaultTapPayAllowedCardTypes
            .map((TapPayCardType cardType) => cardType.name)
            .toList(),
    'isPhoneNumberRequired': isPhoneNumberRequired,
    'isEmailRequired': isEmailRequired,
    'isBillingAddressRequired': isBillingAddressRequired,
  });

  if (result == null) {
    return TapPaySdkCommonResult(
        success: false,
        message:
            "Encountered an unidentified error while checking if Google Pay is available.");
  } else {
    return TapPaySdkCommonResult.fromMap(Map<String, dynamic>.from(result));
  }
}