Short array syntax - auto-convert api dir
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithHonoreeContact.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contribution.create API.
4 *
5 * Demonstrates creating contribution with Soft Credit by passing in honor_contact_id.
6 *
7 * @return array
8 * API result array
9 */
10 function contribution_create_example() {
11 $params = [
12 'contact_id' => 28,
13 'receive_date' => '20120511',
14 'total_amount' => '100',
15 'financial_type_id' => 1,
16 'non_deductible_amount' => '10',
17 'fee_amount' => '5',
18 'net_amount' => '95',
19 'source' => 'SSF',
20 'contribution_status_id' => 1,
21 'honor_contact_id' => 29,
22 ];
23
24 try{
25 $result = civicrm_api3('Contribution', 'create', $params);
26 }
27 catch (CiviCRM_API3_Exception $e) {
28 // Handle error here.
29 $errorMessage = $e->getMessage();
30 $errorCode = $e->getErrorCode();
31 $errorData = $e->getExtraParams();
32 return [
33 'is_error' => 1,
34 'error_message' => $errorMessage,
35 'error_code' => $errorCode,
36 'error_data' => $errorData,
37 ];
38 }
39
40 return $result;
41 }
42
43 /**
44 * Function returns array of result expected from previous function.
45 *
46 * @return array
47 * API result array
48 */
49 function contribution_create_expectedresult() {
50
51 $expectedResult = [
52 'is_error' => 0,
53 'version' => 3,
54 'count' => 1,
55 'id' => 1,
56 'values' => [
57 '1' => [
58 'id' => '1',
59 'contact_id' => '28',
60 'financial_type_id' => '1',
61 'contribution_page_id' => '',
62 'payment_instrument_id' => '4',
63 'receive_date' => '20120511000000',
64 'non_deductible_amount' => '10',
65 'total_amount' => '100',
66 'fee_amount' => '5',
67 'net_amount' => '95',
68 'trxn_id' => '',
69 'invoice_id' => '',
70 'currency' => 'USD',
71 'cancel_date' => '',
72 'cancel_reason' => '',
73 'receipt_date' => '',
74 'thankyou_date' => '',
75 'source' => 'SSF',
76 'amount_level' => '',
77 'contribution_recur_id' => '',
78 'is_test' => '',
79 'is_pay_later' => '',
80 'contribution_status_id' => '1',
81 'address_id' => '',
82 'check_number' => '',
83 'campaign_id' => '',
84 'creditnote_id' => '',
85 'tax_amount' => '',
86 'revenue_recognition_date' => '',
87 'contribution_type_id' => '1',
88 ],
89 ],
90 ];
91
92 return $expectedResult;
93 }
94
95 /*
96 * This example has been generated from the API test suite.
97 * The test that created it is called "testCreateContributionWithHonoreeContact"
98 * and can be found at:
99 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
100 *
101 * You can see the outcome of the API tests at
102 * https://test.civicrm.org/job/CiviCRM-master-git/
103 *
104 * To Learn about the API read
105 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
106 *
107 * Browse the api on your own site with the api explorer
108 * http://MYSITE.ORG/path/to/civicrm/api
109 *
110 * Read more about testing here
111 * http://wiki.civicrm.org/confluence/display/CRM/Testing
112 *
113 * API Standards documentation:
114 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
115 */