PHP code example of gocardless / gocardless-pro

1. Go to this page and download the library: Download gocardless/gocardless-pro library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gocardless / gocardless-pro example snippets




$access_token = getenv('GC_ACCESS_TOKEN');
$client = new \GoCardlessPro\Client([
  'access_token' => $access_token,
  'environment'  => \GoCardlessPro\Environment::SANDBOX
]);

$client->customers()->list();

$customers = $client->customers()->list(['params' => ['limit' => 400]]);

echo count($customers->records);
foreach ($customers->records as $resource) {
  echo $resource->given_name;
}

$customer = $client->customers()->get($customer_id);
echo $customer->given_name;

$client->customers()->get($customer_id, ['params' => ['some_flag' => true]]);

$api_response = $client->customers()->get($customer_id)->api_response;
echo $api_response->status_code;

$client->customers()->create([
  'params' => ['given_name' => 'Pete', 'family_name' => 'Hamilton']
]);

$client->customers()->update($customer_id, [
  'params' => ['family_name' => 'Smith']
]);

$client->customers()->create([
  'params' =>  ['given_name' => 'Pete', 'family_name' => 'Hamilton']
  'headers' => ['Idempotency-Key' => 'ABC123']
]);

try {
  $client->customer()->create([
    'params' => ['invalid_name' => 'Pete']
  ]);
} catch (\GoCardlessPro\Core\Exception\ApiException $e) {
  // Api request failed / record couldn't be created.
} catch (\GoCardlessPro\Core\Exception\MalformedResponseException $e) {
  // Unexpected non-JSON response.
} catch (\GoCardlessPro\Core\Exception\ApiConnectionException $e) {
  // Network error.
}


// When you create a webhook endpoint, you can specify a secret. When GoCardless sends
// you a webhook, it will sign the body using that secret. Since only you and GoCardless
// know the secret, you can check the signature and ensure that the webhook is truly
// from GoCardless.
//
// We recommend storing your webhook endpoint secret in an environment variable
// for security, but you could hook.
         echo $event->id;
     }

     header('HTTP/1.1 200 OK');
} catch (GoCardlessPro\Core\Exception\InvalidSignatureException) {
     // The webhook doesn't appear to be genuinely from GoCardless, as the signature
     // 
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php
bash
php composer.phar