diff --git a/composer.json b/composer.json index 9034a8b8..4d348078 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/mollie-api-php", "description": "Mollie API client library for PHP", - "version": "1.5.1", + "version": "1.6.0", "homepage": "https://github.com/mollie/mollie-api-php", "license": "BSD-2-Clause", "authors": [ @@ -13,7 +13,7 @@ "keywords": [ "mollie", "payment", "service", "ideal", "creditcard", "mistercash", "bancontact", "sofort", "sofortbanking", "sepa", "bitcoin", "paypal", "paysafecard", "podiumcadeaukaart", "banktransfer", "direct debit", "belfius", - "belfius direct net", "refunds", "api", "payments", "gateway" + "belfius direct net", "refunds", "api", "payments", "gateway", "subscriptions", "recurring", "charges" ], "require-dev": { "phpunit/phpunit": "^3.7|^4.8|^5.4" diff --git a/examples/15-recurring-payment.php b/examples/15-recurring-payment.php index 3db023fa..8ebe939a 100644 --- a/examples/15-recurring-payment.php +++ b/examples/15-recurring-payment.php @@ -30,12 +30,12 @@ )); /* - * Send the customer off to complete the first payment. - * - * After completion, the customer will have a pending or valid mandate that can be - * used for recurring payments and subscriptions. + * The payment will be either pending or paid immediately. The customer + * does not have to perform any payment steps. */ - echo "

Your payment status is '" . htmlspecialchars($payment->status) . "'.

"; + + echo "

Selected mandate is '" . htmlspecialchars($payment->mandateId) . "' (" . htmlspecialchars($payment->method) . ").

\n"; + echo "

The payment status is '" . htmlspecialchars($payment->status) . "'.

\n"; } catch (Mollie_API_Exception $e) { diff --git a/examples/16-recurring-subscription.php b/examples/16-recurring-subscription.php new file mode 100644 index 00000000..07f28f9a --- /dev/null +++ b/examples/16-recurring-subscription.php @@ -0,0 +1,50 @@ +customers->all(0, 1)->data[0]; + + /* + * Generate a unique subscription id for this example. It is important to include this unique attribute + * in the redirectUrl (below) so a proper return page can be shown to the customer. + */ + $my_subscription = time(); + + /* + * Customer Subscription creation parameters. + * + * See: https://www.mollie.com/nl/docs/reference/subscriptions/create + */ + $subscription = $mollie->customers_subscriptions->with($customer)->create(array( + "amount" => 10.00, + "times" => 12, + "interval" => "1 month", + "description" => "My subscription", + "method" => NULL, + "webhookUrl" => "https://example.org/subscription-payment-webhook/$my_subscription", + )); + + /* + * The subscription will be either pending or active depending on whether the customer has + * a pending or valid mandate. If the customer has no mandates an error is returned. You + * should then set up a "first payment" for the customer (example 14). + */ + + echo "

The subscription status is '" . htmlspecialchars($subscription->status) . "'.

