### Create Instalment Schedule in Ruby Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md This Ruby example shows how to set up an instalment schedule. Ensure the `GoCardlessPro` gem is installed and the client is configured with your credentials. ```ruby @client = GoCardlessPro::Client.new( access_token: "your_access_token", environment: :sandbox ) instalment_schedule = @client.instalment_schedules.create_with_schedule( params: { name: 'ACME Invoice 103', total_amount: 10_000, # 100 GBP in pence, collected from the customer app_fee: 10, # Your 10 pence fee, applied to each instalment, # to be paid out to you currency: 'GBP', instalments: { start_date: '2019-08-20', interval_unit: 'weekly', interval: 2, amounts: [ 3_400, 3_400, 3_200 ] } links: { mandate: 'MD0000XH9A3T4C' }, metadata: {} }, headers: { 'Idempotency-Key': 'random_instalment_schedule_specific_string' } ) ``` -------------------------------- ### List Instalment Schedules (Go) Source: https://developer.gocardless.com/api-reference Provides an example of listing instalment schedules using the Go SDK. Includes client initialization and iterating through the returned schedules. ```go package main import ( // Please check you are using the latest version at https://github.com/gocardless/gocardless-pro-go/releases gocardless "github.com/gocardless/gocardless-pro-go/v6" ) func main() { accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Println("error in initialisating client: %s", err.Error()) return } instalmentScheduleListParams := gocardless.InstalmentScheduleListParams{} instalmentScheduleListResult, err := client.InstalmentSchedules.List(ctx, instalmentScheduleListParams) for _, instalmentSchedule := range instalmentScheduleListResult.InstalmentSchedules { fmt.Println(instalmentSchedule.Name) } } ``` -------------------------------- ### Create Instalment Schedule (Go) Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md This Go code demonstrates how to create an instalment schedule. It includes client initialization and parameter setup for the CreateWithSchedule method. ```go package main import ( gocardless "github.com/gocardless/gocardless-pro-go/v2" "context" "fmt" ) func main() { accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s\n", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Printf("error in initialisating client: %s\n", err.Error()) return } instalmentScheduleCreateWithScheduleParams := gocardless.InstalmentScheduleCreateWithScheduleParams{ TotalAmount: 10000, AppFee: 10, Currency: "GBP", Instalments: gocardless.InstalmentScheduleCreateWithScheduleParamsInstalments{ Interval: 2, IntervalUnit: "monthly", Amounts: []int{3400, 3400, 3200}, }, Metadata: map[string]interface{}{"invoiceId": "001"}, } requestOption := gocardless.WithIdempotencyKey("random_instalment_schedule_specific_string") instalmentSchedule, err := client.InstalmentSchedules().CreateWithSchedule(context.Background(), instalmentScheduleCreateWithScheduleParams, requestOption) if err != nil { fmt.Printf("error creating instalment schedule: %s\n", err.Error()) return } fmt.Printf("Created instalment schedule: %+v\n", instalmentSchedule) } ``` -------------------------------- ### List Instalment Schedules (Python) Source: https://developer.gocardless.com/api-reference Demonstrates listing instalment schedules with the Python SDK. Includes an example of retrieving records and listing with an 'after' cursor. ```python import gocardless_pro client = gocardless_pro.Client(access_token="your_access_token_here", environment='sandbox') client.instalment_schedules.list().records client.instalment_schedules.list(params={"after": "IS123"}).records ``` -------------------------------- ### Create Instalment Schedule (HTTP Example) Source: https://developer.gocardless.com/api-reference Demonstrates how to create an instalment schedule with specific amounts and charge dates using an HTTP POST request. The response indicates an initial 'pending' status. ```HTTP POST https://api.gocardless.com/instalment_schedules HTTP/1.1 { "instalment_schedules": { "name": "Bike Invoice 271", "currency": "GBP", "total_amount": "2500", "instalments": [ { "amount": "1500", "charge_date": "2019-12-14" }, { "amount": "1000", "charge_date": "2020-05-01" } ], "metadata": {}, "links": { "mandate": "MD123" } } } HTTP/1.1 201 (Created) { "instalment_schedules": { "id": "IS123", "status": "pending", "total_amount": "2500", "metadata": {}, "payment_errors": {}, "links": { "mandate": "MD123", "customer": "CU123" } } } ``` -------------------------------- ### List Instalment Schedules (PHP) Source: https://developer.gocardless.com/api-reference Shows how to initialize the GoCardless client and list instalment schedules using the PHP SDK. Includes an example of listing with a creation date filter. ```php $client = new \GoCardlessPro\Client([ 'access_token' => 'your_access_token_here', 'environment' => \GoCardlessPro\Environment::SANDBOX ]); $client->instalmentSchedules()->list(); $client->instalmentSchedules()->list([ "params" => ["created_at[gt]" => "2015-11-03T09:30:00Z"] ]); ``` -------------------------------- ### Create Instalment Schedule with Schedule (PHP) Source: https://developer.gocardless.com/api-reference PHP example demonstrating how to create an instalment schedule with associated payments using the GoCardless Pro client. Includes setting total amount, app fee, currency, and instalment details. ```PHP $client = new \GoCardlessPro\Client([ 'access_token' => 'your_access_token_here', 'environment' => \GoCardlessPro\Environment::SANDBOX ]); $instalment_schedule = $client->instalmentSchedules()->createWithSchedule([ "params" => [ "name" => "ACME Invoice 103", "total_amount" => 10000, // 100 GBP in pence, collected from the customer "app_fee" => 10, // Your 10 pence fee, applied to each instalment, // to be paid out to you "currency" => "GBP", "instalments" => [ "start_date" => "2019-08-20", "interval_unit" => "weekly", ``` -------------------------------- ### Create Instalment Schedule with Regular Intervals (Ruby) Source: https://developer.gocardless.com/recurring-payments/instalments.md This Ruby example shows how to set up an instalment schedule with GoCardless automatically calculating payment dates. Ensure the gocardless_pro gem is installed and the access token is set in the environment. ```ruby require 'gocardless_pro' client = GoCardlessPro::Client.new( access_token: ENV['GC_ACCESS_TOKEN'], environment: :sandbox ) response = client.instalment_schedules.create_with_schedule( params: { name: 'Invoice #1234', currency: 'GBP', total_amount: 2500, instalments: { start_date: '2024-11-01', interval_unit: 'monthly', interval: 1, amounts: [1500, 1000] }, links: { mandate: 'MD123' } } ) ``` -------------------------------- ### Create Instalment Schedule with Fixed Dates (.NET) Source: https://developer.gocardless.com/recurring-payments/instalments.md This .NET example demonstrates creating an instalment schedule with specific charge dates using the GoCardless .NET SDK. Ensure your access token and environment are configured. ```.net using GoCardless; var client = GoCardlessClient.Create( Environment.GetEnvironmentVariable("GC_ACCESS_TOKEN"), GoCardlessClient.Environment.SANDBOX ); var instalmentSchedule = await client.InstalmentSchedules.CreateWithDatesAsync( new InstalmentScheduleCreateWithDatesRequest { Name = "Invoice #1234", Currency = "GBP", TotalAmount = 2500, Instalments = new List { new InstalmentScheduleCreateWithDatesRequest.InstalmentScheduleInstalments { Amount = 1500, ChargeDate = "2024-11-01" }, new InstalmentScheduleCreateWithDatesRequest.InstalmentScheduleInstalments { Amount = 1000, ChargeDate = "2025-02-01" } }, Links = new InstalmentScheduleCreateWithDatesRequest.InstalmentScheduleLinks { Mandate = "MD123" } } ); ``` -------------------------------- ### List Instalment Schedules (Ruby) Source: https://developer.gocardless.com/api-reference Provides examples of using the Ruby SDK to list instalment schedules. Shows basic listing, filtering by creation date, and iterating through results. ```ruby @client = GoCardlessPro::Client.new( access_token: "your_access_token", environment: :sandbox ) @client.instalment_schedules.list @client.instalment_schedules.list( params: { "created_at[gt]" => "2016-08-06T09:30:00Z" } ) @client.instalment_schedules.list.records.each do |instalment_schedule| puts instalment_schedule.inspect end ``` -------------------------------- ### HTTP GET Request for Instalment Schedule Events Source: https://developer.gocardless.com/api-reference Example of an HTTP GET request to retrieve events related to an instalment schedule. This event indicates that a payment has been created as part of an instalment schedule. ```HTTP GET https://api.gocardless.com/events/EV123 HTTP/1.1 HTTP/1.1 200 (OK) { "events": { "id": "EV123", "created_at": "2014-04-08T17:01:06.000Z", "resource_type": "instalment_schedules", "action": "payment_created", "links": { "instalment_schedule": "IS123", "payment": "PM123" }, "details": { "origin": "api", "cause": "payment_created", "description": "Payment created by an instalment schedule." }, "metadata": {}, "resource_metadata": { "order_dispatch_date": "2014-05-22" } } } ``` -------------------------------- ### Initialize GoCardless .NET Client Source: https://developer.gocardless.com/api-reference Set up the GoCardless .NET client for use. This example shows how to create the client instance with an access token and the sandbox environment. ```.NET String accessToken = "your_access_token"; GoCardlessClient gocardless = GoCardlessClient.Create(accessToken, Environment.SANDBOX); ``` -------------------------------- ### HTTP Request to Get Instalment Schedule Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md Example of an HTTP GET request to retrieve an instalment schedule. This shows the request format and potential success and failure responses. ```http GET https://api.gocardless.com/instalment_schedules/IS123 HTTP/1.1 HTTP/1.1 200 OK Content-Type: application/json { "instalment_schedules": { "id": "IS123", "name": "INV-4142", "currency": "GBP", "status": "active", "total_amount": "2500", "metadata": {}, "payment_errors": {}, "links": { "mandate": "MD456", "payments": ["PM123", "PM345"], "customer": "CU456" } } } { "instalment_schedules": { "id": "IS123", "name": "INV-4142", "currency": "GBP", "status": "creation_failed", "total_amount": "2500", "metadata": {}, "payment_errors": { "0": { "field": "description", "message": "was too long" }, "1": {} } } } ``` -------------------------------- ### Initialize GoCardless Client and Create Creditor Bank Account with Go Source: https://developer.gocardless.com/gc-embed/adding-a-creditor-bank-account.md Example of initializing the GoCardless Go client and creating a creditor bank account. Includes error handling for initialization. ```Go package main import ( gocardless "github.com/gocardless/gocardless-pro-go/v2" ) accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Println("error in initialisating client: %s", err.Error()) return } creditorBankAccountCreateParams := gocardless.CreditorBankAccountCreateParams{ AccountNumber: "55779911", BranchCode: "200000", ``` -------------------------------- ### HTTP GET Request for Events Source: https://developer.gocardless.com/api-reference Example of an HTTP GET request to retrieve events from the GoCardless API. This specific example shows an event related to an export starting. ```HTTP GET https://api.gocardless.com/events/EV123 HTTP/1.1 HTTP/1.1 200 (OK) { "events": { "id": "EV123", "created_at": "2024-07-10T00:00:00.000Z", "resource_type": "exports", "action": "started", "links": { "export": "EX0000116MFWYM" }, "details": { "origin": "gocardless", "cause": "export_started", "description": "Export started.", "type": "payout_transactions_reconciliation", "currency": "GBP" }, "metadata": {} } } ``` -------------------------------- ### Create a Subscription Source: https://developer.gocardless.com/api-reference This Go example demonstrates creating a subscription. It requires initializing the GoCardless client with your access token and specifying the sandbox endpoint. The `Links.Mandate` field is necessary to associate the subscription with a mandate. ```Go package main import ( // Please check you are using the latest version at https://github.com/gocardless/gocardless-pro-go/releases gocardless "github.com/gocardless/gocardless-pro-go/v6" ) func main() { accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Println("error in initialisating client: %s", err.Error()) return } subscriptionCreateParams := gocardless.SubscriptionCreateParams{ Amount: 1500, // 15 GBP in pence Currency: "GBP", IntervalUnit: "monthly", DayOfMonth: 5, Links: gocardless.SubscriptionCreateParamsLinks{ Mandate: "MD123", }, Metadata: map[string]string{"subscription_number": "ABC123"}, } subscription, err := client.Subscriptions.Create(ctx, subscriptionCreateParams) } ``` -------------------------------- ### Get Instalment Schedule - Java Source: https://developer.gocardless.com/api-reference Use the GoCardless Java SDK to get an instalment schedule. Build the client with your access token and specify the SANDBOX environment. ```Java import static com.gocardless.GoCardlessClient.Environment.SANDBOX; String accessToken = "your_access_token_here"; GoCardlessClient client = GoCardlessClient .newBuilder(accessToken) .withEnvironment(SANDBOX) .build(); InstalmentSchedule instalmentSchedule = client.instalmentSchedules().get("IS123").execute(); ``` -------------------------------- ### Get Instalment Schedule (Java) Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md Retrieve an existing instalment schedule using its ID. ```java InstalmentSchedule instalmentSchedule = client.instalmentSchedules().get("IS123").execute(); ``` -------------------------------- ### Create a Subscription (Go) Source: https://developer.gocardless.com/direct-debit/taking-subscription-payments.md Create a subscription using the GoCardless Go client. This example configures a monthly subscription and includes metadata and an idempotency key. ```go package main import ( "context" "fmt" gocardless "github.com/gocardless/gocardless-pro-go" ) func main() { accessToken := "your_access_token_here" opts := gocardless.WithEndpoint(gocardless.SandboxEndpoint) client, err := gocardless.New(accessToken, opts) if err != nil { fmt.Println("error in initialisating client: %s", err.Err()) return } ctx := context.TODO() subscriptionCreateParams := gocardless.SubscriptionCreateParams{} subscriptionCreateParams.Amount = 1500 // 15 GBP in pence subscriptionCreateParams.Currency = "GBP" subscriptionCreateParams.IntervalUnit = "GBP" subscriptionCreateParams.DayOfMonth = 5 subscriptionCreateParams.Links.Mandate = "MD0000YTKZKY4J" subscriptionCreateParams.Metadata = map[string]string{"subscription_number": "ABC123"} requestOption := gocardless.WithIdempotencyKey("random_subscription_specific_string") subscription, err := client.subscriptions().Create(ctx, subscriptionCreateParams, requestOption) if err != nil { fmt.Println("error in getting subscription: %s", err.Error()) return } // Keep hold of this subscription ID - we'll use it in a minute. // It should look a bit like "SB00003GKMHFFY" fmt.Println(subscription.Id) } ``` -------------------------------- ### Get Instalment Schedule (JavaScript) Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md Retrieve an existing instalment schedule using its ID in a Node.js environment. Ensure you have the gocardless-nodejs library installed. ```javascript const constants = require("gocardless-nodejs/constants"); const gocardless = require("gocardless-nodejs"); const client = gocardless( "your_access_token_here", constants.Environments.Sandbox, ); const instalmentSchedule = await client.instalmentSchedules.find("IS123"); ``` -------------------------------- ### Initialize GoCardless Config (Go) Source: https://developer.gocardless.com/api-reference Example of initializing the GoCardless client configuration in Go, specifying the access token and sandbox environment. ```Go package main import ( // Please check you are using the latest version at https://github.com/gocardless/gocardless-pro-go/releases gocardless "github.com/gocardless/gocardless-pro-go/v6" ) func main() { accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } } ``` -------------------------------- ### Update Instalment Schedule (Java) Source: https://developer.gocardless.com/api-reference This Java example demonstrates updating an instalment schedule with metadata. ```Java import static com.gocardless.GoCardlessClient.Environment.SANDBOX; String accessToken = "your_access_token_here"; GoCardlessClient client = GoCardlessClient .newBuilder(accessToken) .withEnvironment(SANDBOX) .build(); client.instalmentSchedules().update("IS123") .withMetadata("key", "value") .execute(); ``` -------------------------------- ### List Exports in Go Source: https://developer.gocardless.com/api-reference This Go example demonstrates initializing the GoCardless client and listing exports. It includes error handling for configuration and client initialization. ```Go package main import ( // Please check you are using the latest version at https://github.com/gocardless/gocardless-pro-go/releases gocardless "github.com/gocardless/gocardless-pro-go/v6" ) func main() { accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Println("error in initialisating client: %s", err.Error()) return } exportListParams := gocardless.ExportListParams{} exportListResult, err := client.Exports.List(ctx, exportListParams) for _, export := range exportListResult.Exports { fmt.Println(export.Id) } } ``` -------------------------------- ### Get a single instalment schedule Source: https://developer.gocardless.com/api-reference Retrieves the details of an existing instalment schedule using its ID. ```APIDOC ## GET /instalment_schedules/:id ### Description Retrieves the details of an existing instalment schedule. ### Method GET ### Endpoint `/instalment_schedules/:id` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the instalment schedule. ### Request Example ```http GET https://api.gocardless.com/instalment_schedules/IS123 HTTP/1.1 ``` ### Response #### Success Response (200) - **id** (string) - The ID of the instalment schedule. - **name** (string) - The name of the instalment schedule. - **currency** (string) - The currency of the total amount. - **status** (string) - The current status of the instalment schedule. - **total_amount** (string) - The total amount for the instalment schedule. - **metadata** (object) - Arbitrary metadata. - **payment_errors** (object) - Details of any payment errors. - **links** (object) - Contains links to related resources. - **mandate** (string) - Link to the associated mandate. - **payments** (array) - Links to associated payments. - **customer** (string) - Link to the associated customer. #### Response Example ```json { "instalment_schedules": { "id": "IS123", "name": "INV-4142", "currency": "GBP", "status": "active", "total_amount": "2500", "metadata": {}, "payment_errors": {}, "links": { "mandate": "MD456", "payments": ["PM123", "PM345"], "customer": "CU456" } } } ``` ``` -------------------------------- ### Example: Get Customer Notification XYZ12344 Source: https://developer.gocardless.com/cli-reference/gocardless_get_customer_notification This is a concrete example of how to use the `gocardless get customer_notification` command with a sample notification ID. Replace 'XYZ12344' with the actual ID of the customer notification you wish to retrieve. ```bash gocardless get customer_notification XYZ12344 ``` -------------------------------- ### Create a Subscription Source: https://developer.gocardless.com/api-reference This Ruby example demonstrates how to create a subscription using the GoCardless Pro client. It requires your access token and specifies sandbox environment. The `links.mandate` is essential for associating the subscription with a mandate. ```Ruby @client = GoCardlessPro::Client.new( access_token: "your_access_token", environment: :sandbox ) @client.subscriptions.create( params: { amount: 2500, currency: "GBP", name: "Monthly magazine", interval_unit: "monthly", day_of_month: 1, links: { mandate: "MD123" } } ) ``` -------------------------------- ### Create Customer Bank Account in .NET Source: https://developer.gocardless.com/direct-debit/offline-mandates.md This .NET example demonstrates creating a customer bank account. The GoCardlessClient needs to be created with your access token and the sandbox environment. ```.net String accessToken = "your_access_token"; GoCardlessClient gocardless = GoCardlessClient.Create(accessToken, Environment.SANDBOX); var customerBankAccountRequest = new GoCardless.Services.CustomerBankAccountCreateRequest() { AccountHolderName = "Frank Osborne", AccountNumber = "2715500356", BranchCode = "026073150", CountryCode = "US", Currency = "USD", AccountType = "checking" Links = new GoCardless.Services.CustomerBankAccountCreateRequest.CustomerBankAccountLinks() { Customer = "CU0123" } }; var customerBankAccountResponse = await gocardless.CustomerBankAccounts.CreateAsync(customerBankAccountRequest); GoCardless.Resources.CustomerBankAccount customerBankAccount = customerBankAccountResponse.CustomerBankAccount; ``` -------------------------------- ### Example Usage of Installment Calculation Functions Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md Demonstrates how to use the previously defined functions to calculate the normal installment amount and then the specific amounts for each installment in a payment schedule. ```javascript normal_instalment_amount = calculateInstalmentValue( total, number_of_instalments, ); instalment_amounts = getInstalmentAmounts( total, number_of_instalments, normal_instalment_amount, ); ``` -------------------------------- ### Initialize Go SDK Client and Create Mandate PDF (Go) Source: https://developer.gocardless.com/api-reference Initializes the GoCardless Go SDK client using an access token and sandbox endpoint, then creates a mandate PDF. Demonstrates basic client setup and mandate PDF creation. ```go package main import ( // Please check you are using the latest version at https://github.com/gocardless/gocardless-pro-go/releases gocardless "github.com/gocardless/gocardless-pro-go/v6" ) func main() { accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Println("error in initialisating client: %s", err.Error()) return } mandatePdfCreateParams := gocardless.MandatePdfCreateParams{ Links: &gocardless.MandatePdfCreateParamsLinks{ Mandate: "MD123", }, } mandatePdf, err := client.MandatePdfs.Create(ctx, mandatePdfCreateParams) requestOption := gocardless.WithIdempotencyKey("mandate_pdfs_idempotency_key") mandatePdf, err = client.MandatePdfs.Create(ctx, mandatePdfCreateParams, requestOption) headers := map[string]string{"Accept-Language": "fr"} requestOption = gocardless.WithHeaders(headers) mandatePdf, err = client.MandatePdfs.Create(ctx, mandatePdfCreateParams, requestOption) } ``` -------------------------------- ### Get Event Details Source: https://developer.gocardless.com/api-reference Example of an HTTP GET request to retrieve event details and the corresponding successful JSON response. ```HTTP GET https://api.gocardless.com/events/EV123 HTTP/1.1 HTTP/1.1 200 (OK) { "events": { "id": "EV123", "created_at": "2014-04-08T17:01:06.000Z", "resource_type": "subscriptions", "action": "payment_created", "links": { "subscription": "SB123", "payment": "PM123" }, "details": { "origin": "api", "cause": "payment_created", "description": "Payment created by a subscription." }, "metadata": {}, "resource_metadata": { "order_dispatch_date": "2014-05-22" } } } ``` -------------------------------- ### Get Installment Amounts Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md Determines the specific amounts for each installment, including a final 'balancing' payment to account for remainders. This function helps distribute the total amount across all installments. ```javascript // @param total - the invoice total in GBP/USD etc. // @param number_of_instalments - the number of instalments you'd like to split the // invoice into // @param normal_instalment_amount - the amount in pence/cents etc. for all payments // except the final 'balancing' payment function getInstalmentAmounts( total, number_of_instalments, normal_instalment_amount, ) { number_of_normal_instalments = floor(total / normal_instalment_amount); minimum = 200; // some "reasonable minimum" instalment amount amounts = []; for (i = 1; i < number_of_normal_instalments; i++) { amounts.push(normal_instalment_amount); } remainder = total % normalInstalmentAmount; if (remainder < minimum) { amounts[amounts.length - 1] += remainder; } else { amounts.push(remainder); } return amounts; } ``` -------------------------------- ### Create a Payment in Go Source: https://developer.gocardless.com/api-reference This Go snippet demonstrates creating a payment with the GoCardless Go client. It shows how to initialize the client for the sandbox environment and set up the payment creation parameters, including amount, currency, charge date, reference, metadata, and mandate link. ```Go package main import ( // Please check you are using the latest version at https://github.com/gocardless/gocardless-pro-go/releases gocardless "github.com/gocardless/gocardless-pro-go/v6" ) func main() { accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Println("error in initialisating client: %s", err.Error()) return } paymentCreateParams := gocardless.PaymentCreateParams{ Amount: 100, Currency: "GBP", ChargeDate: "2014-05-19", Reference: "WINEBOX001", Metadata: map[string]string{"order_dispatch_date": "2014-05-22"}, Links: gocardless.PaymentCreateParamsLinks{ Mandate: "MD123", }, } payment, err := client.Payments.Create(ctx, paymentCreateParams) } ``` -------------------------------- ### Get Instalment Schedule Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md Retrieves the details of a specific instalment schedule using its ID. This is useful for checking the status and associated payments of an instalment schedule, especially if not relying on webhooks. ```APIDOC ## GET /instalment_schedules/:id ### Description Retrieves the details of a specific instalment schedule. ### Method GET ### Endpoint https://api.gocardless.com/instalment_schedules/:id ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the instalment schedule. ### Response #### Success Response (200) - **id** (string) - The unique identifier of the instalment schedule. - **name** (string) - The name associated with the instalment schedule. - **currency** (string) - The currency of the payments in the schedule (e.g., GBP). - **status** (string) - The current status of the instalment schedule (e.g., "active", "creation_failed"). - **total_amount** (string) - The total amount for all instalments in the schedule. - **metadata** (object) - Any metadata associated with the instalment schedule. - **payment_errors** (object) - Details about any errors encountered during payment creation for the schedule. - **links** (object) - Contains links to related resources: - **mandate** (string) - The ID of the associated mandate. - **payments** (array of strings) - A list of payment IDs included in the schedule. - **customer** (string) - The ID of the customer associated with the schedule. ### Request Example ```json { "instalment_schedules": { "id": "IS123", "name": "INV-4142", "currency": "GBP", "status": "active", "total_amount": "2500", "metadata": {}, "payment_errors": {}, "links": { "mandate": "MD456", "payments": ["PM123", "PM345"], "customer": "CU456" } } } ``` ### Response Example ```json { "instalment_schedules": { "id": "IS123", "name": "INV-4142", "currency": "GBP", "status": "creation_failed", "total_amount": "2500", "metadata": {}, "payment_errors": { "0": { "field": "description", "message": "was too long" }, "1": {} } } } ``` ``` -------------------------------- ### Open Documentation Source: https://developer.gocardless.com/cli-reference/gocardless_open Quickly navigate to the main GoCardless documentation portal by running 'gocardless open docs'. ```bash gocardless open docs ``` -------------------------------- ### Get Instalment Schedule (Python) Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md This Python snippet demonstrates how to fetch an instalment schedule by its ID. It requires the gocardless_pro library to be installed and the client to be configured with your access token and environment. ```python import gocardless_pro client = gocardless_pro.Client(access_token="your_access_token_here", environment='sandbox') client.instalment_schedules.get("IS123") ``` -------------------------------- ### Create Bank Authorisation (.NET) Source: https://developer.gocardless.com/billing-requests/billing-request-actions.md This .NET example shows how to create a bank authorisation. Configure the GoCardlessClient with your access token and the SANDBOX environment. ```.net String accessToken = "your_access_token"; GoCardlessClient gocardless = GoCardlessClient.Create(accessToken, Environment.SANDBOX); var authorisationLinks = new GoCardless.Services.BankAuthorisationCreateRequest.BankAuthorisationLinks { BillingRequest = "BRQ123" }; var resp = await gocardless.BankAuthorisations.CreateAsync( new GoCardless.Services.BankAuthorisationCreateRequest() { RedirectUrl = "https://my-company.com/landing", links = authorisationLinks, } ); GoCardless.Resources.BankAuthorisation bankAuthorisation = resp.BankAuthorisation; ``` -------------------------------- ### Example Usage of gocardless get payer_authorisation Source: https://developer.gocardless.com/cli-reference/gocardless_get_payer_authorisation Demonstrates how to call the `gocardless get payer_authorisation` command with a specific payer authorisation ID. ```bash gocardless get payer_authorisation XYZ12344 ``` -------------------------------- ### List Instalment Schedules (Java) Source: https://developer.gocardless.com/api-reference Illustrates how to list instalment schedules using the Java SDK. Shows client initialization and iterating through all retrieved schedules. ```java import static com.gocardless.GoCardlessClient.Environment.SANDBOX; String accessToken = "your_access_token_here"; GoCardlessClient client = GoCardlessClient .newBuilder(accessToken) .withEnvironment(SANDBOX) .build(); for (InstalmentSchedule instalmentSchedule : client.instalmentSchedules().all().execute()) { System.out.println(instalmentSchedule.getId()); } ``` -------------------------------- ### List Webhooks (HTTP Example) Source: https://developer.gocardless.com/api-reference Demonstrates an HTTP GET request to list successful webhooks. Includes example request and response. ```HTTP GET https://api.gocardless.com/webhooks/WB123?successful=true HTTP/1.1 HTTP/1.1 200 OK { "meta": { "cursors": { "after": null, "before": null }, "limit": 5 }, "webhooks": [{ "created_at": "2018-03-12T15:13:37.416Z", "id": "WB123", "is_test": true, "request_body": "{\"events\":[{\"id\":\"EV123\",\"created_at\":\"2018-03-12T15:13:37.158Z\",\"resource_type\":\"payments\",\"action\":\"created\",\"links\":{\"payment\":\"PM123\"},\"details\":{\"origin\":\"api\",\"cause\":\"payment_created\",\"description\":\"Payment created via the API.\"},\"metadata\":{}}]}", "request_headers": { "Content-Type": "application/json", "Origin": "https://api.gocardless.com", "User-Agent": "gocardless-webhook-service/1.1", "Webhook-Signature": "e4d043149b4cc27435d05ea275a09de2f810e45bed5448fd6a0a742a3846b365" }, "response_body": "ok", "response_body_truncated": false, "response_code": 200, "response_headers": { "content-type": "text/html; charset=utf-8", "date": "Mon, 12 Mar 2018 15:13:37 GMT", }, "response_headers_content_truncated": false, "response_headers_count_truncated": false, "successful": true, "url": "https://example.com/webhook_handler" }] } ``` -------------------------------- ### Create Instalment Schedule with Dates (PHP) Source: https://developer.gocardless.com/api-reference Example of creating an instalment schedule with multiple dated instalments using the GoCardless Pro PHP SDK. Includes setting app fees and metadata. ```PHP $client = new \GoCardlessPro\Client([ 'access_token' => 'your_access_token_here', 'environment' => \GoCardlessPro\Environment::SANDBOX ]); $instalment_schedule = $client->instalmentSchedules()->createWithDates([ "params" => [ "name" => "ACME Invoice 103", "total_amount" => 10000, // 100 GBP in pence, collected from the customer "app_fee" => 10, // Your 10 pence fee, applied to each instalment, // to be paid out to you "currency" => 'GBP', "instalments" => [ [ "charge_date" => '2019-08-20', "amount" => 3400 ], [ "charge_date" => '2019-09-03', "amount" => 3400 ], [ "charge_date" => '2019-09-17', "amount" => 3200 ], ], "links" => [ "mandate" => 'MD0000XH9A3T4C' ], "metadata" => [] ], "headers" => [ 'Idempotency-Key' => 'random_instalment_schedule_specific_string' ] ]); ``` -------------------------------- ### Initialize Go SDK (Go) Source: https://developer.gocardless.com/billing-requests/taking-an-instant-first-payment-with-direct-debit-mandate-creation.md This Go code initializes the GoCardless client configuration and client. Ensure you provide your access token and specify the sandbox environment. ```go package main import ( gocardless "github.com/gocardless/gocardless-pro-go/v2" ) accessToken := "your_access_token_here" config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) if err != nil { fmt.Printf("got err in initialising config: %s", err.Error()) return } client, err := gocardless.New(config) if err != nil { fmt.Println("error in initialisating client: %s", err.Error()) return } ``` -------------------------------- ### Get Mandate Status Source: https://developer.gocardless.com/mandates/blocking-a-dd-mandate.md Send a GET request to the mandate endpoint to retrieve the status of a mandate. This example shows a mandate with a 'blocked' status. ```HTTP GET https://api.gocardless.com/mandates/MD0000S2KNTB2V { "mandates": { "id": "MD0000S2KNTB2V", "created_at": "2021-09-01T15:36:09.104Z", "reference": "ANKITHATEST-3YD936", "status": "blocked", "scheme": "bacs", "next_possible_charge_date": null, "payments_require_approval": false, "metadata": {}, "links": { "customer_bank_account": "BA0000S4DSSHQK", "creditor": "CR00008AWM8AC8", "customer": "CU00018NMYB3H1" } } } ``` -------------------------------- ### List Creditors in PHP Source: https://developer.gocardless.com/api-reference Shows how to initialize the GoCardless client and list creditors. Includes an example of filtering by creation date. ```PHP $client = new \GoCardlessPro\Client([ 'access_token' => 'your_access_token_here', 'environment' => \GoCardlessPro\Environment::SANDBOX ]); $client->creditors()->list(); $client->creditors()->list([ 'params' => ['created_at[gt]' => '2014-05-08T17:01:06.000Z'] ]); ``` -------------------------------- ### Get Instalment Schedule Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md Retrieves the details of a specific instalment schedule using its ID. This is useful for inspecting the status and details of a schedule after it has been created. ```APIDOC ## GET /instalment_schedules/{id} ### Description Retrieves the details of a specific instalment schedule. ### Method GET ### Endpoint /instalment_schedules/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the instalment schedule to retrieve. ### Response #### Success Response (200 OK) - **instalment_schedules** (object) - Contains details of the requested instalment schedule. - **id** (string) - The unique identifier for the instalment schedule. - **status** (string) - The current status of the instalment schedule. - **total_amount** (string) - The total amount of the schedule. - **metadata** (object) - Any metadata associated with the schedule. - **payment_errors** (object) - Details of any payment errors. - **links** (object) - Links to related resources. - **mandate** (string) - The ID of the associated mandate. - **customer** (string) - The ID of the customer. ### Response Example ```json { "instalment_schedules": { "id": "IS123", "status": "pending", "total_amount": "2500", "metadata": {}, "payment_errors": {}, "links": { "mandate": "MD123", "customer": "CU123" } } } ``` ``` -------------------------------- ### Create Customer (.NET) Source: https://developer.gocardless.com/direct-debit/offline-mandates.md This .NET code snippet demonstrates creating a customer. Initialize the GoCardlessClient with your access token and the SANDBOX environment. ```.net String accessToken = "your_access_token"; GoCardlessClient gocardless = GoCardlessClient.Create(accessToken, Environment.SANDBOX); var customerRequest = new GoCardless.Services.CustomerCreateRequest() { Email = "user@example.com", GivenName = "Frank", FamilyName = "Osborne", AddressLine1 = "27 Acer Road", AddressLine2 = "Apt 2", City = "Los Angeles", PostalCode = " 90213", CountryCode = "US", Region = "CA", }; var customerResponse = await gocardless.Customers.CreateAsync(customerRequest); GoCardless.Resources.Customer customer = customerResponse.Customer; ``` -------------------------------- ### List Customers in Ruby Source: https://developer.gocardless.com/api-reference Set up the GoCardless client and list customers. Includes examples for filtering by creation date and iterating through results. ```Ruby @client = GoCardlessPro::Client.new( access_token: "your_access_token", environment: :sandbox ) @client.customers.list @client.customers.list( params: { "created_at[gt]" => "2016-08-06T09:30:00Z" } ) @client.customers.list.records.each { |customer| puts customer.inspect } ``` -------------------------------- ### Create Instalment Schedule API Request (HTTP) Source: https://developer.gocardless.com/direct-debit/taking-installment-payments.md This is an example of the HTTP POST request body for creating an instalment schedule. It specifies the total amount, currency, individual instalment details, and links to the mandate. ```http POST https://api.gocardless.com/instalment_schedules HTTP/1.1 Content-Type: application/json { "instalment_schedules": { "name": "Bike Invoice 271", "currency": "GBP", "total_amount": "2500", "instalments": [ { "amount": "1500", "charge_date": "2019-12-14" }, { "amount": "1000", "charge_date": "2020-05-01" } ], "metadata": {}, "links": { "mandate": "MD123" } } } ``` -------------------------------- ### List Instalment Schedules (JavaScript) Source: https://developer.gocardless.com/api-reference Shows how to list instalment schedules with the JavaScript SDK. Includes examples for a general list and filtering by customer ID. ```javascript const constants = require('gocardless-nodejs/constants'); const gocardless = require('gocardless-nodejs'); const client = gocardless('your_access_token_here', constants.Environments.Sandbox); const instalmentSchedules = await client.instalmentSchedules.list(); // List all instalment schedules associated with a given customer. const customerInstalmentSchedules = await client.instalmentSchedules.list({ customer: "CU123" }); ```