Native Payment

A native Google Pay payment consists of three steps:

  1. Get a quote — GET /sdk-partner/native/rate with payment_method=google.
  2. Show Google Pay — the Google Pay button and payment sheet in your Android app or on your website.
  3. Send the payment — POST /sdk-partner/native-mobile-pay/mobile-pay with the payment token from Google.

Before you start, complete the Onboarding.

Sequence Diagram

Native Google Pay — integration flow Native Google Pay — integration flow Partner Mercuryo **Partner Backend** **Partner Backend** **Partner Backend** **Google Pay API** **Google Pay API** **Mercuryo API** **Mercuryo API** **Mercuryo Widget** User **Partner App** **Partner Backend** **Google Pay API** **Mercuryo API** **Mercuryo Widget** User Partner App Android / Web Partner Backend Google Pay API Mercuryo API Mercuryo Widget **Partner Backend** **Partner Backend** **Partner Backend** **Google Pay API** **Google Pay API** **Mercuryo API** **Mercuryo API** **Mercuryo Widget** Step 1 — Quote Choose   amount   and   currency Request   a   quote GET   /sdk-partner/native/rate Headers: Sdk-Partner-Token, Sdk-User-IP type = buy, payment_method = google is_total = true from, to, amount, network Check   that   native   Google   Pay is   available   for   this   user 200   —   quote quote_token, fiat_amount, fiat_currency Quote alt [Quote rejected (e.g. 403034, 403109)] Offer   another   payment   method (e.g.   the   Mercuryo   widget) Step 2 — Google Pay isReadyToPay result Show   the   Google   Pay   button and   Mercuryo   Terms   of   Service and   Privacy   Policy Tap   the   Google   Pay   button loadPaymentData totalPrice = fiat_amount currencyCode = fiat_currency tokenization: DIRECT, ECv2, Mercuryo public key Payment   sheet Confirm   the   payment Encrypt   the   payment   token with   the   Mercuryo   public   key PaymentData tokenizationData.token, email, billingAddress Step 3 — Payment PaymentData Sign   the   request   body (X-Signature) POST /sdk-partner/native-mobile-pay/mobile-pay Headers: Sdk-Partner-Token, X-Signature payment_method = google pay_token = token as is buy_token = quote_token email, first_name, last_name, billing_address, address, ip Decrypt   the   token and   process   the   payment alt [Accepted] 200   —   status:   pending [Declined] 200   —   declined status = order_failed, error_code [KYC required] 403   (403001)   —   KYC   required init_token, init_token_type init_token,   init_token_type Open   the   widget   with init_token,   init_token_type Pass   KYC Back   to   the   partner [Error] 4xx   /   5xx   —   code,   message Final status Callback   with   the   final   status (X-Signature) Verify   X-Signature 200   OK Show   the   result Payment   result

Step 1 — Get a Quote

Before showing Google Pay, request a quote from Mercuryo — it is required to execute the payment.

API Endpoint: GET /sdk-partner/native/rate

Header Required Description
Sdk-Partner-Token One of Sdk-Partner-Token or Sdk-User-Token Your partner authentication token.
Sdk-User-Token One of Sdk-Partner-Token or Sdk-User-Token The user's token from sign-in. The quote is calculated for this user and contains kyc_limits — see KYC Before Payment.
Sdk-User-IP Yes The end user's real IP address.
Parameter Required Description
type Yes Must be buy.
from Yes The fiat currency the user pays in (e.g., EUR).
to Yes The cryptocurrency the user buys (e.g., BTC).
amount Yes The fiat amount the user pays, in the from currency.
payment_method Yes Must be google.
is_total Yes Must be true: amount is the total the user pays, fees included.
network Yes The blockchain network of the purchased currency. Pass it to determine availability and correct fees. The wallet address in the payment request must belong to this network.

Example request:

GET /v1.6/sdk-partner/native/rate?type=buy&from=EUR&to=BTC&amount=100&payment_method=google&is_total=true&network=BITCOIN
Sdk-Partner-Token: YOUR_SDK_PARTNER_TOKEN
Sdk-User-IP: 203.0.113.42

Example response:

{
    "status": 200,
    "data": {
        "quote_token": "eyJ...",
        "currency": "BTC",
        "amount": "0.00151",
        "fiat_amount": "100.00",
        "fiat_currency": "EUR",
        ...
    }
}
  • quote_token — store it, you send it as buy_token in the payment request in Step 3.
  • Show the Google Pay button only if you received a quote.

Request a new quote whenever the amount or currency changes, and use the values of the latest quote in the next steps.

Quote Rejected

If native Google Pay can't be used for this user, the quote request is rejected. Don't show the Google Pay button — switch to the Mercuryo widget flow instead, so the purchase isn't lost:

