CRM-15988 - Update generated examples
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithNote.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 = array(
12 'contact_id' => 17,
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 array(
36 'error' => $errorMessage,
37 'error_code' => $errorCode,
38 'error_data' => $errorData,
39 );
40 }
41
42 return $result;
43 }
44
45 /**
46 * Function returns array of result expected from previous function.
47 *
48 * @return array
49 * API result array
50 */
51 function contribution_create_expectedresult() {
52
53 $expectedResult = array(
54 'is_error' => 0,
55 'version' => 3,
56 'count' => 1,
57 'id' => 1,
58 'values' => array(
59 '1' => array(
60 'id' => '1',
61 'contact_id' => '17',
62 'financial_type_id' => '1',
63 'contribution_page_id' => '',
64 'payment_instrument_id' => '1',
65 'receive_date' => '20120101000000',
66 'non_deductible_amount' => '10',
67 'total_amount' => '100',
68 'fee_amount' => '50',
69 'net_amount' => '90',
70 'trxn_id' => '12345',
71 'invoice_id' => '67890',
72 'currency' => 'USD',
73 'cancel_date' => '',
74 'cancel_reason' => '',
75 'receipt_date' => '',
76 'thankyou_date' => '',
77 'source' => 'SSF',
78 'amount_level' => '',
79 'contribution_recur_id' => '',
80 'is_test' => '',
81 'is_pay_later' => '',
82 'contribution_status_id' => '1',
83 'address_id' => '',
84 'check_number' => '',
85 'campaign_id' => '',
86 'creditnote_id' => '',
87 'tax_amount' => '',
88 'contribution_type_id' => '1',
89 ),
90 ),
91 );
92
93 return $expectedResult;
94 }
95
96 /*
97 * This example has been generated from the API test suite.
98 * The test that created it is called "testCreateContributionWithNote"
99 * and can be found at:
100 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
101 *
102 * You can see the outcome of the API tests at
103 * https://test.civicrm.org/job/CiviCRM-master-git/
104 *
105 * To Learn about the API read
106 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
107 *
108 * Browse the api on your own site with the api explorer
109 * http://MYSITE.ORG/path/to/civicrm/api
110 *
111 * Read more about testing here
112 * http://wiki.civicrm.org/confluence/display/CRM/Testing
113 *
114 * API Standards documentation:
115 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
116 */