Google Pay
- Web
- Native Android App
Web Integration
You can start accepting Google Pay payments on the Web using Hosted Payment Page or Payment Request Component. No additional configuration is required.
Our Payment Request Component gives you a single integration for Apple Pay and Google Pay. Customers see a Google Pay or an Apple Pay button, depending on what their device and browser combination supports.
If you prefer to integrate directly against the Google Pay API, follow the direct API integration guide below.
Before you begin
To accept Google Pay payments you need to have at least one configured card processor.
To configure card processors go to MONEI Dashboard → Settings → Payment Methods → Card payments.
Before you start, you need to:
- Make sure that you have Google Pay enabled in MONEI Dashboard → Settings → Payment Methods.
- Add a card in Chrome.
- Serve your application over HTTPS. This is a requirement both in development and in production. One way to get up and running is to use a service like ngrok.
To test your integration:
- Use your test mode Account ID and API Key.
- You can use any real card details, you will not be charged in the test mode (card details are automatically replaced with the test card).
- You can check the status of the test payment in your MONEI Dashboard → Payments (in test mode).
By integrating Google Pay™, you adhere to the Google Pay APIs Acceptable Use Policy and accept the terms defined in the Google Pay API Terms of Service.
Direct API Integration
If you prefer to integrate directly against the Google Pay API, follow Google's instructions.
Specify following tokenization specification:
const tokenizationSpecification = {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'monei',
gatewayMerchantId: 'MONEI_ACCOUNT_ID'
}
};
To use Google Pay API directly you need to request production access and obtain your merchantId in Google Console (this step is not required if you are using our Google Pay Component).
paymentDataRequest.merchantInfo = {
merchantName: 'Example Merchant',
merchantId: 'GOOGLE_MERCHANT_ID'
};
Exchange Google Pay token for MONEI Payment Token that can be used to confirm payment:
function processPayment(paymentData) {
// Encode Google Pay token as a base64 string
const token = window.btoa(paymentData.paymentMethodData.tokenizationData.token);
return monei.api
.createToken({
paymentId: '{{payment_id}}',
paymentMethod: {
googlePay: {
token: token
}
}
})
.then(function (result) {
return moneiTokenHandler(result.paymentToken);
});
}
Confirm the Payment
After you have obtained the MONEI Payment Token, you can confirm the payment using the token.
function moneiTokenHandler(token) {
return monei
.confirmPayment({paymentId: '{{payment_id}}', paymentToken: token})
.then(function (result) {
// At this moment you can show a customer the payment result
// But you should always rely on the result passed to the callback endpoint on your server
// to update the order status
console.log(result);
})
.catch(function (error) {
console.log(error);
});
}
Native Android App Integration
Google Pay works out of the box on Android with no additional certificate setup required. Simply integrate the Google Pay API and use MONEI as your payment gateway.
Prerequisites
- Google Pay enabled in MONEI Dashboard → Settings → Payment Methods
- At least one configured card processor in MONEI Dashboard
- Android device or emulator with Google Play Services
Add Dependencies
Add the Google Pay library to your app's build.gradle:
dependencies {
implementation 'com.google.android.gms:play-services-wallet:19.2.1'
}
Add the Google Pay API meta-data to your AndroidManifest.xml:
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
Check Google Pay Availability
Before showing the Google Pay button, verify it's available on the device:
val paymentsClient = Wallet.getPaymentsClient(
this,
Wallet.WalletOptions.Builder()
.setEnvironment(WalletConstants.ENVIRONMENT_TEST) // Use ENVIRONMENT_PRODUCTION for live
.build()
)
val isReadyToPayRequest = IsReadyToPayRequest.fromJson("""
{
"apiVersion": 2,
"apiVersionMinor": 0,
"allowedPaymentMethods": [{
"type": "CARD",
"parameters": {
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"allowedCardNetworks": ["VISA", "MASTERCARD", "AMEX", "DISCOVER", "JCB"]
}
}]
}
""")
paymentsClient.isReadyToPay(isReadyToPayRequest)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
// Show Google Pay button
}
}
Configure Payment Request
Create a payment request with MONEI as the gateway:
val paymentDataRequest = PaymentDataRequest.fromJson("""
{
"apiVersion": 2,
"apiVersionMinor": 0,
"allowedPaymentMethods": [{
"type": "CARD",
"parameters": {
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"allowedCardNetworks": ["VISA", "MASTERCARD", "AMEX", "DISCOVER", "JCB"]
},
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "monei",
"gatewayMerchantId": "YOUR_MONEI_ACCOUNT_ID"
}
}
}],
"merchantInfo": {
"merchantName": "Your Store Name",
"merchantId": "YOUR_GOOGLE_MERCHANT_ID"
},
"transactionInfo": {
"totalPrice": "10.00",
"totalPriceStatus": "FINAL",
"currencyCode": "EUR",
"countryCode": "ES"
}
}
""")
Launch Google Pay
Launch the Google Pay payment sheet when the user taps the button:
private val googlePayLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
when (result.resultCode) {
Activity.RESULT_OK -> {
result.data?.let { intent ->
val paymentData = PaymentData.getFromIntent(intent)
handlePaymentSuccess(paymentData)
}
}
Activity.RESULT_CANCELED -> {
// User cancelled
}
AutoResolveHelper.RESULT_ERROR -> {
// Handle error
}
}
}
fun requestPayment() {
val task = paymentsClient.loadPaymentData(paymentDataRequest)
AutoResolveHelper.resolveTask(task, this, GOOGLE_PAY_REQUEST_CODE)
}
Process the Payment
Extract the token from the payment data and send it to your backend:
private fun handlePaymentSuccess(paymentData: PaymentData?) {
val paymentInfo = paymentData?.toJson() ?: return
val json = JSONObject(paymentInfo)
// Extract the Google Pay token
val token = json
.getJSONObject("paymentMethodData")
.getJSONObject("tokenizationData")
.getString("token")
// Base64 encode the token
val encodedToken = Base64.encodeToString(token.toByteArray(), Base64.NO_WRAP)
// Send to your backend to create MONEI payment token and confirm payment
sendToBackend(encodedToken)
}
Backend Integration
On your backend, exchange the Google Pay token for a MONEI payment token:
# 1. Create a payment
curl -X POST https://api.monei.com/v1/payments \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"amount": 1000,
"currency": "EUR",
"orderId": "order_123"
}'
# 2. Create a token from Google Pay token
curl -X POST https://api.monei.com/v1/payment-tokens \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"paymentId": "PAYMENT_ID_FROM_STEP_1",
"paymentMethod": {
"googlePay": {
"token": "BASE64_ENCODED_GOOGLE_PAY_TOKEN"
}
}
}'
# 3. Confirm the payment
curl -X POST https://api.monei.com/v1/payments/PAYMENT_ID/confirm \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"paymentToken": "MONEI_TOKEN_FROM_STEP_2"
}'
Before you go live
- Make sure that you are using live (production) mode Account ID and API Key.
- Make sure that you have at least one enabled card processor.
- Make sure that you have Google Pay enabled in MONEI Dashboard → Settings → Payment Methods.
- For direct API integration, request production access from Google and obtain your
merchantId.