PHP code example of konsulting / justgiving-api-sdk

1. Go to this page and download the library: Download konsulting/justgiving-api-sdk 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/ */

    

konsulting / justgiving-api-sdk example snippets


$auth = new AppAuth('abcde123');
$client = new JustGivingClient($auth);

$response = $client->account->isEmailRegistered('[email protected]');

if ($response->existenceCheck()) {
    echo 'An account has been registered with that email.';
}

$response = $client->charity->getById(2050);

if (! $response->wasSuccessful()) {
    throw new Exception(implode(', ', $response->errors));
}

$response->name;          // 'The Demo Charity1'
$response->websiteUrl;    // 'http://www.democharity.co.uk'
$response->pageShortName; // 'jgdemo'

$auth = new BasicAuth('abced123', '[email protected]', 'pass123');
$httpClient = new \My\Own\Psr18Client;
$options = [
    'root_domain' => 'https://api.staging.justgiving.com', 
    'api_version' => 2,
];

$client = new JustGivingClient($auth, $httpClient, $options);

$client->donation->getStatus($donationId);                  // The actual method

$client->donation->RetrieveDonationStatus($donationId);     // The alias method that's the same as the API action name

// Data set via constructor
$team = new Team([
    'name'      => 'My Team',
    'story'     => 'This is my story',
    'target'    => 1000,
]);

// Data set via fill() method
$team = new Team;
$team->fill([
    'name'      => 'My Team',
    'story'     => 'This is my story',
    'target'    => 1000,
]);

// Data set by setting public properties individually
$team = new Team;
$team->name = 'My Team';
$team->story = 'This is my story';
$team->target = 1000;

$endpoint = 'campaign/' . $campaignGUID;

$client->request('GET', $endpoint, [], ['api_version' => 2]);

$client->request('POST', 'new-endpoint', [
        'headers' => ['x-custom-header' => 'custom'],
        'json'    => ['title' => 'The Title'],
    ], [
        'api_version' => 2,
        'root_domain' => 'https://api.staging.justgiving.com',
    ]);

$response->getBody()->getContents()     // Returns the raw JSON response

$response->body;                         // Returns the decoded response

$result = $client->charity->getById(2050);
$result->body->name;            // 'The Demo Charity1'
$result->body->websiteUrl;      // 'http://www.democharity.co.uk'
$result->body->pageShortName;   // 'jgdemo'

$result = $client->charity->getById(2050);
$result->name;                  // 'The Demo Charity1'
$result->websiteUrl;            // 'http://www.democharity.co.uk'
$result->pageShortName;         // 'jgdemo'

$response = $this->client->account->create(new CreateAccountRequest([
    'email'     => "[email protected]",
    'firstName' => "John",
    'lastName'  => "Smith",
    'password'  => 'password',
    'title'     => "Mr",
    'address' => new Address([
       'line1'             => "testLine1",
       'line2'             => "testLine2",
       'country'           => "United Kingdom",
       'countyOrState'     => "testCountyOrState",
       'townOrCity'        => "testTownOrCity",
       'postcodeOrZipcode' => "M130EJ",
    ]),

    'acceptTermsAndConditions' => false
]));

$errors = $response->errors;
// $errors is:
// [
//    'ReasonPhrase'                        => 'Validation errors occured.',
//    'FirstNameNotSpecified'               => 'The FirstName field is 

$response = $this->client->account->create(new CreateAccountRequest([
    'email'     => "[email protected]",
    'firstName' => "John",
    'lastName'  => "Smith",
    'password'  => 'password',
    'title'     => "Mr",
    'address' => new Address([
       'line1'             => "testLine1",
       'line2'             => "testLine2",
       'country'           => "United Kingdom",
       'countyOrState'     => "testCountyOrState",
       'townOrCity'        => "testTownOrCity",
       'postcodeOrZipcode' => "M130EJ",
    ]),

    'acceptTermsAndConditions' => true
]));

$errors = $response->errors;
// $errors is:
// [
//    'ReasonPhrase'    => 'Bad request',
//    'General'         => 'That email address is already in use'
// ]