- Published on
Payment and Mollie in Drupal 8
- Authors
- Name
- Christophe Jossart
- @colorfield
Outdated content
Most content from this article might still be relevant but some sections can be outdated.
Mollie provides a facade for several payment methods (credit card, debit card, Paypal, Sepa, Bitcoin, ...) with various languages and frameworks support.
In some cases, you could decide to use the Payment module instead of the full Commerce distribution.
This tutorial describes how to create a product as a node and process payment with Mollie, only via configuration. A possible use case can be an existing Drupal 8 site that just needs to enable a few products (like membership, ...).
Mollie Payment module
Get thecomposer require drupal/mollie_payment
Composer will install the Mollie API client library for you into the vendor directory, so no need to download it into the libraries directory.
Enable the module, it will also enable the Plugin, Currency and Payment modules.
drush en mollie_payment
Enable the Payment Form module (that is shipped with the Payment module).
drush en payment_form
At the time of writing, you will need to use the Payment dev release.
composer require drupal/payment:2.x-dev
Then patch the line items ajax issue.
cd LOCAL_PATH/modules/contrib/payment
curl -O https://www.drupal.org/files/issues/fix_ajax-1.patch
patch -p1 < fix_ajax-1.patch
For deploying in other environments, make sure that your main composer.json file contains the patch into the extra section.
"patches": {
"drupal/payment": {
"Ajax broken in payment_form submodule": "https://www.drupal.org/files/issues/fix_ajax-1.patch"
}
},
Troubleshooting
If this error is triggered while viewing a line item:
Call to undefined function Drupal\payment\Entity\bcadd() in Drupal\payment\Entity\Payment->getAmount()
or this one while importing a currency:
Error: Call to undefined function Commercie\Currency\bcdiv() in Commercie\Currency\Currency->getRoundingStep()
bcadd or bcdiv is missing, so install the bcmath php extension.
Composer should warn you about the missing ext-bcmath, but in some situations it can happen that the modules are being required properly but the error occurs at runtime (e.g. your command line php version is 7.0 and your Apache vhost version is 7.1, with a bcmath enabled for 7.0 but not for 7.1).
It can be easily fixed, here we are using php 7.1 on our vhost
sudo apt-get install php7.1-bcmath
# restart your server, here we assume Apache
sudo service apache2 restart
Create a Mollie account
After signing up, you will immediately receive a Test API key and a preconfigured Test profile that you can adapt to your configuration.
Define the site URL under Contact information. Then define the desired Payment methods.
Configure the Mollie Payment module
Head to /admin/config/services/payment/mollie (or click on Configuration > Web Services > Payment > Mollie Payment).
Create a Mollie profile
Test then the connection under /admin/config/services/payment/mollie/connection-test
Configure the Payment module
Add the Mollie payment method under /admin/config/services/payment/method
Configure the Currency module
Add or import a currency, preferably import it. Here we will use EUR.
If you want to add manually a currency, refer to the following documentation to get the ISO 4217:2015 reference:
Create a product content type
Then add a Payment Form field and configure it.
just set the currency if desired
Create a product
And voilà, here is the result
Resources
- Slideshare Anatomy of payment systems in Drupal 8
- Drupal.org Payment handbook
- Mollie Payment contrib module
- Commerce Mollie contrib module