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