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.
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.
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.
To handle iDEAL payments we'll need an instance of AMNL\Mollie\IDeal\IDealGateway
. The constructor has the following parameters:
$partner_id
- Your Mollie Partner ID (account number)$profile_key
- Profile key [optional]
$testmode
- Set to false to disable the test mode [optional - true by default]
$base_url
- Sets the base URL used for API calls [optional - defaults to null, which means the default url will be used]
$client
- Instance of the Buzz client that should be used to issue requests. Should be an instance of \Buzz\Client\ClientInterface.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);
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();
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:
$amount
- Amount that must be paid, in Euro cents
$report_url
- URL that will be called to inform your application of a status update$return_url
- URL the customer will be send to after the payment process is done (even if it was unsuccessful!)$description
- Description which will be visible to the customer$options
- Array of additional options needed for a specific gateway. In case of the IDealGateway this should contain a key bank which has a Bank instance or a bank ID (int / string) as its value.When the payment is prepared the preparePayment
method returns an instance of AMNL\Mollie\ProviderResponse
. This object has three properties:
transactionId
- The name says it all: identifier for the transaction that has just been created.amount
- Amount in eurocentsdestination
- URL to which the user should be forwardedMost likely you would want to store the transactionId
(for example in an Order object), before forwarding the user to the URL provided in destination
.
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.
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.
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.
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.