3 * Test Generated example demonstrating the Contribution.create API.
5 * Demonstrates creating contribution with Soft Credit defaults for amount and type.
10 function contribution_create_example() {
13 'receive_date' => '20120511',
14 'total_amount' => '100',
15 'financial_type_id' => 1,
16 'non_deductible_amount' => '10',
20 'contribution_status_id' => 1,
21 'soft_credit_to' => 22,
25 $result = civicrm_api3('Contribution', 'create', $params);
27 catch (CiviCRM_API3_Exception
$e) {
29 $errorMessage = $e->getMessage();
30 $errorCode = $e->getErrorCode();
31 $errorData = $e->getExtraParams();
33 'error' => $errorMessage,
34 'error_code' => $errorCode,
35 'error_data' => $errorData,
43 * Function returns array of result expected from previous function.
48 function contribution_create_expectedresult() {
50 $expectedResult = array(
59 'financial_type_id' => '1',
60 'contribution_page_id' => '',
61 'payment_instrument_id' => '4',
62 'receive_date' => '20120511000000',
63 'non_deductible_amount' => '10',
64 'total_amount' => '100',
71 'cancel_reason' => '',
73 'thankyou_date' => '',
76 'contribution_recur_id' => '',
79 'contribution_status_id' => '1',
83 'creditnote_id' => '',
85 'contribution_type_id' => '1',
90 return $expectedResult;
94 * This example has been generated from the API test suite.
95 * The test that created it is called "testCreateContributionWithSoftCreditDefaults"
96 * and can be found at:
97 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
99 * You can see the outcome of the API tests at
100 * https://test.civicrm.org/job/CiviCRM-master-git/
102 * To Learn about the API read
103 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
105 * Browse the api on your own site with the api explorer
106 * http://MYSITE.ORG/path/to/civicrm/api
108 * Read more about testing here
109 * http://wiki.civicrm.org/confluence/display/CRM/Testing
111 * API Standards documentation:
112 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards