3 * Test Generated example demonstrating the Contribution.create API.
5 * Demonstrates creating contribution with SoftCredit.
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' => array(
25 'soft_credit_type_id' => 3,
31 $result = civicrm_api3('Contribution', 'create', $params);
33 catch (CiviCRM_API3_Exception
$e) {
35 $errorMessage = $e->getMessage();
36 $errorCode = $e->getErrorCode();
37 $errorData = $e->getExtraParams();
39 'error' => $errorMessage,
40 'error_code' => $errorCode,
41 'error_data' => $errorData,
49 * 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' => '4',
68 'receive_date' => '20120511000000',
69 'non_deductible_amount' => '10',
70 'total_amount' => '100',
77 'cancel_reason' => '',
79 'thankyou_date' => '',
82 'contribution_recur_id' => '',
85 'contribution_status_id' => '1',
89 'creditnote_id' => '',
91 'contribution_type_id' => '1',
96 return $expectedResult;
100 * This example has been generated from the API test suite.
101 * The test that created it is called "testCreateContributionWithSoftCredit"
102 * and can be found at:
103 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
105 * You can see the outcome of the API tests at
106 * https://test.civicrm.org/job/CiviCRM-master-git/
108 * To Learn about the API read
109 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
111 * Browse the api on your own site with the api explorer
112 * http://MYSITE.ORG/path/to/civicrm/api
114 * Read more about testing here
115 * http://wiki.civicrm.org/confluence/display/CRM/Testing
117 * API Standards documentation:
118 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards