Integrating Mion as a payment method consists of the following steps:
-
Creating a payment session
-
Forwarding the user to Mion checkout
-
Verifying the payment status
Creating a payment session
Create a payment session by calling the endpoint Initiate a new payment session. Be sure to call this endpoint from your backend.
This is an authenticated endpoint for which you must use an API key that you can create in the Mion web UI. Remember to set the Payments Read & Write permission for the API key. The usage of the API key is explained here.
Notes:
-
Only "EUR" is currently supported as the
currencyIso3
-
The
amount
must be given in cents. For example, for 12 € set theamount
to 1200. -
Payments on the Bitcoin blockchain can take hours, so set a sufficiently long
expiry
It is highly suggested to save the payment session id
(returned from the request) into your database. Alternatively, you can also use the (optional) reference
to identify the payment session at Mion.
Forwarding the user to Mion checkout
After the payment session is successfully created, redirect the user to https://app.mion.group/checkout/<payment session id>
Replace the <payment session id>
with the payment session id that you got when the payment session was created.
Verifying the payment status
To verify if the user has completed the payment, call one of the endpoints: Get a payment session status, Retrieve a payment session by its reference, or Retrieve a payment session by its ID.
It's also possible to initiate a webhook to get the status updates in real time with the endpoint: Initiate a webhook for payment session status updates
If in the response of these calls, paidAt
has a valid timestamp, the user has successfully paid the requested amount.
In this case the status will be one of the following statuses that indicate a completed payment: "funding-received"
, "funding-collected"
, "exchanged"
, "funded"
Verify the payment status when the user returns to the redirectUrl
. At that point the payment should be completed.
Payment status verification asynchronously
(In addition to when user returns to your page) you should also either:
-
Create a background process that periodically checks the payment status until the payment session expires.
-
Get status updates from the "status update webhook".
This is because the user might close the browser before the redirect or loses connection, in which case the redirect back to the redirectUrl
never happens even though the payment is successful.
Development notes
- When testing such that both "merchant UI" and "checkout UI" is used, it's best to use different browsers or for example incognito mode for one of those. The login for both uses same mechanisms and it's not possible to be simultaneously loggend in as a "merchant user" and a customer.