-
Notifications
You must be signed in to change notification settings - Fork 54
REST Integration
For frontend purposes, we recommend that you use the GraphQL integration, which is more fleshed out.
To integrate the Mollie extension with a PWA using REST, we added 2 endpoints to the normal Magento 2 checkout flow.
This is a normal flow:
- Create cart
- Add products
- Set shipping information
- Place order
When using Mollie the order flow looks like this:
- Create cart
- Add products
- Set shipping information
- Create payment token
- Place order
- Start transaction
To create a payment token you should do a GET request to the applicable endpoint:
GET /V1/carts/mine/mollie/payment-token
GET /V1/guest-carts/:cartId/mollie/payment-token
This will return a random 32 character string:
TumUZulyLVk16boibN59euvSr1Quh6hR
Next, after placing the order, do a POST request to the endpoint with the payment token:
POST /V1/mollie/transaction/start
{
"token": "TumUZulyLVk16boibN59euvSr1Quh6hR"
}
The response will be the redirect URL. You should redirect your user to this URL:
https://www.mollie.com/payscreen/order/checkout/rhdz9w
This page will handle the payment and redirect your user back to your webshop. By default, the URL of the Magento installation is used, but in most cases, you'll want to provide a custom URL.
You can enter one under
Stores -> Configuration -> Sales -> Payment Methods -> Mollie -> General -> Use custom redirect url?
.
In some cases, you might want to reset the cart to active. For example, when a Point Of Sale transaction fails, you can use this endpoint to reset the cart and try again.
POST /V1/mollie/reset-cart/:payment-token
The payment token is the same as the one received from the Create a payment token step. After calling this endpoint you should call the start transaction endpoint again to retrieve a new redirect url.
After the order is placed, you can retrieve its details. You can do this by using the value of the {{order_hash}}
, which gets appended to your custom URL:
GET /V1/mollie/get-order/<hash-value>
A few payment methods like iDeal, KBC and Point Of Sale have extra information available which can be shown to the end-user in the checkout. For iDeal and KBC these are issuers, for Point Of Sale this are the available terminals.
You can retrieve this by calling:
GET /V1/mollie/payment-method/meta
The result will be an array for all available payment methods. Per method there are three keys: code
, issuers
and terminals
. Example:
[
{
"code": "mollie_methods_ideal",
"issuers": [
{
"id": "ideal_ABNANL2A",
"name": "ABN AMRO",
"image": "https:\/\/www.mollie.com\/external\/icons\/payment-methods\/ideal\/issuers\/ABNANL2A.svg",
"images": [
"https:\/\/www.mollie.com\/external\/icons\/payment-methods\/ideal\/issuers\/ABNANL2A.png",
"https:\/\/www.mollie.com\/external\/icons\/payment-methods\/ideal\/issuers\/ABNANL2A%402x.png",
"https:\/\/www.mollie.com\/external\/icons\/payment-methods\/ideal\/issuers\/ABNANL2A.svg"
],
"image1x": "https:\/\/www.mollie.com\/external\/icons\/payment-methods\/ideal\/issuers\/ABNANL2A.png",
"image2x": "https:\/\/www.mollie.com\/external\/icons\/payment-methods\/ideal\/issuers\/ABNANL2A%402x.png",
"image_svg": "https:\/\/www.mollie.com\/external\/icons\/payment-methods\/ideal\/issuers\/ABNANL2A.svg"
},
{
"id": "ideal_ASNBNL21",
// ...
}
],
"terminals": [],
},
{
"code": "mollie_methods_pointofsale",
"issuers": [],
"terminals": [
{
"id": "term_xxxxxx",
"brand": "PAX",
"model": "A920Pro",
"serial_number": "111111111",
"description": "Terminal1"
}
]
},
]
When a manual order is created in the backend, it is possible to select Mollie Payment Link as payment method. This method adds a link in the order confirmation email where the customer can click on to pay the order. This link opens a page in the webshop. Some setups with a headless frontend want to implement a custom page for this step. That can be done by setting Stores -> Configuration -> Mollie -> Advanced -> PWA Storefront Integration -> Use custom payment link url?
to yes
. The URL then provided will receive an {{order}}
variable. This variable can be used to do a API call to retrieve the link to finish the payment.
GET {{url}}/rest/V1/mollie/get-payment-link-redirect/{{order}}
The response will be an array with two variables:
{
"already_paid": "false",
"redirect_url": "https://www.example.com"
}
To retrieve a list of recurring orders, you can use this endpoint:
GET /V1/mollie/orders/recurring
This endpoint uses the SearchCriteriaInteface
so you can filter and sort however you like.
Note: For this endpoint you need backend authentication, which differs from the other endpoints in this document.
The Mollie Payments extension is developed by Magmodules.
- Install Mollie using Composer
- Update Mollie using Composer
- Install Mollie using the Magento® Marketplace