Find file
Fetching contributors…
Cannot retrieve contributors at this time
104 lines (76 sloc) 3.44 KB
FirstGiving PHP SDK
[FirstGiving Platform]( is
a set of APIs that integrate our charity and donations capabilities into your website. Read more about
[integrating FirstGiving with your web site](
on the FirstGiving developer site.
This repository contains the open source PHP SDK that allows you to utilize the
above on your website. Except as otherwise noted, the FirstGiving PHP SDK
is licensed under the Apache Licence, Version 2.0
The [examples] folder is a good place to start. The minimal you'll need to
have is:
// Include the FirstGiving API client library.
require_once 'FirstGivingAPIClient.php';
// Setup the connection information.
$apiKey = 'YOURAPIKEY';
$apiSecret = 'YOURAPISECRET';
$apiEndpoint = '';
// Create an instance of the API client library.
$firstGivingApiClient = new FirstGivingAPIClient($apiKey, $apiSecret, $apiEndpoint);
// Create a donation.
$donation = new FirstGivingDonation();
$donation->setDescription('Test transaction.');
// Create a credit card payment.
$creditCardPayment = new FirstGivingCreditCardPayment();
$creditCardPayment->setBillToAddressLine1('1 Main St.');
try {
/* @var $firstGivingCreditCardDonationResponse FirstGivingCreditCardDonationResponse */
$firstGivingCreditCardDonationResponse = $firstGivingApiClient->makeCreditCardDonation($donation, $creditCardPayment, $_SERVER['REMOTE_ADDR']);
echo 'The donation was processed.';
// Uncategorized error reported by FirstGiving...
} catch (FirstGivingGeneralException $e) {
// Do some custom error handling....
$errorTarget = $e->getErrorTarget();
$friendlyConsumerError = $e->getFriendlyConsumerError();
$verboseExceptionMessage = $e->getVerboseExceptionMessage();
$rawResponse = $e->getRawResponse();
$responseCode = $e->getResponseCode();
// Invalid input reported by FirstGiving....
} catch (FirstGivingInvalidInputException $e) {
// Here you can do something useful with fields that valid validation.
$errorTarget = $e->getErrorTarget();
$friendlyConsumerError = $e->getFriendlyConsumerError();
$verboseExceptionMessage = $e->getVerboseExceptionMessage();
$rawResponse = $e->getRawResponse();
$responseCode = $e->getResponseCode();
throw $e;
// Something totally unexpected happened.
} catch (Exception $e) {
$problem = $e->getMessage();
[API Information]:
We are relying on the [GitHub issues tracker][issues] linked from above for
feedback. File bugs or other issues [here][issues].