3 * Test Generated example of using contribution create API
4 * Create Contribution with Nested Line Items *
6 function contribution_create_example(){
9 'receive_date' => '20120511',
10 'total_amount' => '100',
11 'financial_type_id' => 1,
12 'payment_instrument_id' => 1,
13 'non_deductible_amount' => '10',
17 'invoice_id' => 67890,
19 'contribution_status_id' => 1,
21 'api.line_item.create' => array(
23 'price_field_id' => 1,
29 'price_field_id' => 1,
38 $result = civicrm_api3('contribution', 'create', $params);
40 catch (CiviCRM_API3_Exception
$e) {
42 $errorMessage = $e->getMessage();
43 $errorCode = $e->getErrorCode();
44 $errorData = $e->getExtraParams();
45 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
52 * Function returns array of result expected from previous function
54 function contribution_create_expectedresult(){
56 $expectedResult = array(
65 'financial_type_id' => '1',
66 'contribution_page_id' => '',
67 'payment_instrument_id' => '1',
68 'receive_date' => '20120511000000',
69 'non_deductible_amount' => '10',
70 'total_amount' => '100',
74 'invoice_id' => '67890',
77 'cancel_reason' => '',
79 'thankyou_date' => '',
82 'contribution_recur_id' => '',
83 'honor_contact_id' => '',
86 'contribution_status_id' => '1',
87 'honor_type_id' => '',
89 'check_number' => 'null',
91 'contribution_type_id' => '1',
92 'api.line_item.create' => array(
101 'entity_table' => 'civicrm_contribution',
103 'price_field_id' => '1',
104 'label' => 'line item',
106 'unit_price' => '10',
107 'line_total' => '20',
108 'participant_count' => '',
109 'price_field_value_id' => '',
110 'financial_type_id' => '',
111 'deductible_amount' => '',
123 'entity_table' => 'civicrm_contribution',
125 'price_field_id' => '1',
126 'label' => 'line item',
128 'unit_price' => '80',
129 'line_total' => '80',
130 'participant_count' => '',
131 'price_field_value_id' => '',
132 'financial_type_id' => '',
133 'deductible_amount' => '',
142 return $expectedResult;
147 * This example has been generated from the API test suite. The test that created it is called
149 * testCreateContributionChainedLineItems and can be found in
150 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContributionTest.php
152 * You can see the outcome of the API tests at
153 * http://tests.dev.civicrm.org/trunk/results-api_v3
155 * To Learn about the API read
156 * http://book.civicrm.org/developer/current/techniques/api/
158 * and review the wiki at
159 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
161 * Read more about testing here
162 * http://wiki.civicrm.org/confluence/display/CRM/Testing
164 * API Standards documentation:
165 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards