Merge pull request #9648 from MegaphoneJon/CRM-19608
[civicrm-core.git] / api / v3 / examples / Contact / CreateParticipantPayment.php
CommitLineData
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 11function contact_create_example() {
50fb255d 12 $params = array(
13 'contact_type' => 'Individual',
14 'display_name' => 'dlobo',
15 'api.participant' => array(
1d8ee3d6 16 'event_id' => 42,
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(
1d8ee3d6 41 'is_error' => 1,
42 'error_message' => $errorMessage,
50fb255d 43 'error_code' => $errorCode,
44 'error_data' => $errorData,
45 );
46 }
6a488035 47
50fb255d 48 return $result;
6a488035
TO
49}
50
fb32de45 51/**
50fb255d 52 * Function returns array of result expected from previous function.
53 *
54 * @return array
55 * API result array
6a488035 56 */
a828d7b8 57function contact_create_expectedresult() {
6a488035 58
53ca8fd7 59 $expectedResult = array(
50fb255d 60 'is_error' => 0,
61 'version' => 3,
62 'count' => 1,
63 'id' => 5,
64 'values' => array(
53ca8fd7 65 '5' => array(
50fb255d 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' => '',
1d8ee3d6 77 'sort_name' => 'dlobo',
50fb255d 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',
6a488035 127 ),
50fb255d 128 ),
6a488035 129 ),
50fb255d 130 ),
6a488035 131 ),
50fb255d 132 );
6a488035 133
fb32de45 134 return $expectedResult;
6a488035
TO
135}
136
a828d7b8 137/*
50fb255d 138* This example has been generated from the API test suite.
a828d7b8
CW
139* The test that created it is called "testCreateParticipantWithPayment"
140* and can be found at:
69d79249 141* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ParticipantTest.php
6a488035
TO
142*
143* You can see the outcome of the API tests at
69d79249 144* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
145*
146* To Learn about the API read
69d79249 147* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 148*
69d79249 149* Browse the api on your own site with the api explorer
41d4d31f 150* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
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
b259a4ab 157*/