Mollie Payment Gateway
Configuration
First, you'll need to add Mollie to your simple-commerce.php
config file. You will also need to pass in key
and secret
variables.
You can obtain your API keys from the Mollie Dashboard.
1'gateways' => [2 \DoubleThreeDigital\SimpleCommerce\Gateways\Builtin\MollieGateway::class => [3 'key' => env('MOLLIE_KEY'),4 'profile' => env('MOLLIE_PROFILE'),5 ],6],
It's best practice to use
.env
file for any API keys you need, rather than referencing them directly in your config file. Review Statamic Docs.
Payment flow
Mollie is an off-site gateway, which means the customer is redirected onto Mollie's checkout page to complete payment. Here's a quick run down of how the whole process works:
- After filling out shipping info etc, the store redirects the customer to Mollie
- The customer enters their payment information on Mollie's checkout
- If the payment is successful, a webhook is sent to your server.
- The customer is then redirected back to your site.
Handing the user off to Mollie's checkout
To redirect the customer off to Mollie's checkout page, you can use the sc:checkout:mollie
tag.
1{{ sc:checkout:mollie redirect="/thanks" error_redirect="/payment-error" }}
However, bear in mind that where-ever you use that tag, the customer will be redirected away from your site. So it's probably best to have it sitting on it's own page.
Handling Mollie's webhook
The Mollie gateway has a webhook which is hit by Mollie whenever a payment is made.
Simple Commerce will configure the webhook on Mollie's end. However, you'll need to add the webhook URL to your list of CSRF exceptions, found in app/Http/Middleware/VerifyCsrfToken.php
.
1protected $except = [2 '/!/simple-commerce/gateways/mollie/webhook',3];
When you're going through the payment flow in your development environment, you will need to use something like Expose or Ngrok to proxy request to your local server. Otherwise, Mollie wouldn't be able to hit the webhook. You will also need to update the APP_URL
in your .env
.
Handling the redirect back to your site
On the return back to your site from Mollie, you can have customers redirected to seperate URLs, depending on whether the payment was successful or failed/cancelled.
The redirect
parameter on the sc:checkout:mollie
tag will handle the successful payment redirects.
Where as error_redirect
will handle any other payment states.
Code highlighting provided by Torchlight.