Payment for Google Pay

Payment using the Android SDK can be taken from cards registered in Android Pay Wallet, as well as ones you have used for previous transactions but which are not registered with wallet (known as Card on File with Google). After clicking the 'Pay' button:

  1. Choose your Google account from the list displayed
  2. Choose the card from the list displayed, which is one of the following:
    • Cards registered with Android Pay and cards on file
    • Cards on file only
    • An empty list, because no cards are associated with the account

Apart from payment using Android Pay or cards on file, you can also accept a standard mobile payment from Android devices, in which the user enters card information directly on their mobile device.

Configuring Parameters

Merchants must configure support for specific payment methods. The following flags are used to map payment methods in the Android SDK:

Android Pay Card

WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD

Card on File with Google

WalletConstants.PAYMENT_METHOD_CARD

You can select either Card on File or both payment methods, depending on whether you are in one of the countries in which Paysafe supports Android Pay.

Initiating a Payment for Google Pay

  1. Set up an instance of PaymentsClient in your Activity for interacting with Google Pay.
    This procedure integrates with Google Pay, which helps retrieve the payload for the card (which is associated with the consumer's Google account, including those cards tokenized for Android Pay). For testing the integration you can set the environment as follows: WalletConstants.ENVIRONMENT_TEST
PaymentsClient paymentsClient = Wallet.getPaymentsClient(this,
         new Wallet.WalletOptions.Builder()
        .setEnvironment(WalletConstants.ENVIRONMENT_TEST)
        .build());
  1. Call isReadyToPay() to check whether Google Pay is supported on the device.
    In this step we set up payment methods that will be supported within your application. In the method isReadyToPay(), we set parameters for addAllowedPaymentMethod which in turn sets flags for the corresponding supported payment methods.
    If the flag WalletConstants.PAYMENT_METHOD_CARD is set, the user will be presented only with cards that are on file, and not with cards registered with Android Pay.
    If the flag WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD is set then the user is presented with cards registered for Android Pay.
    You can add both payment methods if you are in a country where Paysafe supports Android Pay.
    If the device does not support Google Pay, the customer must use the traditional method of making a mobile payment, which involves entering card details on the mobile device.
/**
 * IsReadyToPay
 */
private void isReadyToPay() {
    IsReadyToPayRequest request = IsReadyToPayRequest.newBuilder()
            .addAllowedPaymentMethod( WalletConstants.PAYMENT_METHOD_CARD)
            .addAllowedPaymentMethod( WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD)
            .build();
    Task <Boolean> task = paymentsClient.isReadyToPay(request);
    task.addOnCompleteListener(
            new OnCompleteListener<Boolean>() {
                public void onComplete( Task<Boolean> task) {
                    try {
                        boolean result =
                                task.getResult( ApiException.class);
                        if(result == true) {
                            // LOG
                            Utils.debugLog("IsReadyToPay Result: True");

                            // Google Payment supported on device
                            //show Google as payment option

                            // Define this ArrayList<Integer> in your class and instantiate it
                            // to use below to set flag for payment method options
                            flagPaymentMethods = new ArrayList<Integer>();

                            // CHECK, if device supports NFC
                            // if YES, show below payment methods
                            // 1. Card on file
                            // 2. Android Pay
                            if (Utils.isNFCAvailable(PaysafeApplication.mApplicationContext)) {
                                // LOG
                                Utils.debugLog("Payment Method: card_on_file and android_pay");

                                // set payment methods
                                flagPayWithGoogle = WalletConstants.PAYMENT_METHOD_CARD;
                                flagAndroidPay = WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD;
                                // Add Options to Payment Methods
                                flagPaymentMethods.add(flagPayWithGoogle);
                                flagPaymentMethods.add(flagAndroidPay);

                            }
                            else {
                                // LOG
                                Utils.debugLog("Payment Method: card_on_file");
                                // if NO (device does'nt support NFC), show below payment methods
                                // 1. Card on file
                                flagPayWithGoogle = WalletConstants.PAYMENT_METHOD_CARD;
                                // Add Options to Payment Methods
                                flagPaymentMethods.add(flagPayWithGoogle);

                            }

                        } else {
                            // LOG
                            Utils.debugLog("IsReadyToPay Result: False");

                            // Google Payment not supported on device
                            //hide Google as payment option
                            Utils.showDialogAlert("Google Payment Option Not Supported!",
                                    mContext);
                            mBtnPayWithGoogle.setEnabled(false);

                        }
                    } catch (ApiException exception) {
                    }
                }
            });
} // end of isReadyToPay()
  1. Clicking BUY creates a PaymentDataRequest object and calls the loadPaymentData API. The PaymentDataRequest object is parseable and represents a payment data request containing the information necessary for a payment.
findViewById(R.id.buy_button).setOnClickListener(
        new View .OnClickListener() {
              @Override
              public void onClick( View view) {
                         PaymentDataRequest request = createPaymentDataRequest ();
                         if (request != null) {
                                   AutoResolveHelper .resolveTask( paymentsClient.loadPaymentData(request), this,
                                   LOAD_PAYMENT_DATA_REQUEST_CODE);
                         }
               }
      }
);
  1. Set the PaymentMethodTokenizationParameters as follows:
PaymentMethodTokenizationParameters params =
                         PaymentMethodTokenizationParameters.newBuilder()
        .setPaymentMethodTokenizationType(WalletConstants.
                         PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY )
        .addParameter("gateway", "paysafe")
        .addParameter("gatewayMerchantId", "yourMerchantIdGivenFromYourGateway")
        .build();
  1. Add Payment Method Tokenization Parameters in the Payment Data Request, as per the WalletConstants in step 2 above.
/**
 * CreatePaymentDataRequest
 */
private PaymentDataRequest createPaymentDataRequest() {
    PaymentDataRequest .Builder request =
            PaymentDataRequest .newBuilder()
                    .setTransactionInfo(
                            TransactionInfo.newBuilder()
                                    .setTotalPriceStatus(
                                            WalletConstants.TOTAL_PRICE_STATUS_FINAL)
                                    .setTotalPrice("10.00")
                                    .setCurrencyCode("USD")
                                    .build())
                    .addAllowedPaymentMethod(
                            WalletConstants .PAYMENT_METHOD_CARD)
                    .addAllowedPaymentMethod(
                            WalletConstants .PAYMENT_METHOD_TOKENIZED_CARD)
                    .setCardRequirements(
                            CardRequirements.newBuilder()
                                    .addAllowedCardNetworks(Arrays.asList(
                                            WalletConstants.CARD_NETWORK_AMEX,
                                            WalletConstants.CARD_NETWORK_DISCOVER,
                                            WalletConstants.CARD_NETWORK_VISA,
                                            WalletConstants.CARD_NETWORK_MASTERCARD))
                                    .build());

    request.setPaymentMethodTokenizationParameters(params);
    return request.build();
} // end of createPaymentDataRequest()

Making the Payment

  1. Click the Google Pay button.
  1. If Google Pay is supported, the consumer will be able to choose their card (either a card on file or a tokenized card where Paysafe supports Android Pay).

  1. Click Continue. The payment bundle will be requested using the card selected.

When you confirm the payment, the SDK communicates with the Paysafe Customer Vault API server to get a single-use token. The single-use token can then be used my the merchant server for an authorization or purchase request calling the Paysafe Card Payments API.

Did you find this page useful?