Commit | Line | Data |
---|---|---|
6a516bd6 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contribution.create API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * Demonstrates creating contribution with Soft Credit defaults for amount and type. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function contribution_create_example() { | |
11 | $params = array( | |
5c49fee0 | 12 | 'contact_id' => 21, |
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, | |
5c49fee0 | 21 | 'soft_credit_to' => 22, |
50fb255d | 22 | ); |
6a516bd6 | 23 | |
50fb255d | 24 | try{ |
a828d7b8 | 25 | $result = civicrm_api3('Contribution', 'create', $params); |
50fb255d | 26 | } |
27 | catch (CiviCRM_API3_Exception $e) { | |
28 | // Handle error here. | |
29 | $errorMessage = $e->getMessage(); | |
30 | $errorCode = $e->getErrorCode(); | |
31 | $errorData = $e->getExtraParams(); | |
32 | return array( | |
33 | 'error' => $errorMessage, | |
34 | 'error_code' => $errorCode, | |
35 | 'error_data' => $errorData, | |
36 | ); | |
37 | } | |
38 | ||
39 | return $result; | |
6a516bd6 DG |
40 | } |
41 | ||
42 | /** | |
50fb255d | 43 | * Function returns array of result expected from previous function. |
44 | * | |
45 | * @return array | |
46 | * API result array | |
6a516bd6 | 47 | */ |
50fb255d | 48 | function contribution_create_expectedresult() { |
6a516bd6 DG |
49 | |
50 | $expectedResult = array( | |
50fb255d | 51 | 'is_error' => 0, |
52 | 'version' => 3, | |
53 | 'count' => 1, | |
54 | 'id' => 1, | |
55 | 'values' => array( | |
6a516bd6 | 56 | '1' => array( |
50fb255d | 57 | 'id' => '1', |
5c49fee0 | 58 | 'contact_id' => '21', |
50fb255d | 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', | |
65 | 'fee_amount' => '5', | |
66 | 'net_amount' => '95', | |
67 | 'trxn_id' => '', | |
68 | 'invoice_id' => '', | |
69 | 'currency' => 'USD', | |
70 | 'cancel_date' => '', | |
71 | 'cancel_reason' => '', | |
72 | 'receipt_date' => '', | |
73 | 'thankyou_date' => '', | |
74 | 'source' => 'SSF', | |
75 | 'amount_level' => '', | |
76 | 'contribution_recur_id' => '', | |
77 | 'is_test' => '', | |
78 | 'is_pay_later' => '', | |
79 | 'contribution_status_id' => '1', | |
80 | 'address_id' => '', | |
81 | 'check_number' => '', | |
82 | 'campaign_id' => '', | |
83 | 'creditnote_id' => '', | |
84 | 'tax_amount' => '', | |
85 | 'contribution_type_id' => '1', | |
86 | ), | |
6a516bd6 | 87 | ), |
50fb255d | 88 | ); |
6a516bd6 DG |
89 | |
90 | return $expectedResult; | |
91 | } | |
92 | ||
a828d7b8 | 93 | /* |
50fb255d | 94 | * This example has been generated from the API test suite. |
a828d7b8 CW |
95 | * The test that created it is called "testCreateContributionWithSoftCreditDefaults" |
96 | * and can be found at: | |
6a516bd6 DG |
97 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php |
98 | * | |
99 | * You can see the outcome of the API tests at | |
100 | * https://test.civicrm.org/job/CiviCRM-master-git/ | |
101 | * | |
102 | * To Learn about the API read | |
103 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API | |
104 | * | |
105 | * Browse the api on your own site with the api explorer | |
41d4d31f | 106 | * http://MYSITE.ORG/path/to/civicrm/api |
6a516bd6 DG |
107 | * |
108 | * Read more about testing here | |
109 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
110 | * | |
111 | * API Standards documentation: | |
112 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
113 | */ |