fix failing test, check contribution creating with default date of now
[civicrm-core.git] / api / v3 / examples / Contact / APIChainedArray.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using contact get API
4 * /*this demonstrates the usage of chained api functions. In this case no notes or custom fields have been created *
6a488035
TO
5 */
6function contact_get_example(){
edb0d67a 7$params = array(
6a488035 8 'id' => 1,
6a488035 9 'api.website.get' => array(),
edb0d67a 10 'api.Contribution.get' => array(
6a488035
TO
11 'total_amount' => '120.00',
12 ),
13 'api.CustomValue.get' => 1,
14 'api.Note.get' => 1,
15);
16
fb32de45 17try{
18 $result = civicrm_api3('contact', 'get', $params);
19}
20catch (CiviCRM_API3_Exception $e) {
21 // handle error here
22 $errorMessage = $e->getMessage();
23 $errorCode = $e->getErrorCode();
24 $errorData = $e->getExtraParams();
25 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
26}
6a488035 27
fb32de45 28return $result;
6a488035
TO
29}
30
fb32de45 31/**
6a488035
TO
32 * Function returns array of result expected from previous function
33 */
34function contact_get_expectedresult(){
35
edb0d67a 36 $expectedResult = array(
6a488035
TO
37 'is_error' => 0,
38 'version' => 3,
39 'count' => 1,
40 'id' => 1,
edb0d67a 41 'values' => array(
42 '1' => array(
6a488035
TO
43 'contact_id' => '1',
44 'contact_type' => 'Individual',
45 'contact_sub_type' => '',
46 'sort_name' => 'xyz3, abc3',
47 'display_name' => 'abc3 xyz3',
48 'do_not_email' => 0,
49 'do_not_phone' => 0,
50 'do_not_mail' => 0,
51 'do_not_sms' => 0,
52 'do_not_trade' => 0,
53 'is_opt_out' => 0,
54 'legal_identifier' => '',
55 'external_identifier' => '',
56 'nick_name' => '',
57 'legal_name' => '',
58 'image_URL' => '',
59 'preferred_mail_format' => 'Both',
60 'first_name' => 'abc3',
61 'middle_name' => '',
62 'last_name' => 'xyz3',
6ecbca5b 63 'prefix_id' => '',
64 'suffix_id' => '',
6a488035 65 'job_title' => '',
6ecbca5b 66 'gender_id' => '',
6a488035
TO
67 'birth_date' => '',
68 'is_deceased' => 0,
69 'deceased_date' => '',
70 'household_name' => '',
71 'organization_name' => '',
72 'sic_code' => '',
73 'contact_is_deleted' => 0,
6a488035
TO
74 'current_employer' => '',
75 'address_id' => '',
76 'street_address' => '',
77 'supplemental_address_1' => '',
78 'supplemental_address_2' => '',
79 'city' => '',
80 'postal_code_suffix' => '',
81 'postal_code' => '',
82 'geo_code_1' => '',
83 'geo_code_2' => '',
84 'state_province_id' => '',
6a488035 85 'country_id' => '',
6a488035
TO
86 'phone_id' => '',
87 'phone_type_id' => '',
88 'phone' => '',
89 'email_id' => '1',
90 'email' => 'man3@yahoo.com',
91 'on_hold' => 0,
92 'im_id' => '',
93 'provider_id' => '',
94 'im' => '',
95 'worldregion_id' => '',
96 'world_region' => '',
6ecbca5b 97 'individual_prefix' => '',
98 'individual_suffix' => '',
99 'gender' => '',
9f1b81e0 100 'state_province_name' => '',
101 'state_province' => '',
102 'country' => '',
6a488035 103 'id' => '1',
edb0d67a 104 'api.website.get' => array(
6a488035
TO
105 'is_error' => 0,
106 'version' => 3,
107 'count' => 1,
108 'id' => 1,
edb0d67a 109 'values' => array(
110 '0' => array(
6a488035
TO
111 'id' => '1',
112 'contact_id' => '1',
113 'url' => 'http://civicrm.org',
114 ),
115 ),
116 ),
edb0d67a 117 'api.Contribution.get' => array(
6a488035
TO
118 'is_error' => 0,
119 'version' => 3,
120 'count' => 1,
121 'id' => 2,
edb0d67a 122 'values' => array(
123 '0' => array(
6a488035
TO
124 'contact_id' => '1',
125 'contact_type' => 'Individual',
126 'contact_sub_type' => '',
127 'sort_name' => 'xyz3, abc3',
128 'display_name' => 'abc3 xyz3',
129 'contribution_id' => '2',
130 'currency' => 'USD',
131 'receive_date' => '2011-01-01 00:00:00',
132 'non_deductible_amount' => '10.00',
133 'total_amount' => '120.00',
134 'fee_amount' => '50.00',
135 'net_amount' => '90.00',
136 'trxn_id' => '12335',
137 'invoice_id' => '67830',
138 'cancel_date' => '',
139 'cancel_reason' => '',
140 'receipt_date' => '',
141 'thankyou_date' => '',
142 'contribution_source' => 'SSF',
143 'amount_level' => '',
144 'is_test' => 0,
145 'is_pay_later' => 0,
146 'contribution_status_id' => '1',
147 'check_number' => '',
148 'contribution_campaign_id' => '',
149 'financial_type_id' => '1',
150 'financial_type' => 'Donation',
edb0d67a 151 'instrument_id' => '81',
6a488035
TO
152 'payment_instrument' => 'Credit Card',
153 'product_id' => '',
154 'product_name' => '',
155 'sku' => '',
156 'contribution_product_id' => '',
157 'product_option' => '',
158 'fulfilled_date' => '',
159 'contribution_start_date' => '',
160 'contribution_end_date' => '',
161 'contribution_recur_id' => '',
162 'financial_account_id' => '1',
163 'accounting_code' => '4200',
164 'contribution_note' => '',
165 'contribution_batch' => '',
166 'contribution_status' => 'Completed',
167 'contribution_payment_instrument' => 'Credit Card',
168 'contribution_check_number' => '',
169 'id' => '2',
edb0d67a 170 'contribution_type_id' => '1',
6a488035
TO
171 ),
172 ),
173 ),
edb0d67a 174 'api.CustomValue.get' => array(
6a488035
TO
175 'is_error' => 0,
176 'version' => 3,
177 'count' => 0,
178 'values' => array(),
179 ),
edb0d67a 180 'api.Note.get' => array(
6a488035
TO
181 'is_error' => 0,
182 'version' => 3,
183 'count' => 0,
184 'values' => array(),
185 ),
186 ),
187 ),
188);
189
fb32de45 190 return $expectedResult;
6a488035
TO
191}
192
193
194/*
195* This example has been generated from the API test suite. The test that created it is called
196*
197* testGetIndividualWithChainedArrays and can be found in
198* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
199*
200* You can see the outcome of the API tests at
201* http://tests.dev.civicrm.org/trunk/results-api_v3
202*
203* To Learn about the API read
204* http://book.civicrm.org/developer/current/techniques/api/
205*
206* and review the wiki at
207* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
208*
209* Read more about testing here
210* http://wiki.civicrm.org/confluence/display/CRM/Testing
211*
212* API Standards documentation:
213* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
214*/