Commit | Line | Data |
---|---|---|
50fb255d | 1 | <?php |
50fb255d | 2 | /** |
3 | * Test Generated example of using tax_contribution_page create API. | |
4 | * | |
5c49fee0 | 5 | * Create Contribution with Nested Line Items. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function tax_contribution_page_create_example() { | |
cf8f0fff | 11 | $params = [ |
50fb255d | 12 | 'contact_id' => 1, |
13 | 'receive_date' => '20120511', | |
14 | 'total_amount' => '400', | |
15 | 'financial_type_id' => 7, | |
16 | 'trxn_id' => 12345, | |
17 | 'invoice_id' => 67890, | |
18 | 'source' => 'SSF', | |
19 | 'contribution_status_id' => 1, | |
20 | 'skipLineItem' => 1, | |
cf8f0fff CW |
21 | 'api.line_item.create' => [ |
22 | '0' => [ | |
23 | 'price_field_id' => [ | |
50fb255d | 24 | '0' => 3, |
cf8f0fff | 25 | ], |
50fb255d | 26 | 'qty' => 1, |
27 | 'line_total' => '100', | |
28 | 'unit_price' => '100', | |
29 | 'financial_type_id' => 7, | |
cf8f0fff CW |
30 | ], |
31 | '1' => [ | |
32 | 'price_field_id' => [ | |
50fb255d | 33 | '0' => 3, |
cf8f0fff | 34 | ], |
50fb255d | 35 | 'qty' => 1, |
36 | 'line_total' => '300', | |
37 | 'unit_price' => '300', | |
38 | 'financial_type_id' => 8, | |
cf8f0fff CW |
39 | ], |
40 | ], | |
41 | ]; | |
50fb255d | 42 | |
43 | try{ | |
44 | $result = civicrm_api3('tax_contribution_page', 'create', $params); | |
45 | } | |
46 | catch (CiviCRM_API3_Exception $e) { | |
47 | // Handle error here. | |
48 | $errorMessage = $e->getMessage(); | |
49 | $errorCode = $e->getErrorCode(); | |
50 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 51 | return [ |
50fb255d | 52 | 'error' => $errorMessage, |
53 | 'error_code' => $errorCode, | |
54 | 'error_data' => $errorData, | |
cf8f0fff | 55 | ]; |
50fb255d | 56 | } |
57 | ||
58 | return $result; | |
59 | } | |
60 | ||
61 | /** | |
62 | * Function returns array of result expected from previous function. | |
63 | * | |
64 | * @return array | |
65 | * API result array | |
66 | */ | |
67 | function tax_contribution_page_create_expectedresult() { | |
68 | ||
cf8f0fff | 69 | $expectedResult = [ |
50fb255d | 70 | 'is_error' => 0, |
71 | 'version' => 3, | |
72 | 'count' => 1, | |
73 | 'id' => 1, | |
cf8f0fff CW |
74 | 'values' => [ |
75 | '1' => [ | |
50fb255d | 76 | 'id' => '1', |
77 | 'contact_id' => '1', | |
78 | 'financial_type_id' => '7', | |
79 | 'contribution_page_id' => '', | |
80 | 'payment_instrument_id' => '4', | |
81 | 'receive_date' => '20120511000000', | |
82 | 'non_deductible_amount' => '', | |
83 | 'total_amount' => '435', | |
84 | 'fee_amount' => 0, | |
85 | 'net_amount' => '435', | |
86 | 'trxn_id' => '12345', | |
87 | 'invoice_id' => '67890', | |
88 | 'currency' => 'USD', | |
89 | 'cancel_date' => '', | |
90 | 'cancel_reason' => '', | |
91 | 'receipt_date' => '', | |
92 | 'thankyou_date' => '', | |
93 | 'source' => 'SSF', | |
94 | 'amount_level' => '', | |
95 | 'contribution_recur_id' => '', | |
96 | 'is_test' => '', | |
97 | 'is_pay_later' => '', | |
98 | 'contribution_status_id' => '1', | |
99 | 'address_id' => '', | |
100 | 'check_number' => '', | |
101 | 'campaign_id' => '', | |
102 | 'creditnote_id' => '', | |
103 | 'tax_amount' => '35', | |
104 | 'contribution_type_id' => '7', | |
cf8f0fff CW |
105 | 'api.line_item.create' => [ |
106 | '0' => [ | |
50fb255d | 107 | 'is_error' => 0, |
108 | 'version' => 3, | |
109 | 'count' => 1, | |
110 | 'id' => 1, | |
cf8f0fff CW |
111 | 'values' => [ |
112 | '0' => [ | |
50fb255d | 113 | 'id' => '1', |
114 | 'entity_table' => 'civicrm_contribution', | |
115 | 'entity_id' => '1', | |
116 | 'contribution_id' => '1', | |
cf8f0fff | 117 | 'price_field_id' => [ |
50fb255d | 118 | '0' => '3', |
cf8f0fff | 119 | ], |
50fb255d | 120 | 'label' => 'line item', |
121 | 'qty' => '1', | |
122 | 'unit_price' => '100', | |
123 | 'line_total' => '100', | |
124 | 'participant_count' => '', | |
125 | 'price_field_value_id' => '', | |
126 | 'financial_type_id' => '7', | |
127 | 'deductible_amount' => '', | |
128 | 'tax_amount' => '20', | |
cf8f0fff CW |
129 | ], |
130 | ], | |
131 | ], | |
132 | '1' => [ | |
50fb255d | 133 | 'is_error' => 0, |
134 | 'version' => 3, | |
135 | 'count' => 1, | |
136 | 'id' => 2, | |
cf8f0fff CW |
137 | 'values' => [ |
138 | '0' => [ | |
50fb255d | 139 | 'id' => '2', |
140 | 'entity_table' => 'civicrm_contribution', | |
141 | 'entity_id' => '1', | |
142 | 'contribution_id' => '1', | |
cf8f0fff | 143 | 'price_field_id' => [ |
50fb255d | 144 | '0' => '3', |
cf8f0fff | 145 | ], |
50fb255d | 146 | 'label' => 'line item', |
147 | 'qty' => '1', | |
148 | 'unit_price' => '300', | |
149 | 'line_total' => '300', | |
150 | 'participant_count' => '', | |
151 | 'price_field_value_id' => '', | |
152 | 'financial_type_id' => '8', | |
153 | 'deductible_amount' => '', | |
154 | 'tax_amount' => '15', | |
cf8f0fff CW |
155 | ], |
156 | ], | |
157 | ], | |
158 | ], | |
159 | ], | |
160 | ], | |
161 | ]; | |
50fb255d | 162 | |
163 | return $expectedResult; | |
164 | } | |
165 | ||
166 | /** | |
167 | * This example has been generated from the API test suite. | |
168 | * The test that created it is called | |
169 | * testCreateContributionChainedLineItems | |
170 | * and can be found in | |
171 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/TaxContributionPageTest.php | |
172 | * | |
173 | * You can see the outcome of the API tests at | |
174 | * https://test.civicrm.org/job/CiviCRM-master-git/ | |
175 | * | |
176 | * To Learn about the API read | |
177 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API | |
178 | * | |
179 | * Browse the api on your own site with the api explorer | |
41d4d31f | 180 | * http://MYSITE.ORG/path/to/civicrm/api |
50fb255d | 181 | * |
182 | * Read more about testing here | |
183 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
184 | * | |
185 | * API Standards documentation: | |
186 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
187 | */ |