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