Google Pay
Show the Google Pay button in your own checkout and send the payment token to Paytrim.
In your own checkout, you show the Google Pay button yourself. Your customer either selects a card stored in their Google account or adds a new one. You pass the resulting payment token to Paytrim for processing. To show Google Pay on the hosted payment page instead, without any work with Google, see Apple Pay and Google Pay on the hosted payment page.
Google Pay terms
To accept Google Pay, you must follow the Google Pay APIs Acceptable Use Policy and accept the Google Pay API Terms of Service.
Before you begin
- Make sure Google Pay is active in your project.
- Read Google's documentation and make sure your integration follows it:
Authentication methods
Google Pay returns cards with one of two authentication methods. Both are always enabled; you can't turn either of them off.
| Method | What it means |
|---|---|
PAN_ONLY | The card is stored in your customer's Google account and isn't bound to a device, for example on desktop or on non-Android mobile web. |
CRYPTOGRAM_3DS | The card is bound to an Android device. Issuers can delegate strong customer authentication to Google for later payments on that device. The payment comes with a cryptogram. |
Paytrim decrypts the payment token from Google with its own Google Pay keys. The card number never reaches your systems.
Encrypted payload
You pass the encrypted payment token from Google to Paytrim. Paytrim decrypts it and stores the card in the vault.
With the activation of Google Pay, you receive the gateway and gatewayMerchantId for the tokenizationSpecification of your Google Pay payment request: gateway is the name of Paytrim at Google, gatewayMerchantId is your merchant ID. The examples use them as $GOOGLE_PAY_GATEWAY and $GOOGLE_PAY_GATEWAY_MERCHANT_ID. A token issued for another gatewayMerchantId is refused.
| Step | Endpoint | What it does |
|---|---|---|
| 1 | POST /v1/orders/ | Creates the order and the Google Pay transaction. |
| 2 | POST {google_pay_token_url}/tokens/ | Decrypts the payment token and returns a vaultToken, cryptogram and ECI indicator. |
| 3 | POST /pay/{order_id}/select-payment-method/google-pay/{transaction_id}/ | Executes the payment. |
Create the order
Create an order with a google-pay transaction:
curl https://api.pay.paytrim.com/v1/orders/ \
--user "$API_KEY:" \
--header "Content-Type: application/json" \
--data '{
"currency": "EUR",
"amount": 995,
"merchant_order_id": "EXAMPLE001",
"description": "Example Google Pay order",
"return_url": "https://www.example.com/order/EXAMPLE001",
"webhook_url": "https://www.example.com/webhook",
"transactions": [
{
"payment_method": "google-pay"
}
],
"customer": {
"merchant_customer_id": "123456789",
"email_address": "user@example.com",
"first_name": "John",
"last_name": "Smith",
"address_type": "billing",
"address": "100 Main St",
"postal_code": "SW1A 1AA",
"city": "London",
"country": "GB",
"locale": "en",
"phone_numbers": ["+441234567890"],
"ip_address": "198.51.100.1"
}
}'The response contains the IDs and the setup token you need in the next steps:
{
"id": "6bf8a727-bef2-4420-8d41-af82f6f19f3d",
"status": "new",
"transactions": [
{
"id": "59f5866a-c216-472e-b803-8a4e83c4578a",
"payment_method": "google-pay",
"payment_method_details": {
"setup_token": "c6d0a22b-df22-41a2-aac1-d647173ff219"
},
"status": "new"
}
]
}The response is shortened. Save the order id, the transaction id and the setup_token.
Fields of the customer can be required. See Create an order in the API reference for the fields and their formats.
Store the payment details
Your customer selects a card in Google Pay. Google returns the payment token in paymentData.paymentMethodData.tokenizationData.token. Send it as a string, together with the setup token and transaction ID from step 1:
curl "https://google-pay.pay.paytrim.com/tokens/" \
--header "Content-Type: application/json" \
--data '{
"googlePayMessage": "{\"signature\":\"MEUCIQDXc...03d\",\"protocolVersion\":\"ECv2\",\"signedMessage\":\"...\"}",
"setupToken": "c6d0a22b-df22-41a2-aac1-d647173ff219",
"transactionId": "59f5866a-c216-472e-b803-8a4e83c4578a"
}'For a token from Google's test environment, when your payment request has environment set to TEST, use https://google-pay.pay.paytrim.com/test/tokens/ instead: those tokens are encrypted with other keys.
{
"vaultToken": "d972dc43-6a3d-4dcf-b54e-6e9a0fe325e3",
"cryptogram": "AgAAAAAABk4DWZ4C28yUQAAAAAA=",
"eciIndicator": "05"
}cryptogram and eciIndicator can be empty. An empty cryptogram means the card was returned as PAN_ONLY: the payment is processed as a regular card payment, and your customer has to authenticate with 3-D Secure. The redirect_url of the next step then leads to the authentication.
This request needs no API key: the setupToken identifies the transaction.
Execute the payment
Send the values from step 2 to the payment URL of the transaction, together with your customer's browser details:
curl https://api.pay.paytrim.com/pay/6bf8a727-bef2-4420-8d41-af82f6f19f3d/select-payment-method/google-pay/59f5866a-c216-472e-b803-8a4e83c4578a/ \
--header "Content-Type: application/json" \
--data '{
"vaultToken": "d972dc43-6a3d-4dcf-b54e-6e9a0fe325e3",
"cryptogram": "AgAAAAAABk4DWZ4C28yUQAAAAAA=",
"eciIndicator": "05",
"browser_info_screen_width": 1920,
"browser_info_screen_height": 1080,
"browser_info_color_depth": 24,
"browser_info_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
"browser_info_time_zone_offset": 0,
"browser_info_language": "en-US",
"browser_info_java_enabled": "false"
}'| Field | Description |
|---|---|
vaultToken | The vault token from step 2. |
cryptogram | The cryptogram from step 2. Can be empty. |
eciIndicator | The ECI indicator from step 2. Can be empty. |
browser_info_screen_width | Screen width of your customer's device, in pixels. |
browser_info_screen_height | Screen height of your customer's device, in pixels. |
browser_info_color_depth | Color depth of the screen, in bits. |
browser_info_user_agent | User agent of your customer's browser. |
browser_info_time_zone_offset | Time zone offset of your customer's browser. |
browser_info_language | Language of your customer's browser, such as en-US. |
browser_info_java_enabled | Whether Java is enabled in your customer's browser, as the string true or false. |
{
"is_successful": true,
"redirect_url": "https://api.pay.paytrim.com/pay/6bf8a727-bef2-4420-8d41-af82f6f19f3d/59f5866a-c216-472e-b803-8a4e83c4578a/completed/",
"reason": "none"
}Redirect your customer to the redirect_url. Then confirm the payment before you deliver. See Execute a Google Pay payment in the API reference.
browser_info_time_zone_offset is the offset in minutes, as new Date().getTimezoneOffset() returns it. This request needs no API key.
Confirm the payment
Paytrim sends a webhook when the order status changes. Retrieve the order and deliver only when the order status is completed. See Confirm the payment.
Test your integration
Use Google's test environment: the Google Pay payment sheet then shows test cards instead of the real cards in your Google account. See Google's test card suite for how to set it up, and send the token to https://google-pay.pay.paytrim.com/test/tokens/.
Go live
- Request production access for your website in the Google Pay & Wallet Console. Google checks your integration against its integration checklist.
- Switch the Google Pay payment request to the production environment, and send the token to
https://google-pay.pay.paytrim.com/tokens/. - Make sure Google Pay is active in your live project, and use its API key.
- Set the webhook URL in your live project, or send a
webhook_urlwith every order.
Then work through the go-live checklist.
Recurring payments
Google Pay supports recurring payments. See Recurring payments with Google Pay.