3 * Test Generated example of using contribution create API.
5 * Create Contribution with Nested Line Items
10 function contribution_create_example() {
13 'receive_date' => '20120511',
14 'total_amount' => '100',
15 'financial_type_id' => 1,
16 'payment_instrument_id' => 1,
17 'non_deductible_amount' => '10',
21 'invoice_id' => 67890,
23 'contribution_status_id' => 1,
25 'api.line_item.create' => array(
27 'price_field_id' => 1,
33 'price_field_id' => 1,
42 $result = civicrm_api3('contribution', 'create', $params);
44 catch (CiviCRM_API3_Exception
$e) {
46 $errorMessage = $e->getMessage();
47 $errorCode = $e->getErrorCode();
48 $errorData = $e->getExtraParams();
50 'error' => $errorMessage,
51 'error_code' => $errorCode,
52 'error_data' => $errorData,
60 * Function returns array of result expected from previous function.
65 function contribution_create_expectedresult() {
67 $expectedResult = array(
76 'financial_type_id' => '1',
77 'contribution_page_id' => '',
78 'payment_instrument_id' => '1',
79 'receive_date' => '20120511000000',
80 'non_deductible_amount' => '10',
81 'total_amount' => '100',
85 'invoice_id' => '67890',
88 'cancel_reason' => '',
90 'thankyou_date' => '',
93 'contribution_recur_id' => '',
96 'contribution_status_id' => '1',
100 'creditnote_id' => '',
102 'contribution_type_id' => '1',
103 'api.line_item.create' => array(
112 'entity_table' => 'civicrm_contribution',
114 'contribution_id' => '1',
115 'price_field_id' => '1',
116 'label' => 'line item',
118 'unit_price' => '10',
119 'line_total' => '20',
120 'participant_count' => '',
121 'price_field_value_id' => '',
122 'financial_type_id' => '',
123 'deductible_amount' => '',
136 'entity_table' => 'civicrm_contribution',
138 'contribution_id' => '1',
139 'price_field_id' => '1',
140 'label' => 'line item',
142 'unit_price' => '80',
143 'line_total' => '80',
144 'participant_count' => '',
145 'price_field_value_id' => '',
146 'financial_type_id' => '',
147 'deductible_amount' => '',
157 return $expectedResult;
161 * This example has been generated from the API test suite.
162 * The test that created it is called
163 * testCreateContributionChainedLineItems
164 * and can be found in
165 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
167 * You can see the outcome of the API tests at
168 * https://test.civicrm.org/job/CiviCRM-master-git/
170 * To Learn about the API read
171 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
173 * Browse the api on your own site with the api explorer
174 * http://MYSITE.ORG/path/to/civicrm/api
176 * Read more about testing here
177 * http://wiki.civicrm.org/confluence/display/CRM/Testing
179 * API Standards documentation:
180 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards