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