Russell’s Bicycle Shed

Specialists in Cycling

# Add the following to <dependencies> in your pom.xml
<dependency>
    <groupId>com.gocardless</groupId>
    <artifactId>gocardless-pro</artifactId>
    <version>3.0.0</version>
</dependency>

package com.gcintegration;

import com.gocardless.GoCardlessClient;
import com.gocardless.resources.Customer;

import java.util.List;
import java.util.Arrays;

public class GCIntegration {
    public static void main(String[] args) {
        GoCardlessClient client = GoCardlessClient
            // We recommend storing your access token in an
            // environment variable for security, but you could
            // include it as a string directly in your code
            .newBuilder(System.getenv("GC_ACCESS_TOKEN"))
            // Change me to LIVE when you're ready to go live
            .withEnvironment(GoCardlessClient.Environment.SANDBOX)
            .build();
    }
}

List<Customer> customers = client.customers().list().execute().getItems();
System.out.println(Arrays.toString(customers.toArray()));

import com.gocardless.GoCardlessClient;

package com.gcintegration;

import com.gocardless.GoCardlessClient;
import com.gocardless.resources.RedirectFlow;

public class CreateRedirectFlow {
    public static void main(String[] args) {
        GoCardlessClient client = GoCardlessClient
            // We recommend storing your access token in an
            // environment variable for security, but you could
            // include it as a string directly in your code
            .newBuilder(System.getenv("GC_ACCESS_TOKEN"))
            // Change me to LIVE when you're ready to go live
            .withEnvironment(GoCardlessClient.Environment.SANDBOX)
            .build();

        RedirectFlow redirectFlow = client.redirectFlows().create()
            .withDescription("Cider Barrels") // This will be shown on the payment pages.
            .withSessionToken("dummy_session_token") // Not the access token
            .withSuccessRedirectUrl("https://developer.gocardless.com/example-redirect-uri/")
            // Optionally, prefill customer details on the payment page
            .withPrefilledCustomerGivenName("Tim")
            .withPrefilledCustomerFamilyName("Rogers")
            .withPrefilledCustomerEmail("tim@gocardless.com")
            .withPrefilledCustomerAddressLine1("338-346 Goswell Road")
            .withPrefilledCustomerCity("London")
            .withPrefilledCustomerPostalCode("EC1V 7LQ")
            .execute();
        // Hold on to this ID - you'll need it when you
        // "confirm" the redirect flow later
        System.out.println(redirectFlow.getId());
        System.out.println(redirectFlow.getRedirectUrl());
    }
}