Merge pull request #5086 from deepak-srivastava/CRM-15490
[civicrm-core.git] / api / v3 / examples / Contact / ChainTwoWebsites.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
50fb255d 3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6a488035 6 */
50fb255d 7
8/**
9 * Test Generated example of using contact create API.
10 *
11 * test demonstrates the syntax to create 2 chained entities
12 *
13 * @return array
14 * API result array
15 */
16function contact_create_example() {
17 $params = array(
18 'first_name' => 'abc3',
19 'last_name' => 'xyz3',
20 'contact_type' => 'Individual',
21 'email' => 'man3@yahoo.com',
22 'api.contribution.create' => array(
6a488035
TO
23 'receive_date' => '2010-01-01',
24 'total_amount' => '100',
25 'financial_type_id' => 1,
26 'payment_instrument_id' => 1,
27 'non_deductible_amount' => '10',
28 'fee_amount' => '50',
29 'net_amount' => '90',
30 'trxn_id' => 15345,
31 'invoice_id' => 67990,
32 'source' => 'SSF',
33 'contribution_status_id' => 1,
34 ),
50fb255d 35 'api.website.create' => array(
6a488035
TO
36 'url' => 'http://civicrm.org',
37 ),
50fb255d 38 'api.website.create.2' => array(
6a488035
TO
39 'url' => 'http://chained.org',
40 ),
50fb255d 41 );
6a488035 42
50fb255d 43 try{
44 $result = civicrm_api3('contact', 'create', $params);
45 }
46 catch (CiviCRM_API3_Exception $e) {
47 // Handle error here.
48 $errorMessage = $e->getMessage();
49 $errorCode = $e->getErrorCode();
50 $errorData = $e->getExtraParams();
51 return array(
52 'error' => $errorMessage,
53 'error_code' => $errorCode,
54 'error_data' => $errorData,
55 );
56 }
6a488035 57
50fb255d 58 return $result;
6a488035
TO
59}
60
fb32de45 61/**
50fb255d 62 * Function returns array of result expected from previous function.
63 *
64 * @return array
65 * API result array
6a488035 66 */
50fb255d 67function contact_create_expectedresult() {
6a488035 68
edb0d67a 69 $expectedResult = array(
50fb255d 70 'is_error' => 0,
71 'version' => 3,
72 'count' => 1,
73 'id' => 1,
74 'values' => array(
edb0d67a 75 '1' => array(
50fb255d 76 'id' => '1',
77 'contact_type' => 'Individual',
78 'contact_sub_type' => '',
79 'do_not_email' => 0,
80 'do_not_phone' => 0,
81 'do_not_mail' => 0,
82 'do_not_sms' => 0,
83 'do_not_trade' => 0,
84 'is_opt_out' => 0,
85 'legal_identifier' => '',
86 'external_identifier' => '',
87 'sort_name' => 'xyz3, abc3',
88 'display_name' => 'abc3 xyz3',
89 'nick_name' => '',
90 'legal_name' => '',
91 'image_URL' => '',
92 'preferred_communication_method' => '',
93 'preferred_language' => 'en_US',
94 'preferred_mail_format' => 'Both',
95 'hash' => '67eac7789eaee00',
96 'api_key' => '',
97 'first_name' => 'abc3',
98 'middle_name' => '',
99 'last_name' => 'xyz3',
100 'prefix_id' => '',
101 'suffix_id' => '',
102 'formal_title' => '',
103 'communication_style_id' => '',
104 'email_greeting_id' => '1',
105 'email_greeting_custom' => '',
106 'email_greeting_display' => '',
107 'postal_greeting_id' => '1',
108 'postal_greeting_custom' => '',
109 'postal_greeting_display' => '',
110 'addressee_id' => '1',
111 'addressee_custom' => '',
112 'addressee_display' => '',
113 'job_title' => '',
114 'gender_id' => '',
115 'birth_date' => '',
116 'is_deceased' => 0,
117 'deceased_date' => '',
118 'household_name' => '',
119 'primary_contact_id' => '',
120 'organization_name' => '',
121 'sic_code' => '',
122 'user_unique_id' => '',
123 'created_date' => '2013-07-28 08:49:19',
124 'modified_date' => '2012-11-14 16:02:35',
125 'api.contribution.create' => array(
126 'is_error' => 0,
127 'version' => 3,
128 'count' => 1,
129 'id' => 1,
130 'values' => array(
131 '0' => array(
132 'id' => '1',
133 'contact_id' => '1',
134 'financial_type_id' => '1',
135 'contribution_page_id' => '',
136 'payment_instrument_id' => '1',
137 'receive_date' => '20100101000000',
138 'non_deductible_amount' => '10',
139 'total_amount' => '100',
140 'fee_amount' => '50',
141 'net_amount' => '90',
142 'trxn_id' => '15345',
143 'invoice_id' => '67990',
144 'currency' => 'USD',
145 'cancel_date' => '',
146 'cancel_reason' => '',
147 'receipt_date' => '',
148 'thankyou_date' => '',
149 'source' => 'SSF',
150 'amount_level' => '',
151 'contribution_recur_id' => '',
152 'is_test' => '',
153 'is_pay_later' => '',
154 'contribution_status_id' => '1',
155 'address_id' => '',
156 'check_number' => '',
157 'campaign_id' => '',
158 'creditnote_id' => '',
159 'tax_amount' => '',
160 'contribution_type_id' => '1',
6a488035 161 ),
50fb255d 162 ),
163 ),
164 'api.website.create' => array(
165 'is_error' => 0,
166 'version' => 3,
167 'count' => 1,
168 'id' => 1,
169 'values' => array(
170 '0' => array(
171 'id' => '1',
172 'contact_id' => '1',
173 'url' => 'http://civicrm.org',
174 'website_type_id' => '',
6a488035 175 ),
50fb255d 176 ),
177 ),
178 'api.website.create.2' => array(
179 'is_error' => 0,
180 'version' => 3,
181 'count' => 1,
182 'id' => 2,
183 'values' => array(
184 '0' => array(
185 'id' => '2',
186 'contact_id' => '1',
187 'url' => 'http://chained.org',
188 'website_type_id' => '',
6a488035 189 ),
50fb255d 190 ),
6a488035 191 ),
50fb255d 192 ),
6a488035 193 ),
50fb255d 194 );
6a488035 195
fb32de45 196 return $expectedResult;
6a488035
TO
197}
198
50fb255d 199/**
200* This example has been generated from the API test suite.
201* The test that created it is called
202* testCreateIndividualWithContributionDottedSyntax
203* and can be found in
69d79249 204* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
205*
206* You can see the outcome of the API tests at
69d79249 207* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
208*
209* To Learn about the API read
69d79249 210* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 211*
69d79249
E
212* Browse the api on your own site with the api explorer
213* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
214*
215* Read more about testing here
216* http://wiki.civicrm.org/confluence/display/CRM/Testing
217*
218* API Standards documentation:
219* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 220*/