Code Meaning
403034 The user's country isn't supported.
403109 Google Pay is not available for this user.
{
    "status": 403,
    "code": 403109,
    "message": "This payment method is not available for current user."
}

Terms of Service

You MUST obtain the user's consent to Mercuryo's Terms of Service and Privacy Policy before the payment.

For users from the United States, you must also display a link to Coinme's Terms of Service, in addition to Mercuryo's.

Example text (non-US users):

By continuing you accept Mercuryo Terms of Service and Privacy Policy

Example text (US users):

By continuing you accept Coinme Terms of Service, Mercuryo Terms of Service and Privacy Policy

You can get the current Terms of Service and Privacy Policy links for the user via GET /widget/terms, passing the user's ip_address or country. The response returns the relevant set of links: only Mercuryo's for non-US users, or both Mercuryo's and Coinme's for US users.

Step 2 — Show Google Pay

Your app or site works with Google Pay directly. The sequence of calls is:

  1. Create the Google Pay client.
  2. Check readiness to pay — isReadyToPay.
  3. Show the Google Pay button.
  4. Open the payment sheet — loadPaymentData when the user taps the button.

For the full Google Pay API reference, see the official documentation:

Values in angle brackets, such as <MERCURYO_PUBLIC_KEY>, are provided by Mercuryo during Onboarding. Use them exactly as provided.

Create the Google Pay client

Field Value
environment TEST for the Mercuryo sandbox, PRODUCTION for live payments

Android:

val walletOptions = Wallet.WalletOptions.Builder()
    .setEnvironment(WalletConstants.ENVIRONMENT_PRODUCTION) // ENVIRONMENT_TEST for the Mercuryo sandbox
    .build()
val paymentsClient = Wallet.getPaymentsClient(activity, walletOptions)

Web — load https://pay.google.com/gp/p/js/pay.js and create the client:

const paymentsClient = new google.payments.api.PaymentsClient({
    environment: 'PRODUCTION' // 'TEST' for the Mercuryo sandbox
});

Check readiness to pay

Call isReadyToPay before showing the button.

Request:

{
    "apiVersion": 2,
    "apiVersionMinor": 0,
    "allowedPaymentMethods": [
        {
            "type": "CARD",
            "parameters": {
                "allowedAuthMethods": ["CRYPTOGRAM_3DS"],
                "allowedCardNetworks": ["MASTERCARD", "VISA"]
            }
        }
    ]
}
Field Value
apiVersion, apiVersionMinor 2, 0
allowedPaymentMethods[].type CARD
allowedAuthMethods CRYPTOGRAM_3DS — cards tokenized on an Android device
allowedCardNetworks MASTERCARD, VISA

Android:

val request = IsReadyToPayRequest.fromJson(isReadyToPayJson)
paymentsClient.isReadyToPay(request).addOnCompleteListener { task ->
    val showGooglePay = task.isSuccessful && task.result == true
}

Web:

const response = await paymentsClient.isReadyToPay(isReadyToPayRequest);
const showGooglePay = response.result;

Response (Web):

{
    "result": true
}

Show the Google Pay button only if the result is true. If it is false, Google Pay isn't available on this device or in this browser — don't show it.

Show the Google Pay button

Pass the card payment method to the button, so that Google shows it for the right card types. Use the same allowedPaymentMethods as in the payment sheet request.

Android — use the Google Pay PayButton:

googlePayButton.initialize(
    ButtonOptions.newBuilder()
        .setAllowedPaymentMethods(allowedPaymentMethodsJson) // JSON array with the card payment method
        .build()
)
googlePayButton.setOnClickListener { requestPayment() }

Web:

const button = paymentsClient.createButton({
    buttonType: 'buy',
    allowedPaymentMethods: paymentDataRequest.allowedPaymentMethods,
    onClick: onGooglePayButtonClicked
});
document.getElementById('google-pay-container').appendChild(button);

Follow the Google Pay brand guidelines: don't change the button's colors, proportions or text.

Open the payment sheet

When the user taps the button, call loadPaymentData.

Important (Web): Call loadPaymentData directly in the click handler. Build the request in advance, when you get the quote, and don't wait for anything (network requests, timers, await) before the call — otherwise the browser blocks the Google Pay window.

Request:

