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