Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 2 | /** |
3 | * Test Generated example of using contribution create API | |
4 | * Create Contribution with Nested Line Items * | |
6a488035 TO |
5 | */ |
6 | function contribution_create_example(){ | |
53ca8fd7 | 7 | $params = array( |
6a488035 TO |
8 | 'contact_id' => 1, |
9 | 'receive_date' => '20120511', | |
10 | 'total_amount' => '100', | |
11 | 'financial_type_id' => 1, | |
12 | 'payment_instrument_id' => 1, | |
13 | 'non_deductible_amount' => '10', | |
14 | 'fee_amount' => '50', | |
15 | 'net_amount' => '90', | |
16 | 'trxn_id' => 12345, | |
17 | 'invoice_id' => 67890, | |
18 | 'source' => 'SSF', | |
19 | 'contribution_status_id' => 1, | |
6a488035 | 20 | 'skipLineItem' => 1, |
53ca8fd7 | 21 | 'api.line_item.create' => array( |
22 | '0' => array( | |
6a488035 TO |
23 | 'price_field_id' => 1, |
24 | 'qty' => 2, | |
25 | 'line_total' => '20', | |
26 | 'unit_price' => '10', | |
27 | ), | |
53ca8fd7 | 28 | '1' => array( |
6a488035 TO |
29 | 'price_field_id' => 1, |
30 | 'qty' => 1, | |
31 | 'line_total' => '80', | |
32 | 'unit_price' => '80', | |
33 | ), | |
34 | ), | |
35 | ); | |
36 | ||
fb32de45 | 37 | try{ |
38 | $result = civicrm_api3('contribution', 'create', $params); | |
39 | } | |
40 | catch (CiviCRM_API3_Exception $e) { | |
41 | // handle error here | |
42 | $errorMessage = $e->getMessage(); | |
43 | $errorCode = $e->getErrorCode(); | |
44 | $errorData = $e->getExtraParams(); | |
45 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); | |
46 | } | |
6a488035 | 47 | |
fb32de45 | 48 | return $result; |
6a488035 TO |
49 | } |
50 | ||
fb32de45 | 51 | /** |
6a488035 TO |
52 | * Function returns array of result expected from previous function |
53 | */ | |
54 | function contribution_create_expectedresult(){ | |
55 | ||
53ca8fd7 | 56 | $expectedResult = array( |
6a488035 TO |
57 | 'is_error' => 0, |
58 | 'version' => 3, | |
59 | 'count' => 1, | |
60 | 'id' => 1, | |
53ca8fd7 | 61 | 'values' => array( |
62 | '1' => array( | |
6a488035 TO |
63 | 'id' => '1', |
64 | 'contact_id' => '1', | |
65 | 'financial_type_id' => '1', | |
66 | 'contribution_page_id' => '', | |
67 | 'payment_instrument_id' => '1', | |
68 | 'receive_date' => '20120511000000', | |
69 | 'non_deductible_amount' => '10', | |
70 | 'total_amount' => '100', | |
71 | 'fee_amount' => '50', | |
72 | 'net_amount' => '90', | |
73 | 'trxn_id' => '12345', | |
74 | 'invoice_id' => '67890', | |
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 | 'honor_contact_id' => '', | |
84 | 'is_test' => '', | |
85 | 'is_pay_later' => '', | |
86 | 'contribution_status_id' => '1', | |
87 | 'honor_type_id' => '', | |
88 | 'address_id' => '', | |
9f1b81e0 | 89 | 'check_number' => '', |
6a488035 | 90 | 'campaign_id' => '', |
502b3d42 | 91 | 'contribution_type_id' => '1', |
53ca8fd7 | 92 | 'api.line_item.create' => array( |
93 | '0' => array( | |
6a488035 TO |
94 | 'is_error' => 0, |
95 | 'version' => 3, | |
96 | 'count' => 1, | |
97 | 'id' => 1, | |
53ca8fd7 | 98 | 'values' => array( |
99 | '0' => array( | |
6a488035 TO |
100 | 'id' => '1', |
101 | 'entity_table' => 'civicrm_contribution', | |
102 | 'entity_id' => '1', | |
103 | 'price_field_id' => '1', | |
104 | 'label' => 'line item', | |
105 | 'qty' => '2', | |
106 | 'unit_price' => '10', | |
107 | 'line_total' => '20', | |
108 | 'participant_count' => '', | |
109 | 'price_field_value_id' => '', | |
110 | 'financial_type_id' => '', | |
111 | 'deductible_amount' => '', | |
112 | ), | |
113 | ), | |
114 | ), | |
53ca8fd7 | 115 | '1' => array( |
6a488035 TO |
116 | 'is_error' => 0, |
117 | 'version' => 3, | |
118 | 'count' => 1, | |
119 | 'id' => 2, | |
53ca8fd7 | 120 | 'values' => array( |
121 | '0' => array( | |
6a488035 TO |
122 | 'id' => '2', |
123 | 'entity_table' => 'civicrm_contribution', | |
124 | 'entity_id' => '1', | |
125 | 'price_field_id' => '1', | |
126 | 'label' => 'line item', | |
127 | 'qty' => '1', | |
128 | 'unit_price' => '80', | |
129 | 'line_total' => '80', | |
130 | 'participant_count' => '', | |
131 | 'price_field_value_id' => '', | |
132 | 'financial_type_id' => '', | |
133 | 'deductible_amount' => '', | |
134 | ), | |
135 | ), | |
136 | ), | |
137 | ), | |
138 | ), | |
139 | ), | |
140 | ); | |
141 | ||
fb32de45 | 142 | return $expectedResult; |
6a488035 TO |
143 | } |
144 | ||
145 | ||
146 | /* | |
147 | * This example has been generated from the API test suite. The test that created it is called | |
148 | * | |
149 | * testCreateContributionChainedLineItems and can be found in | |
69d79249 | 150 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php |
6a488035 TO |
151 | * |
152 | * You can see the outcome of the API tests at | |
69d79249 | 153 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
154 | * |
155 | * To Learn about the API read | |
69d79249 | 156 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 157 | * |
69d79249 E |
158 | * Browse the api on your own site with the api explorer |
159 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
6a488035 TO |
160 | * |
161 | * Read more about testing here | |
162 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
163 | * | |
164 | * API Standards documentation: | |
165 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 166 | */ |