Commit | Line | Data |
---|---|---|
6094aad5 PN |
1 | <?php |
2 | /** | |
3 | * Test Generated example demonstrating the Payment.create API. | |
4 | * | |
5 | * Update Payment | |
6 | * | |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function payment_create_example() { | |
cf8f0fff | 11 | $params = [ |
6094aad5 PN |
12 | 'contribution_id' => 1, |
13 | 'total_amount' => 100, | |
14 | 'id' => 3, | |
15 | 'check_permissions' => TRUE, | |
cf8f0fff | 16 | ]; |
6094aad5 PN |
17 | |
18 | try{ | |
19 | $result = civicrm_api3('Payment', 'create', $params); | |
20 | } | |
21 | catch (CiviCRM_API3_Exception $e) { | |
22 | // Handle error here. | |
23 | $errorMessage = $e->getMessage(); | |
24 | $errorCode = $e->getErrorCode(); | |
25 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 26 | return [ |
1d8ee3d6 | 27 | 'is_error' => 1, |
28 | 'error_message' => $errorMessage, | |
6094aad5 PN |
29 | 'error_code' => $errorCode, |
30 | 'error_data' => $errorData, | |
cf8f0fff | 31 | ]; |
6094aad5 PN |
32 | } |
33 | ||
34 | return $result; | |
35 | } | |
36 | ||
37 | /** | |
38 | * Function returns array of result expected from previous function. | |
39 | * | |
40 | * @return array | |
41 | * API result array | |
42 | */ | |
43 | function payment_create_expectedresult() { | |
44 | ||
cf8f0fff | 45 | $expectedResult = [ |
6094aad5 PN |
46 | 'is_error' => 0, |
47 | 'version' => 3, | |
48 | 'count' => 1, | |
49 | 'id' => 5, | |
cf8f0fff CW |
50 | 'values' => [ |
51 | '5' => [ | |
6094aad5 PN |
52 | 'id' => '5', |
53 | 'from_financial_account_id' => '7', | |
54 | 'to_financial_account_id' => '6', | |
1d8ee3d6 | 55 | 'trxn_date' => '20170207024653', |
6094aad5 PN |
56 | 'total_amount' => '100', |
57 | 'fee_amount' => '', | |
58 | 'net_amount' => '100', | |
59 | 'currency' => 'USD', | |
60 | 'is_payment' => '1', | |
61 | 'trxn_id' => '', | |
62 | 'trxn_result_code' => '', | |
63 | 'status_id' => '1', | |
64 | 'payment_processor_id' => '', | |
cf8f0fff CW |
65 | ], |
66 | ], | |
67 | ]; | |
6094aad5 PN |
68 | |
69 | return $expectedResult; | |
70 | } | |
71 | ||
72 | /* | |
73 | * This example has been generated from the API test suite. | |
74 | * The test that created it is called "testUpdatePayment" | |
75 | * and can be found at: | |
76 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PaymentTest.php | |
77 | * | |
78 | * You can see the outcome of the API tests at | |
79 | * https://test.civicrm.org/job/CiviCRM-master-git/ | |
80 | * | |
81 | * To Learn about the API read | |
82 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API | |
83 | * | |
84 | * Browse the api on your own site with the api explorer | |
85 | * http://MYSITE.ORG/path/to/civicrm/api | |
86 | * | |
87 | * Read more about testing here | |
88 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
89 | * | |
90 | * API Standards documentation: | |
91 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
92 | */ |