\n"; +} +catch (Mollie_API_Exception $e) +{ + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} diff --git a/src/Mollie/API/Client.php b/src/Mollie/API/Client.php index 05b5ba32..9c4755f8 100644 --- a/src/Mollie/API/Client.php +++ b/src/Mollie/API/Client.php @@ -34,7 +34,7 @@ class Mollie_API_Client /** * Version of our client. */ - const CLIENT_VERSION = "1.5.1"; + const CLIENT_VERSION = "1.6.0"; /** * Endpoint of the remote API. @@ -142,6 +142,13 @@ class Mollie_API_Client */ public $customers_mandates; + /** + * RESTful Customers Subscriptions resource. + * + * @var Mollie_API_Resource_Customers_Subscriptions + */ + public $customers_subscriptions; + /** * @var string */ @@ -172,13 +179,14 @@ public function __construct () $this->getCompatibilityChecker() ->checkCompatibility(); - $this->payments = new Mollie_API_Resource_Payments($this); - $this->payments_refunds = new Mollie_API_Resource_Payments_Refunds($this); - $this->issuers = new Mollie_API_Resource_Issuers($this); - $this->methods = new Mollie_API_Resource_Methods($this); - $this->customers = new Mollie_API_Resource_Customers($this); - $this->customers_payments = new Mollie_API_Resource_Customers_Payments($this); - $this->customers_mandates = new Mollie_API_Resource_Customers_Mandates($this); + $this->payments = new Mollie_API_Resource_Payments($this); + $this->payments_refunds = new Mollie_API_Resource_Payments_Refunds($this); + $this->issuers = new Mollie_API_Resource_Issuers($this); + $this->methods = new Mollie_API_Resource_Methods($this); + $this->customers = new Mollie_API_Resource_Customers($this); + $this->customers_payments = new Mollie_API_Resource_Customers_Payments($this); + $this->customers_mandates = new Mollie_API_Resource_Customers_Mandates($this); + $this->customers_subscriptions = new Mollie_API_Resource_Customers_Subscriptions($this); // OAuth2 endpoints $this->permissions = new Mollie_API_Resource_Permissions($this); diff --git a/src/Mollie/API/Object/Customer/Mandate.php b/src/Mollie/API/Object/Customer/Mandate.php index 9d30fb80..cd0b12ca 100644 --- a/src/Mollie/API/Object/Customer/Mandate.php +++ b/src/Mollie/API/Object/Customer/Mandate.php @@ -31,6 +31,7 @@ */ class Mollie_API_Object_Customer_Mandate { + const STATUS_PENDING = "pending"; const STATUS_VALID = "valid"; const STATUS_INVALID = "invalid"; diff --git a/src/Mollie/API/Object/Customer/Subscription.php b/src/Mollie/API/Object/Customer/Subscription.php new file mode 100644 index 00000000..3981e43b --- /dev/null +++ b/src/Mollie/API/Object/Customer/Subscription.php @@ -0,0 +1,112 @@ + + * @copyright Mollie B.V. + * @link https://www.mollie.com + */ +class Mollie_API_Object_Customer_Subscription +{ + const STATUS_ACTIVE = "active"; + const STATUS_PENDING = "pending"; // Waiting for a valid mandate. + const STATUS_CANCELLED = "cancelled"; + const STATUS_SUSPENDED = "suspended"; // Active, but mandate became invalid. + const STATUS_COMPLETED = "completed"; + + /** + * @var string + */ + public $resource; + + /** + * @var string + */ + public $id; + + /** + * @var string + */ + public $customerId; + + /** + * Either "live" or "test" depending on the customer's mode. + * + * @var string + */ + public $mode; + + /** + * ISO 8601 format. + * + * @var string + */ + public $createdDatetime; + + /** + * @var string + */ + public $status; + + /** + * @var string + */ + public $amount; + + /** + * @var int|null + */ + public $times; + + /** + * @var string + */ + public $interval; + + /** + * @var string + */ + public $description; + + /** + * @var string|null + */ + public $method; + + /** + * ISO 8601 format. + * + * @var string|null + */ + public $cancelledDatetime; + + /** + * Contains an optional 'webhookUrl'. + * + * @var object|null + */ + public $links; +} diff --git a/src/Mollie/API/Object/Payment.php b/src/Mollie/API/Object/Payment.php index c419404d..4b7be40f 100644 --- a/src/Mollie/API/Object/Payment.php +++ b/src/Mollie/API/Object/Payment.php @@ -203,7 +203,7 @@ class Mollie_API_Object_Payment * The customer ID this payment is performed by. * * @example cst_51EkUqla3 - * @var string + * @var string|null */ public $customerId; @@ -218,10 +218,18 @@ class Mollie_API_Object_Payment * The mandate ID this payment is performed with. * * @example mdt_pXm1g3ND - * @var string + * @var string|null */ public $mandateId; + /** + * The subscription ID this payment belongs to. + * + * @example sub_rVKGtNd6s3 + * @var string|null + */ + public $subscriptionId; + /** * The locale used for this payment. * diff --git a/src/Mollie/API/Resource/Customers/Subscriptions.php b/src/Mollie/API/Resource/Customers/Subscriptions.php new file mode 100644 index 00000000..bb9b4768 --- /dev/null +++ b/src/Mollie/API/Resource/Customers/Subscriptions.php @@ -0,0 +1,49 @@ + + * @copyright Mollie B.V. + * @link https://www.mollie.com + * + * @method Mollie_API_Object_Customer_Subscription[]|Mollie_API_Object_List all($offset = 0, $limit = 0, array $filters = array()) + * @method Mollie_API_Object_Customer_Subscription get($subscription_id, array $filters = array()) + */ +class Mollie_API_Resource_Customers_Subscriptions extends Mollie_API_Resource_Base +{ + /** + * @var string + */ + protected $resource_path = "customers_subscriptions"; + + /** + * @return Mollie_API_Object_Customer_Subscription + */ + protected function getResourceObject () + { + return new Mollie_API_Object_Customer_Subscription; + } +}