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