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