50fb255d |
1 | <?php |
50fb255d |
2 | /** |
3 | * Test Generated example of using tax_contribution_page create API. |
4 | * |
5 | * Create Contribution with Nested Line Items |
6 | * |
7 | * @return array |
8 | * API result array |
9 | */ |
10 | function tax_contribution_page_create_example() { |
11 | $params = array( |
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, |
21 | 'api.line_item.create' => array( |
22 | '0' => array( |
23 | 'price_field_id' => array( |
24 | '0' => 3, |
25 | ), |
26 | 'qty' => 1, |
27 | 'line_total' => '100', |
28 | 'unit_price' => '100', |
29 | 'financial_type_id' => 7, |
30 | ), |
31 | '1' => array( |
32 | 'price_field_id' => array( |
33 | '0' => 3, |
34 | ), |
35 | 'qty' => 1, |
36 | 'line_total' => '300', |
37 | 'unit_price' => '300', |
38 | 'financial_type_id' => 8, |
39 | ), |
40 | ), |
41 | ); |
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(); |
51 | return array( |
52 | 'error' => $errorMessage, |
53 | 'error_code' => $errorCode, |
54 | 'error_data' => $errorData, |
55 | ); |
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 | |
69 | $expectedResult = array( |
70 | 'is_error' => 0, |
71 | 'version' => 3, |
72 | 'count' => 1, |
73 | 'id' => 1, |
74 | 'values' => array( |
75 | '1' => array( |
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', |
105 | 'api.line_item.create' => array( |
106 | '0' => array( |
107 | 'is_error' => 0, |
108 | 'version' => 3, |
109 | 'count' => 1, |
110 | 'id' => 1, |
111 | 'values' => array( |
112 | '0' => array( |
113 | 'id' => '1', |
114 | 'entity_table' => 'civicrm_contribution', |
115 | 'entity_id' => '1', |
116 | 'contribution_id' => '1', |
117 | 'price_field_id' => array( |
118 | '0' => '3', |
119 | ), |
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', |
129 | ), |
130 | ), |
131 | ), |
132 | '1' => array( |
133 | 'is_error' => 0, |
134 | 'version' => 3, |
135 | 'count' => 1, |
136 | 'id' => 2, |
137 | 'values' => array( |
138 | '0' => array( |
139 | 'id' => '2', |
140 | 'entity_table' => 'civicrm_contribution', |
141 | 'entity_id' => '1', |
142 | 'contribution_id' => '1', |
143 | 'price_field_id' => array( |
144 | '0' => '3', |
145 | ), |
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', |
155 | ), |
156 | ), |
157 | ), |
158 | ), |
159 | ), |
160 | ), |
161 | ); |
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 | */ |