Merge pull request #15305 from yashodha/CRM_21777
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithNote.ex.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contribution.create API.
4 *
5 * Demonstrates creating contribution with Note Entity.
6 *
7 * @return array
8 * API result array
9 */
10 function contribution_create_example() {
11 $params = [
12 'contact_id' => 25,
13 'receive_date' => '2012-01-01',
14 'total_amount' => '100',
15 'financial_type_id' => 1,
16 'payment_instrument_id' => 1,
17 'non_deductible_amount' => '10',
18 'fee_amount' => '50',
19 'net_amount' => '90',
20 'trxn_id' => 12345,
21 'invoice_id' => 67890,
22 'source' => 'SSF',
23 'contribution_status_id' => 1,
24 'note' => 'my contribution note',
25 ];
26
27 try{
28 $result = civicrm_api3('Contribution', 'create', $params);
29 }
30 catch (CiviCRM_API3_Exception $e) {
31 // Handle error here.
32 $errorMessage = $e->getMessage();
33 $errorCode = $e->getErrorCode();
34 $errorData = $e->getExtraParams();
35 return [
36 'is_error' => 1,
37 'error_message' => $errorMessage,
38 'error_code' => $errorCode,
39 'error_data' => $errorData,
40 ];
41 }
42
43 return $result;
44 }
45
46 /**
47 * Function returns array of result expected from previous function.
48 *
49 * @return array
50 * API result array
51 */
52 function contribution_create_expectedresult() {
53
54 $expectedResult = [
55 'is_error' => 0,
56 'version' => 3,
57 'count' => 1,
58 'id' => 1,
59 'values' => [
60 '1' => [
61 'id' => '1',
62 'contact_id' => '25',
63 'financial_type_id' => '1',
64 'contribution_page_id' => '',
65 'payment_instrument_id' => '1',
66 'receive_date' => '20120101000000',
67 'non_deductible_amount' => '10',
68 'total_amount' => '100',
69 'fee_amount' => '50',
70 'net_amount' => '90',
71 'trxn_id' => '12345',
72 'invoice_id' => '67890',
73 'invoice_number' => '',
74 'currency' => 'USD',
75 'cancel_date' => '',
76 'cancel_reason' => '',
77 'receipt_date' => '',
78 'thankyou_date' => '',
79 'source' => 'SSF',
80 'amount_level' => '',
81 'contribution_recur_id' => '',
82 'is_test' => '',
83 'is_pay_later' => '',
84 'contribution_status_id' => '1',
85 'address_id' => '',
86 'check_number' => '',
87 'campaign_id' => '',
88 'creditnote_id' => '',
89 'tax_amount' => '',
90 'revenue_recognition_date' => '',
91 'contribution_type_id' => '1',
92 ],
93 ],
94 ];
95
96 return $expectedResult;
97 }
98
99 /*
100 * This example has been generated from the API test suite.
101 * The test that created it is called "testCreateContributionWithNote"
102 * and can be found at:
103 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
104 *
105 * You can see the outcome of the API tests at
106 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
107 *
108 * To Learn about the API read
109 * https://docs.civicrm.org/dev/en/latest/api/
110 *
111 * Browse the API on your own site with the API Explorer. It is in the main
112 * CiviCRM menu, under: Support > Development > API Explorer.
113 *
114 * Read more about testing here
115 * https://docs.civicrm.org/dev/en/latest/testing/
116 *
117 * API Standards documentation:
118 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
119 */