Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Pledge.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function pledge_create_example() { | |
9 | $params = array( | |
10 | 'contact_id' => 11, | |
a828d7b8 CW |
11 | 'pledge_create_date' => '20150222', |
12 | 'start_date' => '20150222', | |
13 | 'scheduled_date' => '20150224', | |
50fb255d | 14 | 'amount' => '100', |
15 | 'pledge_status_id' => '2', | |
16 | 'pledge_financial_type_id' => '1', | |
17 | 'pledge_original_installment_amount' => 20, | |
18 | 'frequency_interval' => 5, | |
19 | 'frequency_unit' => 'year', | |
20 | 'frequency_day' => 15, | |
21 | 'installments' => 5, | |
22 | 'sequential' => 1, | |
23 | ); | |
6a488035 | 24 | |
50fb255d | 25 | try{ |
a828d7b8 | 26 | $result = civicrm_api3('Pledge', 'create', $params); |
50fb255d | 27 | } |
28 | catch (CiviCRM_API3_Exception $e) { | |
29 | // Handle error here. | |
30 | $errorMessage = $e->getMessage(); | |
31 | $errorCode = $e->getErrorCode(); | |
32 | $errorData = $e->getExtraParams(); | |
33 | return array( | |
34 | 'error' => $errorMessage, | |
35 | 'error_code' => $errorCode, | |
36 | 'error_data' => $errorData, | |
37 | ); | |
38 | } | |
39 | ||
40 | return $result; | |
6a488035 TO |
41 | } |
42 | ||
fb32de45 | 43 | /** |
50fb255d | 44 | * Function returns array of result expected from previous function. |
45 | * | |
46 | * @return array | |
47 | * API result array | |
6a488035 | 48 | */ |
50fb255d | 49 | function pledge_create_expectedresult() { |
6a488035 | 50 | |
53ca8fd7 | 51 | $expectedResult = array( |
50fb255d | 52 | 'is_error' => 0, |
53 | 'version' => 3, | |
54 | 'count' => 1, | |
55 | 'id' => 1, | |
56 | 'values' => array( | |
53ca8fd7 | 57 | '0' => array( |
50fb255d | 58 | 'id' => '1', |
59 | 'contact_id' => '11', | |
60 | 'financial_type_id' => '1', | |
61 | 'contribution_page_id' => '', | |
62 | 'amount' => '100', | |
63 | 'original_installment_amount' => '20', | |
64 | 'currency' => 'USD', | |
65 | 'frequency_unit' => 'year', | |
66 | 'frequency_interval' => '5', | |
67 | 'frequency_day' => '15', | |
68 | 'installments' => '5', | |
69 | 'start_date' => '2013-07-29 00:00:00', | |
70 | 'create_date' => '20120130621222105', | |
71 | 'acknowledge_date' => '', | |
72 | 'modified_date' => '', | |
73 | 'cancel_date' => '', | |
74 | 'end_date' => '', | |
75 | 'max_reminders' => '', | |
76 | 'initial_reminder_day' => '', | |
77 | 'additional_reminder_day' => '', | |
78 | 'status_id' => '2', | |
79 | 'is_test' => '', | |
80 | 'campaign_id' => '', | |
81 | ), | |
6a488035 | 82 | ), |
50fb255d | 83 | ); |
6a488035 | 84 | |
fb32de45 | 85 | return $expectedResult; |
6a488035 TO |
86 | } |
87 | ||
a828d7b8 | 88 | /* |
50fb255d | 89 | * This example has been generated from the API test suite. |
a828d7b8 CW |
90 | * The test that created it is called "testCreatePledge" |
91 | * and can be found at: | |
69d79249 | 92 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PledgeTest.php |
6a488035 TO |
93 | * |
94 | * You can see the outcome of the API tests at | |
69d79249 | 95 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
96 | * |
97 | * To Learn about the API read | |
69d79249 | 98 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 99 | * |
69d79249 | 100 | * Browse the api on your own site with the api explorer |
41d4d31f | 101 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
102 | * |
103 | * Read more about testing here | |
104 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
105 | * | |
106 | * API Standards documentation: | |
107 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 108 | */ |