Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contribution.create API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * Demonstrates creating contribution with SoftCredit. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function contribution_create_example() { | |
cf8f0fff | 11 | $params = [ |
dc396835 | 12 | 'contact_id' => 28, |
50fb255d | 13 | 'receive_date' => '20120511', |
14 | 'total_amount' => '100', | |
15 | 'financial_type_id' => 1, | |
16 | 'non_deductible_amount' => '10', | |
17 | 'fee_amount' => '5', | |
18 | 'net_amount' => '95', | |
19 | 'source' => 'SSF', | |
20 | 'contribution_status_id' => 1, | |
cf8f0fff CW |
21 | 'soft_credit' => [ |
22 | '1' => [ | |
dc396835 | 23 | 'contact_id' => 29, |
50fb255d | 24 | 'amount' => 50, |
25 | 'soft_credit_type_id' => 3, | |
cf8f0fff CW |
26 | ], |
27 | ], | |
28 | ]; | |
6a488035 | 29 | |
50fb255d | 30 | try{ |
a828d7b8 | 31 | $result = civicrm_api3('Contribution', 'create', $params); |
50fb255d | 32 | } |
33 | catch (CiviCRM_API3_Exception $e) { | |
34 | // Handle error here. | |
35 | $errorMessage = $e->getMessage(); | |
36 | $errorCode = $e->getErrorCode(); | |
37 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 38 | return [ |
1d8ee3d6 | 39 | 'is_error' => 1, |
40 | 'error_message' => $errorMessage, | |
50fb255d | 41 | 'error_code' => $errorCode, |
42 | 'error_data' => $errorData, | |
cf8f0fff | 43 | ]; |
50fb255d | 44 | } |
6a488035 | 45 | |
50fb255d | 46 | return $result; |
6a488035 TO |
47 | } |
48 | ||
fb32de45 | 49 | /** |
50fb255d | 50 | * Function returns array of result expected from previous function. |
51 | * | |
52 | * @return array | |
53 | * API result array | |
6a488035 | 54 | */ |
50fb255d | 55 | function contribution_create_expectedresult() { |
6a488035 | 56 | |
cf8f0fff | 57 | $expectedResult = [ |
50fb255d | 58 | 'is_error' => 0, |
59 | 'version' => 3, | |
60 | 'count' => 1, | |
61 | 'id' => 1, | |
cf8f0fff CW |
62 | 'values' => [ |
63 | '1' => [ | |
50fb255d | 64 | 'id' => '1', |
dc396835 | 65 | 'contact_id' => '28', |
50fb255d | 66 | 'financial_type_id' => '1', |
67 | 'contribution_page_id' => '', | |
68 | 'payment_instrument_id' => '4', | |
69 | 'receive_date' => '20120511000000', | |
70 | 'non_deductible_amount' => '10', | |
71 | 'total_amount' => '100', | |
72 | 'fee_amount' => '5', | |
73 | 'net_amount' => '95', | |
74 | 'trxn_id' => '', | |
75 | 'invoice_id' => '', | |
8390b11b | 76 | 'invoice_number' => '', |
50fb255d | 77 | 'currency' => 'USD', |
78 | 'cancel_date' => '', | |
79 | 'cancel_reason' => '', | |
80 | 'receipt_date' => '', | |
81 | 'thankyou_date' => '', | |
82 | 'source' => 'SSF', | |
83 | 'amount_level' => '', | |
84 | 'contribution_recur_id' => '', | |
85 | 'is_test' => '', | |
86 | 'is_pay_later' => '', | |
87 | 'contribution_status_id' => '1', | |
88 | 'address_id' => '', | |
89 | 'check_number' => '', | |
90 | 'campaign_id' => '', | |
91 | 'creditnote_id' => '', | |
92 | 'tax_amount' => '', | |
1d8ee3d6 | 93 | 'revenue_recognition_date' => '', |
dc396835 | 94 | 'is_template' => '', |
50fb255d | 95 | 'contribution_type_id' => '1', |
cf8f0fff CW |
96 | ], |
97 | ], | |
98 | ]; | |
6a488035 | 99 | |
fb32de45 | 100 | return $expectedResult; |
6a488035 TO |
101 | } |
102 | ||
a828d7b8 | 103 | /* |
50fb255d | 104 | * This example has been generated from the API test suite. |
a828d7b8 CW |
105 | * The test that created it is called "testCreateContributionWithSoftCredit" |
106 | * and can be found at: | |
69d79249 | 107 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php |
6a488035 TO |
108 | * |
109 | * You can see the outcome of the API tests at | |
8390b11b | 110 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
6a488035 TO |
111 | * |
112 | * To Learn about the API read | |
8390b11b | 113 | * https://docs.civicrm.org/dev/en/latest/api/ |
6a488035 | 114 | * |
8390b11b SL |
115 | * Browse the API on your own site with the API Explorer. It is in the main |
116 | * CiviCRM menu, under: Support > Development > API Explorer. | |
6a488035 TO |
117 | * |
118 | * Read more about testing here | |
8390b11b | 119 | * https://docs.civicrm.org/dev/en/latest/testing/ |
6a488035 TO |
120 | * |
121 | * API Standards documentation: | |
8390b11b | 122 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
b259a4ab | 123 | */ |