Simple to use, modern and well-tested PHP API client for Mollie.
- PHP 5.3 or newer
- PHP cURL extension (with SSL)
- PHP xdebug extension (optional, for unit tests)
- Composer
- Active website profile at Mollie.com (see: Mollie Documentation)
Currently all API functions that don't require oauth authentication are supported. This means you can use this API client for everything except managing organizations, profiles, permissions and settlements.
- Payments
- Payment methods
- Issuers
- Refunds
- Recurring payments
- Customers
- Mandates
- Subscriptions
The Mollie PHP API client is available as composer package. Installation is as simple as requiring the package for your project.
composer require cloudstek/mollie-php-api
You can also manually add the package to your projects composer.json requirements:
{
"require": {
"cloudstek/mollie-php-api": "^2.0.1"
}
}
Next, require the composer autoloader in your project:
<?php
require_once("vendor/autoload.php");
Below are a few common examples on how to use the Mollie PHP API client. For advanced usage please see the documentation.
<?php
// Import the namespace
use Mollie\API\Mollie;
// Create an API client instance
$mollie = new Mollie('test_yourapikeyhere');
// Alternatively..
$mollie = new Mollie();
$mollie->setApiKey('test_yourapikeyhere');
// Now you're ready to use the Mollie API, please read on for more examples.
<?php
use Mollie\API\Mollie;
// Initialize API client
$mollie = new Mollie('test_yourapikeyhere');
// Create customer
$customer = $mollie->customer()->create('John Doe', 'john.doe@example.org');
// Alternatively you can also specify a locale and/or metadata.
// In the following example we'll create the same customer with some metadata
$customer = $mollie->customer()->create(
'John Doe',
'john.doe@example.org',
array(
'user_id' => 11,
'group' => 'regular_customers'
)
);
// Now save the customer ID to your database for future reference. Pseudo code:
$db->save($customer->id);
<?php
use Mollie\API\Mollie;
// Initialize API client
$mollie = new Mollie('test_yourapikeyhere');
// Create new payment
$payment = $mollie->payment()->create(
10.00,
'Expensive cup of coffee',
'https://example.org/order/101'
);
// Redirect user to payment page
$payment->gotoPaymentPage();
According to the Mollie API documentation, Linking customers to payments enables a number of Mollie Checkout features, including:
- Payment preferences for your customers.
- Enabling your customers to charge a previously used debit or credit card with a single click.
- Improved payment insights in your dashboard.
- Recurring payments.
<?php
use Mollie\API\Mollie;
// Initialize API client
$mollie = new Mollie('test_yourapikeyhere');
// Create new payment
$payment = $mollie->customer('cst_test')->payment()->create(
10.00,
'Expensive cup of coffee',
'https://example.org/order/101'
);
// Redirect user to payment page
$payment->gotoPaymentPage();
exit; // Do redirect immediately
<?php
use Mollie\API\Mollie;
// Initialize API client
$mollie = new Mollie('test_yourapikeyhere');
// Get customer
$customer = $mollie->customer('cst_test')->get();
// Make sure the customer has no valid mandates
if(!$customer->mandate()->hasValid()) {
// Create mandate by issueing the first recurring payment.
// This is usually a small amount like a few cents as it's only used to confirm
// the payment details.
$customer->mandate()->createFirstRecurring(
0.01,
'Recurring payment mandate confirmation',
'https://example.org/account'
);
}
<?php
use Mollie\API\Mollie;
// Initialize API client
$mollie = new Mollie('test_yourapikeyhere');
// Get customer
$customer = $mollie->customer('cst_test')->get();
// Check if customer has a valid mandate for recurring payments
if($customer->mandate()->hasValid()) {
$customer->payment()->createRecurring(10.00, 'Expensive cup of coffee');
}
else {
// Customer has no valid mandates, you should get one first.
}
See CHANGELOG.md for a complete list of changes.
Feel free to make contributions to the code by submitting pull requests and opening issues to express your ideas and feature requests.
If you contribute code, make sure it is covered by unit tests and passes existing tests to prevent regressions.