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() { | |
cf8f0fff | 9 | $params = [ |
8390b11b SL |
10 | 'contact_id' => 12, |
11 | 'pledge_create_date' => '20190820', | |
12 | 'start_date' => '20190820', | |
13 | 'scheduled_date' => '20190822', | |
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, | |
cf8f0fff | 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(); | |
cf8f0fff | 33 | return [ |
1d8ee3d6 | 34 | 'is_error' => 1, |
35 | 'error_message' => $errorMessage, | |
50fb255d | 36 | 'error_code' => $errorCode, |
37 | 'error_data' => $errorData, | |
cf8f0fff | 38 | ]; |
50fb255d | 39 | } |
40 | ||
41 | return $result; | |
6a488035 TO |
42 | } |
43 | ||
fb32de45 | 44 | /** |
50fb255d | 45 | * Function returns array of result expected from previous function. |
46 | * | |
47 | * @return array | |
48 | * API result array | |
6a488035 | 49 | */ |
50fb255d | 50 | function pledge_create_expectedresult() { |
6a488035 | 51 | |
cf8f0fff | 52 | $expectedResult = [ |
50fb255d | 53 | 'is_error' => 0, |
54 | 'version' => 3, | |
55 | 'count' => 1, | |
56 | 'id' => 1, | |
cf8f0fff CW |
57 | 'values' => [ |
58 | '0' => [ | |
50fb255d | 59 | 'id' => '1', |
8390b11b | 60 | 'contact_id' => '12', |
50fb255d | 61 | 'financial_type_id' => '1', |
62 | 'contribution_page_id' => '', | |
63 | 'amount' => '100', | |
64 | 'original_installment_amount' => '20', | |
65 | 'currency' => 'USD', | |
66 | 'frequency_unit' => 'year', | |
67 | 'frequency_interval' => '5', | |
68 | 'frequency_day' => '15', | |
69 | 'installments' => '5', | |
70 | 'start_date' => '2013-07-29 00:00:00', | |
71 | 'create_date' => '20120130621222105', | |
72 | 'acknowledge_date' => '', | |
73 | 'modified_date' => '', | |
74 | 'cancel_date' => '', | |
75 | 'end_date' => '', | |
76 | 'max_reminders' => '', | |
77 | 'initial_reminder_day' => '', | |
78 | 'additional_reminder_day' => '', | |
79 | 'status_id' => '2', | |
80 | 'is_test' => '', | |
81 | 'campaign_id' => '', | |
8390b11b | 82 | 'contribution_type_id' => '1', |
cf8f0fff CW |
83 | ], |
84 | ], | |
85 | ]; | |
6a488035 | 86 | |
fb32de45 | 87 | return $expectedResult; |
6a488035 TO |
88 | } |
89 | ||
a828d7b8 | 90 | /* |
50fb255d | 91 | * This example has been generated from the API test suite. |
a828d7b8 CW |
92 | * The test that created it is called "testCreatePledge" |
93 | * and can be found at: | |
69d79249 | 94 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PledgeTest.php |
6a488035 TO |
95 | * |
96 | * You can see the outcome of the API tests at | |
8390b11b | 97 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
6a488035 TO |
98 | * |
99 | * To Learn about the API read | |
8390b11b | 100 | * https://docs.civicrm.org/dev/en/latest/api/ |
6a488035 | 101 | * |
8390b11b SL |
102 | * Browse the API on your own site with the API Explorer. It is in the main |
103 | * CiviCRM menu, under: Support > Development > API Explorer. | |
6a488035 TO |
104 | * |
105 | * Read more about testing here | |
8390b11b | 106 | * https://docs.civicrm.org/dev/en/latest/testing/ |
6a488035 TO |
107 | * |
108 | * API Standards documentation: | |
8390b11b | 109 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
b259a4ab | 110 | */ |