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() { | |
11 | $params = array( | |
1d8ee3d6 | 12 | 'contact_id' => 24, |
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, | |
21 | 'soft_credit' => array( | |
89bf81b4 | 22 | '1' => array( |
1d8ee3d6 | 23 | 'contact_id' => 25, |
50fb255d | 24 | 'amount' => 50, |
25 | 'soft_credit_type_id' => 3, | |
26 | ), | |
89bf81b4 | 27 | ), |
50fb255d | 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(); | |
38 | return array( | |
1d8ee3d6 | 39 | 'is_error' => 1, |
40 | 'error_message' => $errorMessage, | |
50fb255d | 41 | 'error_code' => $errorCode, |
42 | 'error_data' => $errorData, | |
43 | ); | |
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 | |
53ca8fd7 | 57 | $expectedResult = array( |
50fb255d | 58 | 'is_error' => 0, |
59 | 'version' => 3, | |
60 | 'count' => 1, | |
61 | 'id' => 1, | |
62 | 'values' => array( | |
53ca8fd7 | 63 | '1' => array( |
50fb255d | 64 | 'id' => '1', |
1d8ee3d6 | 65 | 'contact_id' => '24', |
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' => '', | |
76 | 'currency' => 'USD', | |
77 | 'cancel_date' => '', | |
78 | 'cancel_reason' => '', | |
79 | 'receipt_date' => '', | |
80 | 'thankyou_date' => '', | |
81 | 'source' => 'SSF', | |
82 | 'amount_level' => '', | |
83 | 'contribution_recur_id' => '', | |
84 | 'is_test' => '', | |
85 | 'is_pay_later' => '', | |
86 | 'contribution_status_id' => '1', | |
87 | 'address_id' => '', | |
88 | 'check_number' => '', | |
89 | 'campaign_id' => '', | |
90 | 'creditnote_id' => '', | |
91 | 'tax_amount' => '', | |
1d8ee3d6 | 92 | 'revenue_recognition_date' => '', |
50fb255d | 93 | 'contribution_type_id' => '1', |
94 | ), | |
6a488035 | 95 | ), |
50fb255d | 96 | ); |
6a488035 | 97 | |
fb32de45 | 98 | return $expectedResult; |
6a488035 TO |
99 | } |
100 | ||
a828d7b8 | 101 | /* |
50fb255d | 102 | * This example has been generated from the API test suite. |
a828d7b8 CW |
103 | * The test that created it is called "testCreateContributionWithSoftCredit" |
104 | * and can be found at: | |
69d79249 | 105 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php |
6a488035 TO |
106 | * |
107 | * You can see the outcome of the API tests at | |
69d79249 | 108 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
109 | * |
110 | * To Learn about the API read | |
69d79249 | 111 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 112 | * |
69d79249 | 113 | * Browse the api on your own site with the api explorer |
41d4d31f | 114 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
115 | * |
116 | * Read more about testing here | |
117 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
118 | * | |
119 | * API Standards documentation: | |
120 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 121 | */ |