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