Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contact.create API. |
50fb255d | 4 | * |
5c49fee0 CW |
5 | * Single function to create contact with partipation & contribution. |
6 | * Note that in the case of 'contribution' the 'create' is implied (api.contribution.create) | |
50fb255d | 7 | * |
8 | * @return array | |
9 | * API result array | |
6a488035 | 10 | */ |
a828d7b8 | 11 | function contact_create_example() { |
50fb255d | 12 | $params = array( |
13 | 'contact_type' => 'Individual', | |
14 | 'display_name' => 'dlobo', | |
15 | 'api.participant' => array( | |
89bf81b4 | 16 | 'event_id' => 40, |
6a488035 TO |
17 | 'status_id' => 1, |
18 | 'role_id' => 1, | |
19 | 'format.only_id' => 1, | |
20 | ), | |
50fb255d | 21 | 'api.contribution.create' => array( |
6a488035 TO |
22 | 'financial_type_id' => 1, |
23 | 'total_amount' => 100, | |
24 | 'format.only_id' => 1, | |
25 | ), | |
50fb255d | 26 | 'api.participant_payment.create' => array( |
6a488035 TO |
27 | 'contribution_id' => '$value.api.contribution.create', |
28 | 'participant_id' => '$value.api.participant', | |
29 | ), | |
50fb255d | 30 | ); |
6a488035 | 31 | |
50fb255d | 32 | try{ |
a828d7b8 | 33 | $result = civicrm_api3('Contact', 'create', $params); |
50fb255d | 34 | } |
35 | catch (CiviCRM_API3_Exception $e) { | |
36 | // Handle error here. | |
37 | $errorMessage = $e->getMessage(); | |
38 | $errorCode = $e->getErrorCode(); | |
39 | $errorData = $e->getExtraParams(); | |
40 | return array( | |
41 | 'error' => $errorMessage, | |
42 | 'error_code' => $errorCode, | |
43 | 'error_data' => $errorData, | |
44 | ); | |
45 | } | |
6a488035 | 46 | |
50fb255d | 47 | return $result; |
6a488035 TO |
48 | } |
49 | ||
fb32de45 | 50 | /** |
50fb255d | 51 | * Function returns array of result expected from previous function. |
52 | * | |
53 | * @return array | |
54 | * API result array | |
6a488035 | 55 | */ |
a828d7b8 | 56 | function contact_create_expectedresult() { |
6a488035 | 57 | |
53ca8fd7 | 58 | $expectedResult = array( |
50fb255d | 59 | 'is_error' => 0, |
60 | 'version' => 3, | |
61 | 'count' => 1, | |
62 | 'id' => 5, | |
63 | 'values' => array( | |
53ca8fd7 | 64 | '5' => array( |
50fb255d | 65 | 'id' => '5', |
66 | 'contact_type' => 'Individual', | |
67 | 'contact_sub_type' => '', | |
68 | 'do_not_email' => 0, | |
69 | 'do_not_phone' => 0, | |
70 | 'do_not_mail' => 0, | |
71 | 'do_not_sms' => 0, | |
72 | 'do_not_trade' => 0, | |
73 | 'is_opt_out' => 0, | |
74 | 'legal_identifier' => '', | |
75 | 'external_identifier' => '', | |
76 | 'sort_name' => '', | |
77 | 'display_name' => 'dlobo', | |
78 | 'nick_name' => '', | |
79 | 'legal_name' => '', | |
80 | 'image_URL' => '', | |
81 | 'preferred_communication_method' => '', | |
82 | 'preferred_language' => 'en_US', | |
83 | 'preferred_mail_format' => 'Both', | |
84 | 'hash' => '67eac7789eaee00', | |
85 | 'api_key' => '', | |
86 | 'first_name' => '', | |
87 | 'middle_name' => '', | |
88 | 'last_name' => '', | |
89 | 'prefix_id' => '', | |
90 | 'suffix_id' => '', | |
91 | 'formal_title' => '', | |
92 | 'communication_style_id' => '', | |
93 | 'email_greeting_id' => '1', | |
94 | 'email_greeting_custom' => '', | |
95 | 'email_greeting_display' => '', | |
96 | 'postal_greeting_id' => '1', | |
97 | 'postal_greeting_custom' => '', | |
98 | 'postal_greeting_display' => '', | |
99 | 'addressee_id' => '1', | |
100 | 'addressee_custom' => '', | |
101 | 'addressee_display' => '', | |
102 | 'job_title' => '', | |
103 | 'gender_id' => '', | |
104 | 'birth_date' => '', | |
105 | 'is_deceased' => 0, | |
106 | 'deceased_date' => '', | |
107 | 'household_name' => '', | |
108 | 'primary_contact_id' => '', | |
109 | 'organization_name' => '', | |
110 | 'sic_code' => '', | |
111 | 'user_unique_id' => '', | |
112 | 'created_date' => '2013-07-28 08:49:19', | |
113 | 'modified_date' => '2012-11-14 16:02:35', | |
114 | 'api.participant' => 4, | |
115 | 'api.contribution.create' => 1, | |
116 | 'api.participant_payment.create' => array( | |
117 | 'is_error' => 0, | |
118 | 'version' => 3, | |
119 | 'count' => 1, | |
120 | 'id' => 1, | |
121 | 'values' => array( | |
122 | '0' => array( | |
123 | 'id' => '1', | |
124 | 'participant_id' => '4', | |
125 | 'contribution_id' => '1', | |
6a488035 | 126 | ), |
50fb255d | 127 | ), |
6a488035 | 128 | ), |
50fb255d | 129 | ), |
6a488035 | 130 | ), |
50fb255d | 131 | ); |
6a488035 | 132 | |
fb32de45 | 133 | return $expectedResult; |
6a488035 TO |
134 | } |
135 | ||
a828d7b8 | 136 | /* |
50fb255d | 137 | * This example has been generated from the API test suite. |
a828d7b8 CW |
138 | * The test that created it is called "testCreateParticipantWithPayment" |
139 | * and can be found at: | |
69d79249 | 140 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ParticipantTest.php |
6a488035 TO |
141 | * |
142 | * You can see the outcome of the API tests at | |
69d79249 | 143 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
144 | * |
145 | * To Learn about the API read | |
69d79249 | 146 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 147 | * |
69d79249 | 148 | * Browse the api on your own site with the api explorer |
41d4d31f | 149 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
150 | * |
151 | * Read more about testing here | |
152 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
153 | * | |
154 | * API Standards documentation: | |
155 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 156 | */ |