PHP code example of reason-digital / virgin-money-giving-api

1. Go to this page and download the library: Download reason-digital/virgin-money-giving-api 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/ */

    

reason-digital / virgin-money-giving-api example snippets



// Initialise the connector
$fundraiserConnector = new FundraiserVmgConnector('API_KEY', $guzzleClient, $testMode = false);

try {
    $response = $fundraiserConnector->search('Test', 'User');
} catch (ConnectorException $exception) {
    // VMG error message No fundraiser found for  forename=User surname=Test
    $exception->getErrorMessage();
    // VMG erorr code 001.02.011
    $exception->getErrorCode();
}


// Initialise the connector
$fundraiserConnector = new FundraiserVmgConnector('API_KEY', $guzzleClient, $testMode = false);

try {
    $fundraiser = new Fundraiser();
    $fundraiser->setTitle('Mr')
        ->setForename('firstName')
        ->setSurname('lastName')
        ->setAddressLine1('streetName')
        ->setAddressLine2('streetAddress')
        ->setTownCity('city')
        ->setCountyState('county')
        ->setPostcode('postcode')
        ->setCountryCode('countryCode')
        ->setPreferredTelephone('12345678912')
        ->setEmailAddress('Email')
        ->setPersonalUrl('url')
        ->setTermsAndConditionsAccepted('Y')
        ->setDateOfBirth('20010101');
    
    $fundraiserResponse = $fundraiserConnector->createFundraiserAccount($fundraiser, 'CALLBACK_URL');
} catch (ConnectorException $exception) {
    $exception->getErrorMessage();
    $exception->getErrorCode();
}


// Initialise the connector
$fundraiserConnector = new FundraiserVmgConnector('API_KEY', $guzzleClient, $testMode = false);

try {
    $page = new Page();
    $page->setPageTitle()
        ->setEventResourceId('EVENT_ID')
        ->setFundraisingTarget(2000.00)
        ->setCharityResourceId('CHARITY_ID')
        ->setCharitySplits([
            [
                'charityResourceId' => '6a5880c9-13e4-4cf4-987e-931f3899b9d5',
                'charitySplitPercent' => 50
            ],
            [
                'charityResourceId' => '8da32779-1c1b-4d20-8714-df3219836618',
                'charitySplitPercent' => 50
            ]
        ]);
    
    // Now create the page.
    $pageCreateResponse = $fundraiserConnector->createFundraiserPage($page, $fundraiser, $fundraiserResponse->getAccessToken());
} catch (ConnectorException $exception) {
    $exception->getErrorMessage();
    $exception->getErrorCode();
}