Private preview
Set up future MoMo payments Private preview
Learn how to save MoMo details and charge your customers later.
Checkout
Elements
Direct API
You can use Stripe-hosted Checkout to collect MoMo payment method details in advance, and determine the final amount or payment date later. Use it to:
- Save payment methods to use in future purchases
- Collect surcharges after fulfilling a service
- Start a free trial for a subscription
Alternatively, you can save payment details during a MoMo payment and charge the saved payment method immediately.
First, you need a Stripe account. Register now.
To access the Stripe API from your application, use our official libraries:
Command Line
Select a language
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# Available as a gem
sudo gem install stripe
Gemfile
Select a language
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# If you use bundler, you can add this line to your Gemfile
gem 'stripe'
Create a Checkout Session Server-side
Your customer must authorize you to use their MoMo wallet for future payments through Stripe Checkout. Enable MoMo in your Dashboard. Stripe automatically displays MoMo to eligible customers using dynamic payment methods. If you currently specify payment_method_types, see the migration guide.
Create a Checkout Session in setup mode and specify the customer’s ID.
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
Caution
Don’t rely on the redirect to the success_url alone for detecting payment initiation, because:
- Malicious users could directly access the success _ url without paying and gain access to your goods or services.
- After a successful payment, customers might close their browser tab before they’re redirected to the success _ url .
Retrieve the payment method Server-side
After a customer submits their payment details, retrieve the PaymentMethod object. A PaymentMethod stores the customer’s MoMo wallet information for future payments. You can retrieve the PaymentMethod synchronously using the success_url or asynchronously using webhooks.
The decision to retrieve the PaymentMethod synchronously or asynchronously depends on your tolerance for dropoff, as customers might not always reach the success_url after a successful payment (for example, it’s possible for them to close their browser tab before the redirect occurs). Using webhooks prevents your integration from experiencing this form of dropoff.
Handle checkout.session.completed webhooks, which contain a Session object. To learn more, see setting up webhooks. The following example is a checkout.session.completed response.
{
"id": "evt_1Ep24XHssDVaQm2PpwS19Yt0",
"object": "event",
"api_version": "2019-03-14",
"created": 1561420781,
"data": {
"object": {
"id": "cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k",
"object": "checkout.session",
"billing_address_collection": null,
"client_reference_id": null,
"customer": null,
"customer_email": null,
"display_items": [],
"mode": "setup",
"setup_intent": "seti_1EzVO3HssDVaQm2PJjXHmLlM",
"submit_type": null,
"subscription": null,
"success_url": "https://example.com/success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}
Note the value of the setup_intent key, which is the ID for the SetupIntent created with the Checkout Session. A SetupIntent is an object used to set up the customer MoMo wallet information for future payments. Retrieve the SetupIntent object with the ID. The returned object contains the payment_method ID.
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
Monitor webhooks Server-side
Stripe sends a setup_intent.succeeded event when the setup succeeds and the payment method is saved. If the setup fails, Stripe sends a setup_intent.setup_failed event.
Use these events to update your customer’s saved payment method state before attempting off-session payments.
For security, verify incoming webhook signatures and allow traffic from Stripe public IP addresses.
Charge a saved MoMo payment method Server-side
When you’re ready to charge your customer, use the customer’s ID and the PaymentMethod ID to create a PaymentIntent.
To find a momo instrument to charge, list the payment methods associated with your customer.
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
When you have the customer and PaymentMethod IDs, create and confirm a PaymentIntent with the amount and currency of the payment. To charge your customer off session, set off_session to true. That indicates that the customer isn’t in your checkout flow during this payment attempt.
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
Note
The return_url parameter isn’t required when using a MoMo payment method that was previously set up with a SetupIntent or a PaymentIntent with setup_future_usage. It’s required for all other cases.
Test your integration
When testing your payment integration with your test API keys, select MoMo as the payment method and click Pay. If you authorize the mandate on the redirect page, the SetupIntent transitions from requires_action to succeeded. If you decline the mandate on the redirect page, the SetupIntent transitions from requires_action to requires_payment_method.
