mollie / mollie-api-php
Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment But
Installs: 9 042 617
Dependents: 54
Suggesters: 1
Security: 0
Stars: 558
Watchers: 68
Forks: 191
Open Issues: 1
Requires
- php: ^7.2|^8.0
- ext-curl: *
- ext-json: *
- ext-openssl: *
- composer/ca-bundle: ^1.2
Requires (Dev)
- eloquent/liberator: ^2.0||^3.0
- friendsofphp/php-cs-fixer: ^3.0
- guzzlehttp/guzzle: ^6.3 || ^7.0
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^8.5 || ^9.5
Suggests
- mollie/oauth2-mollie-php: Use OAuth to authenticate with the Mollie API. This is needed for some endpoints. Visit https://docs.mollie.com/ for more information.
- dev-master
- v3.x-dev
- v2.76.0
- v2.75.0
- v2.74.1
- v2.74.0
- v2.73.0
- v2.72.0
- v2.71.0
- v2.70.0
- v2.69.0
- v2.68.0
- v2.67.1
- v2.67.0
- v2.66.0
- v2.65.0
- v2.64.0
- v2.63.0
- v2.62.0
- v2.61.0
- v2.60.0
- v2.59.0
- v2.58.0
- v2.58.0-beta
- v2.57.0
- v2.56.1
- v2.56.0
- v2.55.0
- v2.54.0
- v2.53.0
- v2.52.1
- v2.52.0
- v2.51.0
- v2.50.1
- v2.50.0
- v2.49.2
- v2.49.1
- v2.49.0
- v2.48.0
- v2.47.0
- v2.46.0
- v2.45.0
- v2.44.1
- v2.44.0
- v2.43.0
- v2.42.1
- v2.42.0
- v2.41.0
- v2.40.2
- v2.40.1
- v2.40.0
- v2.39.0
- v2.38.0
- v2.37.1
- v2.37.0
- v2.36.1
- v2.36.0
- v2.35.0
- v2.34.0
- v2.33.0
- v2.32.2
- v2.32.1
- v2.32.0
- v2.31.2
- v2.31.1
- v2.31.1-alpha
- v2.31.0
- v2.31.0-alpha
- v2.30.2
- v2.30.1
- v2.30.0
- v2.29.0
- v2.28.0
- v2.27.2
- v2.27.1
- v2.27.0
- v2.26.0
- v2.25.0
- v2.24.0
- v2.23.0
- v2.22.3
- v2.22.2
- v2.22.2alpha
- v2.22.1
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- 2.17.1
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.1
- v2.13.0
- v2.12.1
- v2.12.0
- v2.11.0
- v2.10.0
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.0
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- 2.1.0
- v2.1.0-beta-1
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-beta-1
- v1.19.13
- v1.9.12
- v1.9.11
- v1.9.10
- v1.9.9
- v1.9.7
- v1.9.6
- v1.9.5
- v1.9.4
- v1.9.3
- v1.9.2
- 1.9.1
- 1.9.0
- 1.8.1
- 1.8.0
- 1.7.1
- 1.7.0
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- v1.4.0
- 1.3.3
- 1.3.2
- 1.3.1
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-feature/add-sales-invoices-endpoint
- dev-feature/add-sessions
- dev-v3-with-changed-endpoint-structure-poc
- dev-feature/add-trustly-enum
- dev-feature/add-auto-pagination-helper-methods
- dev-update-readme
- dev-feature/add-auto-pagination-iterator
- dev-add-create-client-links-endpoint
- dev-feature/add-can-be-canceled-method-to-refund-resource
- dev-vannut-patch-1
- dev-improve-refund-documentation
- dev-v1-develop
This package is auto-updated.
Last update: 2024-12-20 15:02:44 UTC
README
Mollie API client for PHP
Accepting iDEAL, Apple Pay, Bancontact, SOFORT Banking, Creditcard, SEPA Bank transfer, SEPA Direct debit, PayPal, Belfius Direct Net, KBC/CBC, paysafecard, ING Home'Pay, Giropay, EPS, Przelewy24, Postepay, In3, Klarna (Pay now, Pay later, Slice it, Pay in 3), Giftcard and Voucher online payments without fixed monthly costs or any punishing registration procedures. Just use the Mollie API to receive payments directly on your website or easily refund transactions to your customers.
Requirements
To use the Mollie API client, the following things are required:
- Get yourself a free Mollie account. No sign up costs.
- Now you're ready to use the Mollie API client in test mode.
- Follow a few steps to enable payment methods in live mode, and let us handle the rest.
- PHP >= 7.2
- Up-to-date OpenSSL (or other SSL/TLS toolkit)
For leveraging Mollie Connect (advanced use cases only), we recommend also installing our OAuth2 client.
Installation
Using Composer
The easiest way to install the Mollie API client is by using Composer. You can require it with the following command:
composer require mollie/mollie-api-php
To work with the most recent API version, ensure that you are using a version of this API client that is equal to or greater than 2.0.0. If you prefer to continue using the v1 API, make sure your client version is below 2.0.0. For guidance on transitioning from v1 to v2, please refer to the migration notes.
Manual Installation
If you're not familiar with using composer we've added a ZIP file to the releases containing the API client and all the packages normally installed by composer.
Download the mollie-api-php.zip
from the releases page.
Include the vendor/autoload.php
as shown in Initialize example.
Usage
Initializing the Mollie API client, and setting your API key.
$mollie = new \Mollie\Api\MollieApiClient(); $mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM");
With the MollieApiClient
you can now access any of the following endpoints by selecting them as a property of the client:
Find our full documentation online on docs.mollie.com.
Orders
Creating Orders
$order = $mollie->orders->create([ "amount" => [ "value" => "1027.99", "currency" => "EUR", ], "billingAddress" => [ "streetAndNumber" => "Keizersgracht 313", "postalCode" => "1016 EE", "city" => "Amsterdam", "country" => "nl", "givenName" => "Luke", "familyName" => "Skywalker", "email" => "luke@skywalker.com", ], "shippingAddress" => [ "streetAndNumber" => "Keizersgracht 313", "postalCode" => "1016 EE", "city" => "Amsterdam", "country" => "nl", "givenName" => "Luke", "familyName" => "Skywalker", "email" => "luke@skywalker.com", ], "metadata" => [ "some" => "data", ], "consumerDateOfBirth" => "1958-01-31", "locale" => "en_US", "orderNumber" => "1234", "redirectUrl" => "https://your_domain.com/return?some_other_info=foo", "webhookUrl" => "https://your_domain.com/webhook", "method" => "ideal", "lines" => [ [ "sku" => "5702016116977", "name" => "LEGO 42083 Bugatti Chiron", "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', "quantity" => 2, "vatRate" => "21.00", "unitPrice" => [ "currency" => "EUR", "value" => "399.00", ], "totalAmount" => [ "currency" => "EUR", "value" => "698.00", ], "discountAmount" => [ "currency" => "EUR", "value" => "100.00", ], "vatAmount" => [ "currency" => "EUR", "value" => "121.14", ], ], // more order line items ], ]);
After creation, the order id is available in the $order->id
property. You should store this id with your order.
After storing the order id you can send the customer off to complete the order payment using $order->getCheckoutUrl()
.
header("Location: " . $order->getCheckoutUrl(), true, 303);
This header location should always be a GET, thus we enforce 303 http response code
For an order create example, see Example - New Order.
Updating Orders
$order = $mollie->orders->get("ord_kEn1PlbGa"); $order->billingAddress->organizationName = "Mollie B.V."; $order->billingAddress->streetAndNumber = "Keizersgracht 126"; $order->billingAddress->city = "Amsterdam"; $order->billingAddress->region = "Noord-Holland"; $order->billingAddress->postalCode = "1234AB"; $order->billingAddress->country = "NL"; $order->billingAddress->title = "Dhr"; $order->billingAddress->givenName = "Piet"; $order->billingAddress->familyName = "Mondriaan"; $order->billingAddress->email = "piet@mondriaan.com"; $order->billingAddress->phone = "+31208202070"; $order->update();
Refunding Orders
Complete
$order = $mollie->orders->get('ord_8wmqcHMN4U'); $refund = $order->refundAll(); echo 'Refund ' . $refund->id . ' was created for order ' . $order->id;
Partially
When executing a partial refund you have to list all order line items that should be refunded.
$order = $mollie->orders->get('ord_8wmqcHMN4U'); $refund = $order->refund([ 'lines' => [ [ 'id' => 'odl_dgtxyl', 'quantity' => 1, ], ], "description" => "Required quantity not in stock, refunding one photo book.", ]);
Cancel Orders
When canceling an order it is crucial to check if the order is cancelable before executing the cancel action. For more information see the possible order statuses.
$order = $mollie->orders->get("ord_pbjz8x"); if ($order->isCancelable) { $canceledOrder = $order->cancel(); echo "Your order " . $order->id . " has been canceled."; } else { echo "Unable to cancel your order " . $order->id . "."; }
Order webhook
When the order status changes, the webhookUrl
you specified during order creation will be called. You can use the id
from the POST parameters to check the status and take appropriate actions. For more details, refer to Example - Webhook.
Payments
Payment Reception Process
Payment Reception Process documentation
To ensure a successful payment reception, you should follow these steps:
-
Utilize the Mollie API client to initiate a payment. Specify the desired amount, currency, description, and optionally, a payment method. It's crucial to define a unique redirect URL where the customer should be directed after completing the payment.
-
Immediately upon payment completion, our platform will initiate an asynchronous request to the configured webhook. This enables you to retrieve payment details, ensuring you know precisely when to commence processing the customer's order.
-
The customer is redirected to the URL from step (1) and should be pleased to find that the order has been paid and is now in the processing stage.
Creating Payments
$payment = $mollie->payments->create([ "amount" => [ "currency" => "EUR", "value" => "10.00" ], "description" => "My first API payment", "redirectUrl" => "https://webshop.example.org/order/12345/", "webhookUrl" => "https://webshop.example.org/mollie-webhook/", ]);
After creation, the payment id is available in the $payment->id
property. You should store this id with your order.
After storing the payment id you can send the customer to the checkout using $payment->getCheckoutUrl()
.
header("Location: " . $payment->getCheckoutUrl(), true, 303);
This header location should always be a GET, thus we enforce 303 http response code
For a payment create example, see Example - New Payment.
Multicurrency
Since API v2.0 it is now possible to create non-EUR payments for your customers. A full list of available currencies can be found in our documentation.
$payment = $mollie->payments->create([ "amount" => [ "currency" => "USD", "value" => "10.00" ], //... ]);
After creation, the settlementAmount
will contain the EUR amount that will be settled on your account.
Create fully integrated iDEAL payments
To fully integrate iDEAL payments on your website, follow these additional steps:
- Retrieve the list of issuers (banks) that support iDEAL.
$method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ["include" => "issuers"]);
Use the $method->issuers
list to let the customer pick their preferred issuer.
$method->issuers
will be a list of objects. Use the property $id
of this object in the
API call, and the property $name
for displaying the issuer to your customer.
- Create a payment with the selected issuer:
$payment = $mollie->payments->create([ "amount" => [ "currency" => "EUR", "value" => "10.00" ], "description" => "My first API payment", "redirectUrl" => "https://webshop.example.org/order/12345/", "webhookUrl" => "https://webshop.example.org/mollie-webhook/", "method" => \Mollie\Api\Types\PaymentMethod::IDEAL, "issuer" => $selectedIssuerId, // e.g. "ideal_INGBNL2A" ]);
The _links
property of the $payment
object will contain an object checkout
with a href
property, which is a URL that points directly to the online banking environment of the selected issuer.
A short way of retrieving this URL can be achieved by using the $payment->getCheckoutUrl()
.
For a more in-depth example, see Example - iDEAL payment.
Retrieving Payments
Retrieve Payment Documentation
We can use the $payment->id
to retrieve a payment and check if the payment isPaid
.
$payment = $mollie->payments->get($payment->id); if ($payment->isPaid()) { echo "Payment received."; }
Or retrieve a collection of payments.
$payments = $mollie->payments->page();
For an extensive example of listing payments with the details and status, see Example - List Payments.
Refunding payments
Our API provides support for refunding payments. It's important to note that there is no confirmation step, and all refunds are immediate and final. Refunds are available for all payment methods except for paysafecard and gift cards.
$payment = $mollie->payments->get($payment->id); // Refund € 2 of this payment $refund = $payment->refund([ "amount" => [ "currency" => "EUR", "value" => "2.00" ] ]);
Payment webhook
When the payment status changes, the webhookUrl
you specified during payment creation will be called. You can use the id
from the POST parameters to check the status and take appropriate actions. For more details, refer to Example - Webhook.
For a working example, see Example - Refund payment.
Enabling debug mode
When troubleshooting, it can be highly beneficial to have access to the submitted request within the ApiException
. To safeguard against inadvertently exposing sensitive request data in your local application logs, the debugging feature is initially turned off.
To enable debugging and inspect the request:
/** @var $mollie \Mollie\Api\MollieApiClient */ $mollie->enableDebugging(); try { $mollie->payments->get('tr_12345678'); } catch (\Mollie\Api\Exceptions\ApiException $exception) { $request = $exception->getRequest(); }
If you are recording instances of ApiException
, the request details will be included in the logs. It is vital to ensure that no sensitive information is retained within these logs and to perform cleanup after debugging is complete.
To disable debugging again:
/** @var $mollie \Mollie\Api\MollieApiClient */ $mollie->disableDebugging();
Please note that debugging is only available when using the default Guzzle http adapter (Guzzle6And7MollieHttpAdapter
).
API documentation
For an in-depth understanding of our API, please explore the Mollie Developer Portal. Our API documentation is available in English.
Contributing to Our API Client
Would you like to contribute to improving our API client? We welcome pull requests. But, if you're interested in contributing to a technology-focused organization, Mollie is actively recruiting developers and system engineers. Discover our current job openings or reach out.
License
BSD (Berkeley Software Distribution) License. Copyright (c) 2013-2018, Mollie B.V.
Support
Contact: www.mollie.com — info@mollie.com — +31 20 820 20 70