Payment and Mollie in Drupal 8

Submitted by christophe on Tue, 15/08/2017 - 10:22
Mollie logo

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, ...).

 

Get the Mollie Payment module

composer require drupal/mollie

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.
 

Mollie test profile

Define the site URL under Contact information. Then define the desired Payment methods.

Mollie 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

Mollie add profile under Drupal

Test then the connection under /admin/config/services/payment/mollie/connection-test

Mollie Drupal connection test

 

Configure the Payment module

Add the Mollie payment method under /admin/config/services/payment/method

Mollie Drupal payment method

Configure the Currency module

Add or import a currency, preferably import it. Here we will use EUR.

Drupal currency, add or import

Drupal currency, import

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

Add product content type


Then add a Payment Form field and configure it.

Add payment form field

just set the currency if desired

Product form currency

 

Create a product

Create a product

And voilà, here is the result

View product

Mollie payment page

 

Resources

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.