AMNL\Mollie

PHP 5.3+ library for communicating with Mollie (PSP)

The goal of this PHP 5.3+ library is to simplify the implementation of the payment methods offered by Mollie B.V.

Installation

You can easily install this library using Composer by adding it to your composer.json or by running this command from your command-line:

php composer.phar require amnl/mollie

If you will be using Symfony 2, you can choose to install the bundle created by @ruudk, which can be found here. And finally, if you aren't using composer or Symfony 2, you can just download the code as an archive.

Usage

Every client implements the AMNL\Mollie\ProviderGateway interface. This is done to make it easier to implement the other payment methods when you've already implemented one. This also means that every client has a checkPayment and a preparePayment method.

iDEAL

To handle iDEAL payments we'll need an instance of AMNL\Mollie\IDeal\IDealGateway. The constructor has the following parameters:

So, let's say your Partner ID is 123456, then you would need to following code to get started (assuming you have an autoloader mechanism in place).

<?php
$gateway = new \AMNL\Mollie\IDeal\IDealGateway(123456);

0. Get list of banks

Before you can prepare a payment, we first need to know which bank the customer is going to use. You can get a list of banks by calling the getBankList method on the gateway instance, which gives you an array of \AMNL\Mollie\IDeal\Bank. You'll need a Bank-object or a bank ID when preparing a payment.

<?php
$banks = $gateway->getBankList();

1. Prepare payment

To prepare a payment and get the URL you should redirect your customer to, you can call either the preparePayment or the prepareIDealPayment method on the gateway instance. The latter will call the former internally.

The method signature of preparePayment is pretty much compatible across all the different payment gateways included in this library. preparePayment accepts the following parameters:

2. Redirect the user

When the payment is prepared the preparePayment method returns an instance of AMNL\Mollie\ProviderResponse. This object has three properties:

Most likely you would want to store the transactionId (for example in an Order object), before forwarding the user to the URL provided in destination.

3. Thank You!

It's very likely that the user will return on the return_url set in 1. Prepare Payment before the transaction has been cleared. You might want to say thank you on the page served at the return_url and let the user know his/her transaction is being processed.

4. Get transaction status

When the report_url is called, it's time to get the status of the transaction. Mollie sends the transaction ID along in the GET-parameter called transaction_id (pretty straight-forward right?). All you have to do is call the checkPayment method on an IDealGateway instance and supply the transaction identifier as the first and only argument.

The method will return a IDealTransactionStatus (which inherits from the "global" AMNL\Mollie\TransactionStatus).

The property you'll be most interested in is paid (isPaid).

Important note (pre v1.0.1): If a transaction had the status "paid" (paid == true) and you request the status a second time, paid will still be true. This behaviour is different from the default implementation that Mollie uses. However, you can check the status property (which contains the message received from the API) to see if you have checked the transaction status before. This behavior is no longer present in release v1.0.1 and later. For more information, see issue #17.

Other payment services

AMNL\Mollie also offers support for Paysafecard, Minitix and IVR (micropayments). However we will not discuss those here, since the API of these gateways and the workflow are pretty much similar to the iDeal example given above.

Questions, bugs or other issues

If you have any questions, please contact the original author: Arno Moonen @itavero on GitHub).

If you come across a bug or notice some unexpected behavior, please add a new issue on GitHub.