Accept a GrabPay payment
Learn how to accept GrabPay, a common payment method in Southeast Asia.
Note
Subscriptions and using GrabPay for future payments aren’t currently supported. Reach out to Stripe support for any support queries on these features.
GrabPay is a single-use payment method. Customers pay with GrabPay by redirecting from your app to GrabPay, authorising the payment, then returning to your app where you get immediate notification on whether the payment succeeded or failed.
Note
Learn more about activating GrabPay in the Dashboard.
Set up StripeServer-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create a PaymentIntentServer-side
A PaymentIntent represents your intent to collect payment from a customer and tracks the lifecycle of the payment process.
Create a PaymentIntent
on your server and specify the amount
to collect and sgd
or myr
as the currency. There is no minimum charge amount for GrabPay so the payment amount can be as low as 1. If you have an existing Payment Intents integration, add grabpay
to the list of payment method types.
Retrieve the client secret
The PaymentIntent includes a client secret that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side.
Submit the payment to StripeClient-side
When a customer clicks to pay with GrabPay, use Stripe.js to submit the payment to Stripe. Stripe.js is the foundational JavaScript library for building payment flows. It automatically handles complexities like the redirect described below, and enables you to extend your integration to other payment methods. Include the Stripe.js script on your checkout page by adding it to the head
of your HTML file.
<head> <title>Checkout</title> <script src="https://js.stripe.com/basil/stripe.js"></script> </head>
Create an instance of Stripe.js with the following JavaScript on your checkout page.
// Set your publishable key. Remember to change this to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe(
);'pk_test_TYooMQauvdEDq54NiTphI7jx'
To create a payment on the client side, add a Pay with GrabPay button and use stripe.
to handle the redirect away from your page and to complete the payment.
<button type="button" id="grabpay-button">Pay with GrabPay</button> <div id="error-message"></div>
const button = document.getElementById('grabpay-button'); button.addEventListener('click', async function() { // By this point, the PaymentIntent should have already been created // Pass the clientSecret of the PaymentIntent to confirmGrabPayPayment stripe.confirmGrabPayPayment(clientSecret, { // Return URL where the customer should be redirected after the authorization return_url: 'https://example.com/checkout/complete', }); });
Pass the client secret of the PaymentIntent
object that you created in Step 2 to stripe.
.
Additionally, add a return_
to this function to indicate where Stripe should redirect the user after they complete the payment on Grab’s website.
When your customer submits a payment, Stripe redirects them to the return_
and includes the following URL query parameters. The return page can use them to get the status of the PaymentIntent so it can display the payment status to the customer.
When you specify the return_
, you can also append your own query parameters for use on the return page.
Parameter | Description |
---|---|
payment_ | The unique identifier for the PaymentIntent . |
payment_ | The client secret of the PaymentIntent object. For subscription integrations, this client_secret is also exposed on the Invoice object through confirmation_ |
When the customer is redirected back to your site, you can use the payment_
to query for the PaymentIntent and display the transaction status to your customer.
<h2>Payment result</h2> <div class="payment-result"> </div> <script> // Check if we're returning from a redirect. const url = new URL(window.location.href); const paymentIntentClientSecret = url.searchParams.get( "paymentIntentClientSecret" ); if (paymentIntentClientSecret) { stripe.retrievePaymentIntent(paymentIntentClientSecret).then(function(result) { const paymentIntent = result.paymentIntent; document.querySelector(".payment-result").textContent = paymentIntent.status; }); } </script>
Test your integration
When testing, the client side redirect brings you to a Stripe-hosted GrabPay test payment page where you can either authorise or fail the test payment.
OptionalHandle post-payment events
Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard, a custom webhook, or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the differences between all supported payment methods.
Receive events and run business actions
There are a few options for receiving and running business actions.
Manually
Use the Stripe Dashboard to view all your Stripe payments, send email receipts, handle payouts, or retry failed payments.
Custom code
Build a webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI.
Prebuilt apps
Handle common business events, such as automation or marketing and sales, by integrating a partner application.
OptionalHandle the GrabPay redirect manually
We recommend relying on Stripe.js to handle GrabPay redirects and payments with confirmGrabPayPayment
. However, you can also manually redirect your customers by:
- Providing the URL where your customers will be redirected after they complete their payment.
- Confirming the
PaymentIntent
has a status ofrequires_
. The type for theaction next_
will beaction redirect_
.to_ url
{ "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }, "payment_method_types": [ "grabpay" ], "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", "amount": 1099, "confirmation_method": "automatic",
- Redirecting the customer to the URL provided in the
next_
property.action
const action = intent.next_action; if (action && action.type === 'redirect_to_url') { window.location = action.redirect_to_url.url; }
When the customer finishes the payment process, they’re sent to the return_
destination. The payment_
and payment_
URL query parameters are included and you can pass through your own query parameters, as described above.
Supported currencies
Stripe users in Malaysia and Singapore can accept GrabPay payments from customers in Malaysia and Singapore respectively. Review the supported currencies and GrabPay transaction limits below:
Country | Customer country | Supported currency | Transaction limits |
---|---|---|---|
Singapore (SG) | Singapore (SG) | SGD | GrabPay SG |
Malaysia (MY) | Malaysia (MY) | MYR | GrabPay MY |