Ian province abbreviation patch - issue 724
[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' => 19,
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' => 20,
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 'error' => $errorMessage,
40 'error_code' => $errorCode,
41 'error_data' => $errorData,
42 );
43 }
44
45 return $result;
46 }
47
48 /**
49 * Function returns array of result expected from previous function.
50 *
51 * @return array
52 * API result array
53 */
54 function contribution_create_expectedresult() {
55
56 $expectedResult = array(
57 'is_error' => 0,
58 'version' => 3,
59 'count' => 1,
60 'id' => 1,
61 'values' => array(
62 '1' => array(
63 'id' => '1',
64 'contact_id' => '19',
65 'financial_type_id' => '1',
66 'contribution_page_id' => '',
67 'payment_instrument_id' => '4',
68 'receive_date' => '20120511000000',
69 'non_deductible_amount' => '10',
70 'total_amount' => '100',
71 'fee_amount' => '5',
72 'net_amount' => '95',
73 'trxn_id' => '',
74 'invoice_id' => '',
75 'currency' => 'USD',
76 'cancel_date' => '',
77 'cancel_reason' => '',
78 'receipt_date' => '',
79 'thankyou_date' => '',
80 'source' => 'SSF',
81 'amount_level' => '',
82 'contribution_recur_id' => '',
83 'is_test' => '',
84 'is_pay_later' => '',
85 'contribution_status_id' => '1',
86 'address_id' => '',
87 'check_number' => '',
88 'campaign_id' => '',
89 'creditnote_id' => '',
90 'tax_amount' => '',
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 "testCreateContributionWithSoftCredit"
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-master-git/
107 *
108 * To Learn about the API read
109 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
110 *
111 * Browse the api on your own site with the api explorer
112 * http://MYSITE.ORG/path/to/civicrm/api
113 *
114 * Read more about testing here
115 * http://wiki.civicrm.org/confluence/display/CRM/Testing
116 *
117 * API Standards documentation:
118 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
119 */