Update Test generated examples
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithSoftCredit.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 = array(
12 'contact_id' => 24,
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' => array(
22 '1' => array(
23 'contact_id' => 25,
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 array(
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 = array(
58 'is_error' => 0,
59 'version' => 3,
60 'count' => 1,
61 'id' => 1,
62 'values' => array(
63 '1' => array(
64 'id' => '1',
65 'contact_id' => '24',
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 'currency' => 'USD',
77 'cancel_date' => '',
78 'cancel_reason' => '',
79 'receipt_date' => '',
80 'thankyou_date' => '',
81 'source' => 'SSF',
82 'amount_level' => '',
83 'contribution_recur_id' => '',
84 'is_test' => '',
85 'is_pay_later' => '',
86 'contribution_status_id' => '1',
87 'address_id' => '',
88 'check_number' => '',
89 'campaign_id' => '',
90 'creditnote_id' => '',
91 'tax_amount' => '',
92 'revenue_recognition_date' => '',
93 'contribution_type_id' => '1',
94 ),
95 ),
96 );
97
98 return $expectedResult;
99 }
100
101 /*
102 * This example has been generated from the API test suite.
103 * The test that created it is called "testCreateContributionWithSoftCredit"
104 * and can be found at:
105 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
106 *
107 * You can see the outcome of the API tests at
108 * https://test.civicrm.org/job/CiviCRM-master-git/
109 *
110 * To Learn about the API read
111 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
112 *
113 * Browse the api on your own site with the api explorer
114 * http://MYSITE.ORG/path/to/civicrm/api
115 *
116 * Read more about testing here
117 * http://wiki.civicrm.org/confluence/display/CRM/Testing
118 *
119 * API Standards documentation:
120 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
121 */