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