Guides
Collect Payments
Overview Setting up Mandates
Direct Debit Mandates Verified Mandates Collecting mandates offline Importing MandatesSend money
Introduction to Outbound Payments Payment Account API request signing Send an outbound payment
Adding a new recipient Initiate an outbound payment Approve an outbound payment Cancel an outbound paymentOptimise and increase revenue
Prevent fraud with Protect+ Retain customers with fallbacks Reduced failed payments with Success+ Blocking mandates Tutorials
Taking Direct Debit payments using Billing Requests and Custom Payment Pages Handling tax Handling Customer Notifications GoCardless Embed
Introduction Creating a creditor Adding a creditor bank account OptionalSetting a scheme identifer OptionalSetting up mandates / collecting payments
Billing Request with Actions: Setting up a Direct Debit mandate Collecting a Direct Debit payment Billing Request with Actions: Taking an Instant Bank Payment Billing Request with Actions Dual Flow: Taking an Instant Bank Payment and setting up a Direct Debit mandateDirect Debit: Taking Subscription Payments
Using subscriptions
Now, let’s create a subscription. Subscriptions collect a fixed, regular amount from a customer.
Let’s try collecting £15 per month on the 5th of each month from our customer:
1<?php
2require 'vendor/autoload.php';
3
4$client = new \GoCardlessPro\Client([
5 'access_token' => getenv('GC_ACCESS_TOKEN'),
6 'environment' => \GoCardlessPro\Environment::SANDBOX
7]);
8
9$subscription = $client->subscriptions()->create([
10 "params" => [
11 "amount" => 1500, // 15 GBP in pence
12 "currency" => "GBP",
13 "interval_unit" => "monthly",
14 "day_of_month" => "5",
15 "links" => [
16 "mandate" => "MD0000XH9A3T4C"
17 // Mandate ID from the last section
18 ],
19 "metadata" => [
20 "subscription_number" => "ABC1234"
21 ]
22 ],
23 "headers" => [
24 "Idempotency-Key" => "random_subscription_specific_string"
25 ]
26]);
27
28// Keep hold of this subscription ID - we'll use it in a minute.
29// It should look a bit like "SB00003GKMHFFY"
30print("ID: " . $subscription->id);Each month, on the 5th of the month, the subscription will generate a new payment for £15 to be collected from the customer.
With the subscription ID, we can grab the subscription from the API. Let’s then try cancelling it so that no further payments are taken:
1<?php
2require 'vendor/autoload.php';
3
4$client = new \GoCardlessPro\Client([
5 'access_token' => getenv('GC_ACCESS_TOKEN'),
6 'environment' => \GoCardlessPro\Environment::SANDBOX
7]);
8
9$subscription = $client->subscriptions()->get("SB00003GKMHFFY");
10 // Subscription ID from above.
11
12print("Status: " . $subscription->status . "<br />");
13print("Cancelling...<br />");
14
15$subscription = $client->subscriptions()->cancel("SB00003GKMHFFY");
16
17print("Status: " . $subscription->status . "<br />");What's Next?
Taking instalment payments against a mandate