{
    "apiVersion": 2,
    "apiVersionMinor": 0,
    "merchantInfo": {
        "merchantId": "<MERCURYO_MERCHANT_ID>",
        "merchantName": "<MERCHANT_NAME>"
    },
    "allowedPaymentMethods": [
        {
            "type": "CARD",
            "parameters": {
                "allowedAuthMethods": ["CRYPTOGRAM_3DS"],
                "allowedCardNetworks": ["MASTERCARD", "VISA"],
                "billingAddressRequired": true,
                "billingAddressParameters": {
                    "format": "FULL"
                }
            },
            "tokenizationSpecification": {
                "type": "DIRECT",
                "parameters": {
                    "protocolVersion": "ECv2",
                    "publicKey": "<MERCURYO_PUBLIC_KEY>"
                }
            }
        }
    ],
    "emailRequired": true,
    "transactionInfo": {
        "totalPriceStatus": "FINAL",
        "totalPrice": "100.00",
        "currencyCode": "EUR",
        "countryCode": "<COUNTRY_CODE>"
    }
}
Field Value
merchantInfo.merchantId <MERCURYO_MERCHANT_ID>
merchantInfo.merchantName <MERCHANT_NAME> — shown to the user on the payment sheet
allowedAuthMethods, allowedCardNetworks Same as in isReadyToPay
billingAddressRequired, billingAddressParameters.format true, FULL — the user's name and billing address are required for the payment
tokenizationSpecification.type DIRECT — Google encrypts the token for Mercuryo, you don't need to decrypt it
tokenizationSpecification.parameters.protocolVersion ECv2
tokenizationSpecification.parameters.publicKey <MERCURYO_PUBLIC_KEY>
emailRequired true — the user's email is required for the payment
transactionInfo.totalPrice data.fiat_amount from the quote
transactionInfo.currencyCode data.fiat_currency from the quote
transactionInfo.countryCode <COUNTRY_CODE>
transactionInfo.totalPriceStatus FINAL — the amount is final and shown on the sheet

Important: the amount on the payment sheet MUST match the quote.

Mercuryo charges the user the amount of the quote whose quote_token you send as buy_token in Step 3. The payment token from Google doesn't contain the amount, so Mercuryo can't see what the user confirmed on the sheet. If the amounts differ, the payment may be declined.

  • Set totalPrice and currencyCode to data.fiat_amount and data.fiat_currency of the same quote whose quote_token you send.
  • If you request a new quote, rebuild the request with its values before the user taps the button.
  • Don't refresh the quote while the payment sheet is open: send the quote_token of the quote whose amount was shown on the sheet.

Android:

private val paymentDataLauncher =
    registerForActivityResult(TaskResultContracts.GetPaymentDataResult()) { taskResult ->
        when (taskResult.status.statusCode) {
            CommonStatusCodes.SUCCESS -> taskResult.result?.let { sendToBackend(it.toJson()) }
            CommonStatusCodes.CANCELED -> { /* the user closed the sheet or Google couldn't show it */ }
            else -> { /* show an error */ }
        }
    }

private fun requestPayment() {
    val request = PaymentDataRequest.fromJson(paymentDataRequestJson)
    paymentsClient.loadPaymentData(request).addOnCompleteListener(paymentDataLauncher::launch)
}

Web:

async function onGooglePayButtonClicked() {
    try {
        const paymentData = await paymentsClient.loadPaymentData(paymentDataRequest);
        await sendToBackend(paymentData);
    } catch (err) {
        if (err.statusCode === 'CANCELED') {
            // the user closed the sheet or Google couldn't show it
        } else {
            // show an error
        }
    }
}

Result:

  • The user confirmed the payment — Google returns PaymentData; continue with Step 3.
  • The user closed the sheet or Google couldn't show it (CANCELED) — don't send anything to Mercuryo.
  • Google returned an error — don't send the payment; show an error to the user.

Example PaymentData:

{
    "apiVersion": 2,
    "apiVersionMinor": 0,
    "email": "user@example.com",
    "paymentMethodData": {
        "type": "CARD",
        "description": "Visa •••• 1111",
        "info": {
            "cardNetwork": "VISA",
            "cardDetails": "1111",
            "billingAddress": {
                "name": "John Doe",
                "address1": "Unter den Linden 1",
                "address2": "",
                "address3": "",
                "locality": "Berlin",
                "administrativeArea": "",
                "postalCode": "10117",
                "countryCode": "DE"
            }
        },
        "tokenizationData": {
            "type": "DIRECT",
            "token": "{\"signature\":\"MEQCIH6Q...\",\"intermediateSigningKey\":{...},\"protocolVersion\":\"ECv2\",\"signedMessage\":\"{...}\"}"
        }
    }
}

Pass PaymentData to your backend and send the payment right away: the payment token is single-use and expires.

Step 3 — Send the Payment

Your backend sends the payment token, the quote_token (as buy_token) and the user's data to Mercuryo.

Request Authentication

Each request is authenticated with two HTTP headers:

Header Description
Sdk-Partner-Token Your partner authentication token, provided by your integration manager.
X-Signature The HMAC-SHA256 signature of the raw request body.

See Signature for how to calculate X-Signature.

