Fix queue code to use CiviCRM's version of what the time is, instead of server's.
[civicrm-core.git] / api / v3 / examples / Contribution / CreateWithNestedLineItems.ex.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contribution.create API.
4 *
5 * Create Contribution with Nested Line Items.
6 *
7 * @return array
8 * API result array
9 */
10 function contribution_create_example() {
11 $params = [
12 'contact_id' => 12,
13 'receive_date' => '20120511',
14 'total_amount' => '100',
15 'financial_type_id' => 1,
16 'payment_instrument_id' => 1,
17 'non_deductible_amount' => '10',
18 'fee_amount' => '50',
19 'net_amount' => '90',
20 'trxn_id' => 12345,
21 'invoice_id' => 67890,
22 'source' => 'SSF',
23 'contribution_status_id' => 1,
24 'skipLineItem' => 1,
25 'api.line_item.create' => [
26 '0' => [
27 'price_field_id' => 1,
28 'qty' => 2,
29 'line_total' => '20',
30 'unit_price' => '10',
31 ],
32 '1' => [
33 'price_field_id' => 1,
34 'qty' => 1,
35 'line_total' => '80',
36 'unit_price' => '80',
37 ],
38 ],
39 ];
40
41 try{
42 $result = civicrm_api3('Contribution', 'create', $params);
43 }
44 catch (CiviCRM_API3_Exception $e) {
45 // Handle error here.
46 $errorMessage = $e->getMessage();
47 $errorCode = $e->getErrorCode();
48 $errorData = $e->getExtraParams();
49 return [
50 'is_error' => 1,
51 'error_message' => $errorMessage,
52 'error_code' => $errorCode,
53 'error_data' => $errorData,
54 ];
55 }
56
57 return $result;
58 }
59
60 /**
61 * Function returns array of result expected from previous function.
62 *
63 * @return array
64 * API result array
65 */
66 function contribution_create_expectedresult() {
67
68 $expectedResult = [
69 'is_error' => 0,
70 'version' => 3,
71 'count' => 1,
72 'id' => 1,
73 'values' => [
74 '1' => [
75 'id' => '1',
76 'contact_id' => '12',
77 'financial_type_id' => '1',
78 'contribution_page_id' => '',
79 'payment_instrument_id' => '1',
80 'receive_date' => '20120511000000',
81 'non_deductible_amount' => '10',
82 'total_amount' => '100',
83 'fee_amount' => '50',
84 'net_amount' => '90',
85 'trxn_id' => '12345',
86 'invoice_id' => '67890',
87 'invoice_number' => '',
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' => 0,
104 'revenue_recognition_date' => '',
105 'contribution_type_id' => '1',
106 'api.line_item.create' => [
107 '0' => [
108 'is_error' => 0,
109 'version' => 3,
110 'count' => 1,
111 'id' => 1,
112 'values' => [
113 '0' => [
114 'id' => '1',
115 'entity_table' => 'civicrm_contribution',
116 'entity_id' => '1',
117 'contribution_id' => '1',
118 'price_field_id' => '1',
119 'label' => 'line item',
120 'qty' => '2',
121 'unit_price' => '10',
122 'line_total' => '20',
123 'participant_count' => '',
124 'price_field_value_id' => '',
125 'financial_type_id' => '',
126 'non_deductible_amount' => '',
127 'tax_amount' => '',
128 ],
129 ],
130 ],
131 '1' => [
132 'is_error' => 0,
133 'version' => 3,
134 'count' => 1,
135 'id' => 2,
136 'values' => [
137 '0' => [
138 'id' => '2',
139 'entity_table' => 'civicrm_contribution',
140 'entity_id' => '1',
141 'contribution_id' => '1',
142 'price_field_id' => '1',
143 'label' => 'line item',
144 'qty' => '1',
145 'unit_price' => '80',
146 'line_total' => '80',
147 'participant_count' => '',
148 'price_field_value_id' => '',
149 'financial_type_id' => '',
150 'non_deductible_amount' => '',
151 'tax_amount' => '',
152 ],
153 ],
154 ],
155 ],
156 ],
157 ],
158 ];
159
160 return $expectedResult;
161 }
162
163 /*
164 * This example has been generated from the API test suite.
165 * The test that created it is called "testCreateContributionChainedLineItems"
166 * and can be found at:
167 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
168 *
169 * You can see the outcome of the API tests at
170 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
171 *
172 * To Learn about the API read
173 * https://docs.civicrm.org/dev/en/latest/api/
174 *
175 * Browse the API on your own site with the API Explorer. It is in the main
176 * CiviCRM menu, under: Support > Development > API Explorer.
177 *
178 * Read more about testing here
179 * https://docs.civicrm.org/dev/en/latest/testing/
180 *
181 * API Standards documentation:
182 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
183 */