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