Overview

Namespaces

  • None
  • PHP

Classes

  • Account
  • AccountContactInfo
  • AccountInfo
  • Donation
  • DonationInfo
  • Donor
  • DonorInfo
  • iGivefirst

Exceptions

  • iGivefirst_AccountInformationIncomplete
  • iGivefirst_AccountNotCreated
  • iGivefirst_AccountNotUpdated
  • iGivefirst_AuthenticationError
  • iGivefirst_DonationInformationIncomplete
  • iGivefirst_DonationNotCreated
  • iGivefirst_DonorAlreadyExists
  • iGivefirst_DonorInformationIncomplete
  • iGivefirst_DonorNotCreated
  • iGivefirst_Error
  • iGivefirst_HttpError
  • iGivefirst_ObjectAlreadyExists
  • iGivefirst_ObjectNotFound
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * Donor interface for the iGivefirst Donation API
 5:  * Allows the lookup and creation of Donors
 6:  */
 7: class Donor {
 8:     private $api;
 9:     
10:     public function __construct($api) {
11:         $this->api = $api;
12:     }
13:     
14:     /**
15:      * Create a donor with the given information
16:      * 
17:      * @param DonorInfo $donor Object containing the donor information
18:      *
19:      * @throws iGivefirst_DonorInformationIncomplete if the donor information was not complete enough
20:      * @throws iGivefirst_DonorNotCreated if the parameters were not valid
21:      * @throws iGivefirst_DonorAlreadyExists if the donor already exists
22:      * 
23:      * @returns Array a hash containing the guid of the newly created donor
24:      */
25:     public function create(DonorInfo $donor) {
26:         if (!$donor->validate()) {
27:             throw new iGivefirst_DonorInformationIncomplete();
28:         }
29:         
30:         $req = $this->api->client->post('/donor');
31:         $req->setBody(json_encode($donor), 'application/json');
32:         
33:         try {
34:             return $this->api->execute($req)->json();
35:         }
36:         catch(iGivefirst_ObjectAlreadyExists $e) {
37:             throw new iGivefirst_DonorAlreadyExists($e);
38:         }
39:         catch(iGivefirst_HttpError $e) {
40:             throw new iGivefirst_DonorNotCreated($e);
41:         }
42:     }
43:     
44:     /**
45:      * Look up a donor by email address
46:      *
47:      * @params string $email email address of the donor
48:      * 
49:      * @throws iGivefirst_HttpError if an error occured
50:      * 
51:      * @returns Array a hash containing all the donor information or null
52:      */
53:      public function lookup($email) {
54:         $req = $this->api->client->get('/find-donor?emailAddress=' . $email);
55: 
56:         try {
57:             return $this->api->execute($req)->json();
58:         }
59:         catch(iGivefirst_ObjectNotFound $e) {
60:             return null;
61:         }
62:         catch(iGivefirst_HttpError $e) {
63:             throw $e;
64:         }
65:      }
66:      
67:     /**
68:      * Get a donor by guid
69:      * 
70:      * @params string $guid guid of the donor to look up
71:      * 
72:      * @throws iGivefirst_HttpError if an error occured
73:      * 
74:      * @returns Array a hash containing all the donor information or null
75:     */
76:     public function get($guid) {
77:         $req = $this->api->client->get('/donor/' . $guid);
78: 
79:         try {
80:             return $this->api->execute($req)->json();
81:         }
82:         catch(iGivefirst_ObjectNotFound $e) {
83:             return null;
84:         }
85:         catch(iGivefirst_HttpError $e) {
86:             throw $e;
87:         }
88:     }
89: }
90: ?>
91: 
API documentation generated by ApiGen 2.8.0