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