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' => 31,
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();
34 'error_message' => $errorMessage,
35 'error_code' => $errorCode,
36 'error_data' => $errorData,
44 * Function returns array of result expected from previous function.
49 function contribution_create_expectedresult() {
60 'financial_type_id' => '1',
61 'contribution_page_id' => '',
62 'payment_instrument_id' => '4',
63 'receive_date' => '20120511000000',
64 'non_deductible_amount' => '10',
65 'total_amount' => '100',
70 'invoice_number' => '',
73 'cancel_reason' => '',
75 'thankyou_date' => '',
78 'contribution_recur_id' => '',
81 'contribution_status_id' => '1',
85 'creditnote_id' => '',
87 'revenue_recognition_date' => '',
89 'contribution_type_id' => '1',
94 return $expectedResult;
98 * This example has been generated from the API test suite.
99 * The test that created it is called "testCreateContributionWithSoftCreditDefaults"
100 * and can be found at:
101 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
103 * You can see the outcome of the API tests at
104 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
106 * To Learn about the API read
107 * https://docs.civicrm.org/dev/en/latest/api/
109 * Browse the API on your own site with the API Explorer. It is in the main
110 * CiviCRM menu, under: Support > Development > API Explorer.
112 * Read more about testing here
113 * https://docs.civicrm.org/dev/en/latest/testing/
115 * API Standards documentation:
116 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/