API Endpoint: POST /sdk-partner/native-mobile-pay/mobile-pay

  • Content-Type: application/json

Request Body

Field Type Description
payment_method string Required for Google Pay. Must be google.
pay_token string Required. paymentMethodData.tokenizationData.token from PaymentData, as is. Don't parse, re-encode or base64-encode it.
buy_token string Required. quote_token from the quote in Step 1.
email string Required. email from PaymentData.
first_name string Required. The user's first name.
last_name string Required. The user's last name.
billing_address object Required. The billing address from PaymentData, see the mapping below.
address string Required. The user's wallet address for the purchased crypto, in the network of the quote.
ip string Required. The user's public IP address — the same end-user IP address you sent as Sdk-User-IP in the quote.
merchant_transaction_id string Optional. Your identifier for the transaction.

billing_address mapping:

billing_address field PaymentData field
country_code paymentMethodData.info.billingAddress.countryCode
street_line_1 billingAddress.address1
street_line_2 billingAddress.address2 and address3, joined with a space
state_code billingAddress.administrativeArea
city billingAddress.locality
zip_code billingAddress.postalCode

Example request:

POST /v1.6/sdk-partner/native-mobile-pay/mobile-pay
Sdk-Partner-Token: YOUR_SDK_PARTNER_TOKEN
X-Signature: 42ec400ca2c40d33f4c3a985efc0f8e93914a1db5403bd239d6e48540542f3d2
Content-Type: application/json
{
    "payment_method": "google",
    "pay_token": "{\"signature\":\"MEQCIH6Q...\",\"intermediateSigningKey\":{...},\"protocolVersion\":\"ECv2\",\"signedMessage\":\"{...}\"}",
    "buy_token": "eyJ...",
    "merchant_transaction_id": "order_123",
    "email": "user@example.com",
    "first_name": "John",
    "last_name": "Doe",
    "billing_address": {
        "country_code": "DE",
        "street_line_1": "Unter den Linden 1",
        "city": "Berlin",
        "zip_code": "10117"
    },
    "address": "1Lbcfr7sAHTD9CgdQo3HTMTkV8LK4ZnX71",
    "ip": "203.0.113.42"
}

Success Response

The response returns the initial status of the transaction:

{
    "status": 200,
    "data": {
        "id": "28a3c125a28075453",
        "status": "pending"
    }
}

status: pending — the payment is accepted and is being processed. The final status is delivered via Callbacks.

KYC Required

If the user has to pass KYC, the response is 403001 with a token to open the Mercuryo widget:

{
    "status": 403,
    "code": 403001,
    "message": "KYC verification needed.",
    "data": {
        "id": "28a3c125a28075453",
        "status": "pending",
        "init_token": "a1b2c3d4...",
        "init_token_type": "type_sdk_silent_sub"
    }
}

data.status is pending for non-US users and order_failed for US users. See KYC During Payment for how to hand the user over to the widget. To avoid this step, the user can pass KYC in advance — see KYC Before Payment.

Declined Payment

A payment declined by the card issuer or the payment provider returns HTTP 200 with status: order_failed and the reason in error_code:

{
    "status": 200,
    "data": {
        "id": "28a3c125a28075453",
        "status": "order_failed",
        "error_code": "insufficient_funds"
    }
}

Show the user that the payment failed and offer to try again with another card.

Errors

Other rejections return an HTTP error status and an application error code:

{
    "status": 422,
    "code": 422001,
    "message": "3D Secure is not supported for this payment method."
}
Code HTTP status Meaning What to do
400000 400 This buy_token can't be used for this payment. Request a new quote with the same Sdk-Partner-Token you use for the payment, and repeat the payment.
400001 400 Validation failed; data contains the invalid fields. Fix the request parameters.
400310 400 The payment token has expired or was already used. Ask the user to pay with Google Pay again; send each token only once.
401000 401 Invalid Sdk-Partner-Token or X-Signature. Check your credentials and the signature calculation.
403004 403 The exchange rate has changed; data contains the new rate. Request a new quote, show the user the new amount and open the Google Pay sheet again. Send the payment with the new quote_token as buy_token and the new pay_token.
403006 403 The transaction is blocked, including for users from the UK and the EEA. Don't retry; offer another payment method.
403009 403 The user's account is locked. Don't retry; the user should contact Mercuryo support.
403030 403 Native Google Pay is not enabled for your account. Contact your integration manager.
403104 403 The service is temporarily unavailable in the user's region (US users). Don't retry; offer another flow.
422001 422 The card issuer requested 3D Secure, which is not supported. Ask the user to pay with another card, or offer payment through the Mercuryo widget.
422003 422 The quote doesn't match the user's current location or other data. Request a new quote and repeat the payment.
5xxxxx 5xx Internal server error. Retry later.