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