Google Pay
Process Flow
Flow diagram
Explanation
- Step 1: Check Google Pay Availability: Ensure Google Pay availability on the user's device before displaying it as a payment option.
- Step 2: Proceed to Checkout: User selects "Pay via Google Pay" provided by MoMo in the checkout process.
- Step 3: Create Payment Request: Initiate an order with a unique orderId and send a payment request to MoMo, request the Google Pay payment method using your credentials.
- Step 4: Return Payment URL: After MoMo authenticates the request, we respond with a payment URL (payUrl).
- Step 5: Redirect to MoMo Web: For merchants operating on a website, redirect the user to MoMo's website using the payUrl.
- Step 6: Display Google Pay Payment Page: MoMo Gateway displays order information and asks users to confirm the payment using the Google Pay button.
- Step 7: Confirm Payment: User authenticates and confirms the payment through Google Pay on their device.
- Step 8: Process Payment: MoMo processes the payment, returns the payment result, and redirects the user back to your web/app.
- Step 9: Display Payment Result: Receive the payment result and present it on the user's device.
API Configuration
Check Google Pay Availability
Before users proceed to checkout, it's essential to verify the availability of Google Pay. Only display Google Pay payment method if Google Pay is confirmed as available during the user checkout session.
1. Include Google's hosted JavaScript on your page
<script async
src="https://pay.google.com/gp/p/js/pay.js"
onload="console.log('TODO: add onload function')">
</script>
2. After the Google Pay API JavaScript library loads, initialize a PaymentsClient object
- For development uses a TEST environment
- For production uses a PRODUCTION environment
const paymentsClient =
new google.payments.api.PaymentsClient({environment: 'TEST'});
3. Add MoMo E-wallet payment methods to your base request object
const baseRequest = {
apiVersion: 2,
apiVersionMinor: 0
};
const baseEwalletPaymentMethod = {
type: "EWALLET",
processingSpecification: {
type: "MOMO",
}
}
const isReadyToPayRequest = Object.assign({}, baseRequest);
isReadyToPayRequest.allowedPaymentMethods = [baseEWalletPaymentMethod];
4. Call isReadyToPay() to determine if the Google Pay API is supported by the current device and browser for your specified payment methods
paymentsClient.isReadyToPay(isReadyToPayRequest)
.then(function(response) {
if (response.result) {
// Display Google Pay payment button
}
})
.catch(function(err) {
// show error in developer console for debugging
console.error(err);
});
Payment method
After users select products or services and make a payment using Google Pay on the merchant website, the merchant server must call the MoMo API to obtain the payment URL, then redirects users to the obtained payment page.
API information to retrieve payment URL
POST /v2/gateway/api/create
requestType: Identify the type of the request
| Attribute | Type | Required | Description |
|---|---|---|---|
| partnerCode | String | Integration information | |
| partnerName | String | Partner name | |
| storeId | String | Store ID | |
| requestId | String(50) | Request ID, unique for each request, MoMo's partner uses the requestId field for idempotency control | |
| amount | Long | Amount needs to be paid Min: 1.000 VND Max: 50.000.000 VND Currency: VND Data type: Long | |
| orderId | String | Partner Transaction ID Regex: ^[0-9a-zA-Z]([-_.]*[0-9a-zA-Z]+)*$ | |
| orderInfo | String | Order's information | |
| redirectUrl | String | A partner's URL. This URL is used to redirect from MoMo page to partner's page after customer's payment. Support: AppLink and WebLink | |
| ipnUrl | String | Partner API. Used by MoMo to submit payment results by IPN method (server-to-server) method | |
| requestType | String | payWithGPay | |
| extraData | String | Default value is empty "" Encode base64 follow Jsonformat: {"key": "value"} Example with data: {"username": "momo"}=> data of extraData: eyJ1c2VybmFtZSI6ICJtb21vIn0= | |
| userInfo | Object | Info of the customer, in which email is required. | |
| autoCapture | Boolean | If set to false, the payment will not be automatically captured. | |
| lang | String | Language of returned message (vi or en) | |
| signature | String | HMAC_SHA256accessKey=$accessKey&amount=$amount&extraData=$extraData&ipnUrl=$ipnUrl&orderId=$orderId&orderInfo=$orderInfo&partnerCode=$partnerCode&redirectUrl=$redirectUrl&requestId=$requestId&requestType=$requestType,secretKey) |
Details of userInfo content
If implemented, customers will have the option to choose between receiving notifications or emails.
| Attribute | Type | Required | Description |
|---|---|---|---|
| name | String | Name of the customer as registered on merchant site | |
| phoneNumber | String | Phone number of the customer as registered on merchant site | |
| String | Email address of the customer as registered on merchant site |
Redirecting information (redirectUrl)
WebLink: Links to open website.
AppLink: Link to open mobile application.
Learn more about AppLink
- Android: https://developer.android.com/training/app-links
- IOS: https://developer.apple.com/documentation/uikit/core_app/..
Example request
{
"partnerCode": "MOMO",
"partnerName": "Test",
"storeId": "MomoTestStore",
"requestType": "payWithGPay",
"userInfo": {
"email": "email_add@domain.com"
},
"ipnUrl": "http://www.example.com",
"redirectUrl": "http://www.example.com",
"orderId": "6d0a1b10-b382-11e9-8fda-91fa25841420",
"amount": 30000,
"lang": "vi",
"orderInfo": "pay with GPay",
"requestId": "6d0a1b11-b382-11e9-8fda-91fa25841420",
"extraData": "eyJlbWFpbCI6ICJleGFtcGxlQGdtYWlsLmNvbSJ9",
"signature": "5344e1f4244173fe0ba2b4c865881aad79b86beff8154b4f74f3b92634ffa711"
}
| Attribute | Type | Required | Description |
|---|---|---|---|
| partnerCode | String | Integration Information | |
| requestId | String | Same as the original request | |
| orderId | String | Partner Transaction ID Regex: ^[0-9a-zA-Z]([-_.]*[0-9a-zA-Z]+)*$ | |
| amount | Long | Same as the original payment amount | |
| responseTime | Long | Time to respond payment results to partner Format: timestamp | |
| message | String | Error description, error language is based on lang | |
| resultCode | int | Error code | |
| payUrl | String | URL for switching from the partner's page to the MoMo payment page |
Example response
{
"partnerCode": "MOMO",
"requestId": "6d0a1b11-b382-11e9-8fda-91fa25841420",
"orderId": "6d0a1b10-b382-11e9-8fda-91fa25841420",
"amount": 30000,
"responseTime": 14547523457,
"message": "Success",
"resultCode": 0,
"payUrl": "https://test-payment.momo.vn/v2/gateway/pay?t=TU9NT1NKSTEyMDE5MDgyM3wxNjEyODQwNTMyNDI3OjAxMjM0NTY3Nzg="
}
Processing payment result
For more information, see Payment Notification.
Parameter description
Description for parameters which are used by MoMo in the URL redirectUrl and the body content of ipnUrl.
| Attribute | Type | Required | Description |
|---|---|---|---|
| partnerCode | String | Integration information | |
| requestId | String | Each Request’s Identification | |
| amount | Long | Amount to pay | |
| orderId | String | OrderId of partner, unique for each request | |
| orderType | String | momo_wallet | |
| orderInfo | String | Order info | |
| partnerUserId | String | MoMo's unique identifier for each MoMo eWallet account. | |
| transId | Long | MoMo's transaction ID | |
| resultCode | Integer | Order status | |
| message | String | description of resultCode based on lang | |
| payType | String | web , | |
| responseTime | Long | Time to return payment result in miliseconds | |
| extraData | String | Additional info | |
| signature | String | Signature to confirm information. Secure transaction in Hmac_SHA256 algorithm with format: a String sort all key name of data field from a-z: accessKey=$accessKey&amount=$amount&extraData=$extraData&message=$message&orderId=$orderId&orderInfo=$orderInfo&orderType=$orderType&partnerCode=$partnerCode&payType=$payType&requestId=$requestId&responseTime=$responseTime&resultCode=$resultCode&transId=$transId |