1: <?php
2:
3: /**
4: * Account interface for the iGivefirst Donation API
5: * Allows creating and updating of account objects on a Donor
6: */
7: class Account {
8: private $api;
9:
10: public function __construct($api) {
11: $this->api = $api;
12: }
13:
14: /**
15: * Create an account with the given information
16: *
17: * @params AccountInfo $account Object containing the account information
18: *
19: * @throws iGivefirst_AccountInformationIncomplete if the account information was not complete enough
20: * @throws iGivefirst_AccountNotCreated if the parameters were not valid
21: *
22: * @returns Array a hash containing the guid of the newly created account
23: */
24: public function create(AccountInfo $account) {
25: if (!$account->validate()) {
26: throw new iGivefirst_AccountInformationIncomplete();
27: }
28:
29: $req = $this->api->client->post('/account');
30: $req->setBody(json_encode($account), 'application/json');
31:
32: try {
33: return $this->api->execute($req)->json();
34: }
35: catch(iGivefirst_HttpError $e) {
36: throw new iGivefirst_AccountNotCreated($e);
37: }
38: }
39:
40: /**
41: * Update an existing account with the given information. You must provide all account information.
42: *
43: * @params string $accountid guid of the account to update
44: * @params AccountInfo $account Object containing the account information
45: *
46: * @throws iGivefirst_AccountInformationIncomplete if the account information was not complete enough
47: * @throws iGivefirst_AccountNotUpdated if the parameters were not valid
48: *
49: * @returns void
50: */
51: public function update($accountid, AccountInfo $account) {
52: if (!$account->validate()) {
53: throw new iGivefirst_AccountInformationIncomplete();
54: }
55:
56: $req = $this->api->client->put('/account/' . $accountid);
57: $req->setBody(json_encode($account), 'application/json');
58:
59: try {
60: $this->api->execute($req);
61: }
62: catch(iGivefirst_HttpError $e) {
63: throw new iGivefirst_AccountNotUpdated($e);
64: }
65: }
66:
67: /**
68: * Disable an eixsting account
69: *
70: * @params string $accountid guid of the account to disable
71: *
72: * @throws iGivefirst_AccountNotUpdated if the parameters were not valid
73: */
74: public function disable($accountid) {
75: $req = $this->api->client->delete('/account/' . $accountid);
76:
77: try {
78: $this->api->execute($req);
79: }
80: catch(iGivefirst_HttpError $e) {
81: throw new iGivefirst_AccountNotUpdated($e);
82: }
83: }
84: }
85:
86: ?>
87: