> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mattildapayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Pay on Android without the SDK

It is possible to use Google Pay without the SDK.

## About this integration

Even without the Android SDK, there is only minimal configuration required to get set up to process Google Pay. Unlike
some other integrations it does not require you to sign up for a Google Developer account.

## Enable Google Pay

To enable Google Pay, head over to your dashboard and then go to
**Connections** -> **Catalog** -> **Google Pay**.

Next, fill in your merchant name and the domain name(s) where you want to
use Google Pay.

## Integrate Google Pay

<Tabs>
  <Tab title="Java">
    To learn how to integrate Google Pay we recommend
    following Google's [tutorial][tutorial]. The steps below will highlight any differences
    and specifics for our API.

    ### Set gateway and merchant ID

    In step 2 of [Google's tutorial][tutorial] you are instructed to request a payment token for your provider.
    In our case, the value for `gateway` needs to be set to `gr4vy`, and the value of `gatewayMerchantId` needs
    to be set to `app.gr4vy.sandbox.mattilda.[merchant_account_id]` for your sandbox environment, and
    `app.gr4vy.mattilda.[merchant_account_id]` in production.

    <CodeGroup>
      ```java Java theme={"dark"}
      private static JSONObject getGatewayTokenizationSpecification() throws JSONException {
          return new JSONObject() {{
                  put("type", "PAYMENT_GATEWAY");
                  put("parameters", new JSONObject() {{
                  put("gateway", "gr4vy");
                  put("gatewayMerchantId", "app.gr4vy.sandbox.example.default");
              }});
          }};
      }
      ```

      ```kotlin Kotlin theme={"dark"}
      private fun gatewayTokenizationSpecification(): JSONObject {
          return JSONObject().apply {
              put("type", "PAYMENT_GATEWAY")
              put("parameters", JSONObject(mapOf(
                      "gateway" to "gr4vy",
                      "gatewayMerchantId" to "app.gr4vy.sandbox.example.default")))
          }
      }
      ```
    </CodeGroup>

    ### Create a transaction

    In step 9 of Google's tutorial, you will have a `paymentData` that needs to be
    sent to the gateway. You can send this object to our [`POST /transactions`](/reference/transactions/new-transaction#google-pay-payment-method-create)
    endpoint either directly or via your server.

    The payment method used needs to contain the data from the Google Pay payload.

    <CodeGroup>
      ```json Payment method data theme={"dark"}
      {
        "amount": 1299,
        "currency": "MXN",
        "country": "MX",
        "payment_method": {
          "method": "googlepay",
          "token": "[paymentData.paymentMethodData.tokenizationData.token]",
          "card_suffix": "[paymentData.paymentMethodData.info.cardDetails]", 
          "card_scheme": "[paymentData.paymentMethodData.info.cardNetwork]",
          "redirect_url": "https://example.com/callback"
        }
      }
      ```
    </CodeGroup>

    <Note>
      We strongly recommend always providing a `redirect_url`, just in case any connection
      is configured to use 3-D Secure.

      This URL will be appended with both a transaction ID
      and status (e.g. `https://example.com/callback?transaction_id=123
              &transaction_status=capture_succeeded`) after 3-D Secure has been completed.
    </Note>
  </Tab>

  <Tab title="React Native">
    In React Native you can use any Google Pay integration, together with your merchant identifier.
    One of the easiest solutions is to use a library like [React Native Google Pay](https://www.npmjs.com/package/react-native-google-pay) to get
    a Google Pay token.

    On initialization, any of these libraries will require you to set the Google Pay merchant identifier
    and our gateway ID. You should set the gateway value to `gr4vy` and the `gatewayMerchantId` to your
    environment, e.g. `app.gr4vy.sandbox.mattilda.[merchant_account_id]`.

    ```js theme={"dark"}
    import { GooglePay } from 'react-native-google-pay';

    const allowedCardNetworks = ['VISA', 'MASTERCARD'];
    const allowedCardAuthMethods = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];

    const requestData = {
      cardPaymentMethod: {
        tokenizationSpecification: {
          type: 'PAYMENT_GATEWAY',
          gateway: 'gr4vy',
          gatewayMerchantId: 'app.gr4vy.sandbox.example.default',
        },
        allowedCardNetworks,
        allowedCardAuthMethods,
      },
      transaction: {
        totalPrice: '10',
        totalPriceStatus: 'FINAL',
        currencyCode: 'AUD',
      },
      merchantName: 'Example Merchant',
    };

    // Set the environment before the payment request
    GooglePay.setEnvironment(GooglePay.ENVIRONMENT_TEST);
    ```

    Once the user has approved the payment, your application will receive a Google Pay token from the library.

    You can pass this library to our server for processing.

    ```js theme={"dark"}
    GooglePay.requestPayment(requestData)
        .then((token: string) => {
          return fetch('https://api.mattildapayments.com/transactions', {
          method: 'POST',
          headers: {
            "Authorization": "Bearer [TOKEN]"
          },
          body: {
            amount: 1299,
            currency: "MXN",
            payment_method: {
              method: "googlepay",
              token: token,
              redirect_url: 'https://example.com/callbacl'
            }
          }
        })
        .then(res => res.json())
        .then(successHandler)
        .catch(errorHandler)
        })
        .catch((error) => console.log(error.code, error.message));
    ```

    <Note>
      We strongly recommend always providing a `redirect_url`, just in case any connection
      is configured to use 3-D Secure. This can be set to an application URL or URN if needed.

      This URL will be appended with both a transaction ID
      and status (e.g. `https://example.com/callback?transaction_id=123
                  &transaction_status=capture_succeeded`) after 3-D Secure has been completed.
    </Note>
  </Tab>
</Tabs>

## Test Google Pay

Please follow the Google Pay documentation with further guides on how
to add [test cards](https://developers.google.com/pay/api/android/guides/resources/test-card-suite) for use in
a sandbox environment.

[tutorial]: https://developers.google.com/pay/api/android/guides/tutorial
