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