3 * Test Generated example demonstrating the 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' => [
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();
51 'error_message' => $errorMessage,
52 'error_code' => $errorCode,
53 'error_data' => $errorData,
61 * Function returns array of result expected from previous function.
66 function contribution_create_expectedresult() {
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',
86 'invoice_id' => '67890',
87 'invoice_number' => '',
90 'cancel_reason' => '',
92 'thankyou_date' => '',
95 'contribution_recur_id' => '',
98 'contribution_status_id' => '1',
100 'check_number' => '',
102 'creditnote_id' => '',
104 'revenue_recognition_date' => '',
106 'contribution_type_id' => '1',
107 'api.line_item.create' => [
116 'entity_table' => 'civicrm_contribution',
118 'contribution_id' => '1',
119 'price_field_id' => '1',
120 'label' => 'line item',
122 'unit_price' => '10',
123 'line_total' => '20',
124 'participant_count' => '',
125 'price_field_value_id' => '',
126 'financial_type_id' => '',
127 'non_deductible_amount' => '',
140 'entity_table' => 'civicrm_contribution',
142 'contribution_id' => '1',
143 'price_field_id' => '1',
144 'label' => 'line item',
146 'unit_price' => '80',
147 'line_total' => '80',
148 'participant_count' => '',
149 'price_field_value_id' => '',
150 'financial_type_id' => '',
151 'non_deductible_amount' => '',
161 return $expectedResult;
165 * This example has been generated from the API test suite.
166 * The test that created it is called "testCreateContributionChainedLineItems"
167 * and can be found at:
168 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
170 * You can see the outcome of the API tests at
171 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
173 * To Learn about the API read
174 * https://docs.civicrm.org/dev/en/latest/api/
176 * Browse the API on your own site with the API Explorer. It is in the main
177 * CiviCRM menu, under: Support > Development > API Explorer.
179 * Read more about testing here
180 * https://docs.civicrm.org/dev/en/latest/testing/
182 * API Standards documentation:
183 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/