Merge pull request #767 from eileenmcnaughton/CRM-12628
[civicrm-core.git] / api / v3 / examples / Contribution / CreateWithNestedLineItems.php
1 <?php
2
3 /*
4 Create Contribution with Nested Line Items
5 */
6 function contribution_create_example(){
7 $params = array(
8 'contact_id' => 1,
9 'receive_date' => '20120511',
10 'total_amount' => '100',
11 'financial_type_id' => 1,
12 'payment_instrument_id' => 1,
13 'non_deductible_amount' => '10',
14 'fee_amount' => '50',
15 'net_amount' => '90',
16 'trxn_id' => 12345,
17 'invoice_id' => 67890,
18 'source' => 'SSF',
19 'contribution_status_id' => 1,
20 'version' => 3,
21 'skipLineItem' => 1,
22 'api.line_item.create' => array(
23 '0' => array(
24 'price_field_id' => 1,
25 'qty' => 2,
26 'line_total' => '20',
27 'unit_price' => '10',
28 ),
29 '1' => array(
30 'price_field_id' => 1,
31 'qty' => 1,
32 'line_total' => '80',
33 'unit_price' => '80',
34 ),
35 ),
36 );
37
38 $result = civicrm_api( 'contribution','create',$params );
39
40 return $result;
41 }
42
43 /*
44 * Function returns array of result expected from previous function
45 */
46 function contribution_create_expectedresult(){
47
48 $expectedResult = array(
49 'is_error' => 0,
50 'version' => 3,
51 'count' => 1,
52 'id' => 1,
53 'values' => array(
54 '1' => array(
55 'id' => '1',
56 'contact_id' => '1',
57 'financial_type_id' => '1',
58 'contribution_page_id' => '',
59 'payment_instrument_id' => '1',
60 'receive_date' => '20120511000000',
61 'non_deductible_amount' => '10',
62 'total_amount' => '100',
63 'fee_amount' => '50',
64 'net_amount' => '90',
65 'trxn_id' => '12345',
66 'invoice_id' => '67890',
67 'currency' => 'USD',
68 'cancel_date' => '',
69 'cancel_reason' => '',
70 'receipt_date' => '',
71 'thankyou_date' => '',
72 'source' => 'SSF',
73 'amount_level' => '',
74 'contribution_recur_id' => '',
75 'honor_contact_id' => '',
76 'is_test' => '',
77 'is_pay_later' => '',
78 'contribution_status_id' => '1',
79 'honor_type_id' => '',
80 'address_id' => '',
81 'check_number' => 'null',
82 'campaign_id' => '',
83 'contribution_type_id' => '1',
84 'api.line_item.create' => array(
85 '0' => array(
86 'is_error' => 0,
87 'undefined_fields' => array(
88 '0' => 'label',
89 '1' => 'entity_id',
90 '2' => 'entity_table',
91 '3' => 'contribution_id',
92 '4' => 'api.has_parent',
93 '5' => 'price_field_id',
94 '6' => 'qty',
95 '7' => 'line_total',
96 '8' => 'unit_price',
97 ),
98 'version' => 3,
99 'count' => 1,
100 'id' => 1,
101 'values' => array(
102 '0' => array(
103 'id' => '1',
104 'entity_table' => 'civicrm_contribution',
105 'entity_id' => '1',
106 'price_field_id' => '1',
107 'label' => 'line item',
108 'qty' => '2',
109 'unit_price' => '10',
110 'line_total' => '20',
111 'participant_count' => '',
112 'price_field_value_id' => '',
113 'financial_type_id' => '',
114 'deductible_amount' => '',
115 ),
116 ),
117 ),
118 '1' => array(
119 'is_error' => 0,
120 'undefined_fields' => array(
121 '0' => 'label',
122 '1' => 'entity_id',
123 '2' => 'entity_table',
124 '3' => 'contribution_id',
125 '4' => 'api.has_parent',
126 '5' => 'price_field_id',
127 '6' => 'qty',
128 '7' => 'line_total',
129 '8' => 'unit_price',
130 ),
131 'version' => 3,
132 'count' => 1,
133 'id' => 2,
134 'values' => array(
135 '0' => array(
136 'id' => '2',
137 'entity_table' => 'civicrm_contribution',
138 'entity_id' => '1',
139 'price_field_id' => '1',
140 'label' => 'line item',
141 'qty' => '1',
142 'unit_price' => '80',
143 'line_total' => '80',
144 'participant_count' => '',
145 'price_field_value_id' => '',
146 'financial_type_id' => '',
147 'deductible_amount' => '',
148 ),
149 ),
150 ),
151 ),
152 ),
153 ),
154 );
155
156 return $expectedResult ;
157 }
158
159
160 /*
161 * This example has been generated from the API test suite. The test that created it is called
162 *
163 * testCreateContributionChainedLineItems and can be found in
164 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContributionTest.php
165 *
166 * You can see the outcome of the API tests at
167 * http://tests.dev.civicrm.org/trunk/results-api_v3
168 *
169 * To Learn about the API read
170 * http://book.civicrm.org/developer/current/techniques/api/
171 *
172 * and review the wiki at
173 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
174 *
175 * Read more about testing here
176 * http://wiki.civicrm.org/confluence/display/CRM/Testing
177 *
178 * API Standards documentation:
179 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
180 */