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