Merge pull request #15840 from yashodha/participant_edit
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class contains api test cases for "civicrm_payment_processor"
14 *
15 * @group headless
16 */
17 class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
18 protected $_paymentProcessorType;
19 protected $_apiversion = 3;
20 protected $_params;
21
22 public function setUp() {
23 parent::setUp();
24 $this->useTransaction(TRUE);
25 // Create dummy processor
26 $params = [
27 'name' => 'API_Test_PP_Type',
28 'title' => 'API Test Payment Processor Type',
29 'class_name' => 'CRM_Core_Payment_APITest',
30 'billing_mode' => 'form',
31 'is_recur' => 0,
32 ];
33 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
34 $this->_paymentProcessorType = $result['id'];
35 $this->_params = [
36 'name' => 'API Test PP',
37 'payment_processor_type_id' => $this->_paymentProcessorType,
38 'class_name' => 'CRM_Core_Payment_APITest',
39 'is_recur' => 0,
40 'domain_id' => 1,
41 ];
42 }
43
44 /**
45 * Check with no name.
46 */
47 public function testPaymentProcessorCreateWithoutName() {
48 $payProcParams = [
49 'is_active' => 1,
50 ];
51 $this->callAPIFailure('payment_processor', 'create', $payProcParams);
52 }
53
54 /**
55 * Create payment processor.
56 */
57 public function testPaymentProcessorCreate() {
58 $params = $this->_params;
59 $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__);
60 $this->callAPISuccessGetSingle('EntityFinancialAccount', ['entity_table' => 'civicrm_payment_processor', 'entity_id' => $result['id']]);
61
62 // Test that the option values are flushed so ths can be used straight away.
63 $this->callAPISuccess('ContributionRecur', 'create', [
64 'contact_id' => $this->individualCreate(),
65 'amount' => 5,
66 'financial_type_id' => 'Donation',
67 'payment_processor_id' => 'API Test PP',
68 'frequency_interval' => 1,
69 ]);
70 $this->getAndCheck($params, $result['id'], 'PaymentProcessor');
71 }
72
73 /**
74 * Update payment processor.
75 */
76 public function testPaymentProcessorUpdate() {
77 $params = $this->_params;
78 $result = $this->callAPISuccess('payment_processor', 'create', $params);
79 $this->assertNotNull($result['id']);
80
81 $updateParams = [
82 'id' => $result['id'],
83 'name' => 'Update API Test',
84 ];
85 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
86 $this->callAPISuccess('payment_processor', 'create', $updateParams);
87 $result = $this->callAPISuccess('payment_processor', 'get', ['id' => $result['id']]);
88
89 $expectedResult = [
90 'id' => $result['id'],
91 'domain_id' => $params['domain_id'],
92 'name' => $updateParams['name'],
93 'payment_processor_type_id' => $params['payment_processor_type_id'],
94 'is_default' => 0,
95 'is_test' => 0,
96 'class_name' => $params['class_name'],
97 'billing_mode' => 1,
98 'is_recur' => $params['is_recur'],
99 'payment_type' => 1,
100 'payment_instrument_id' => 1,
101 'is_active' => 1,
102 ];
103 $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]);
104 }
105
106 /**
107 * Test using example code.
108 */
109 public function testPaymentProcessorCreateExample() {
110 require_once 'api/v3/examples/PaymentProcessor/Create.ex.php';
111 $result = payment_processor_create_example();
112 $expectedResult = payment_processor_create_expectedresult();
113 $this->assertAPISuccess($result);
114 }
115
116 /**
117 * Check payment processor delete.
118 */
119 public function testPaymentProcessorDelete() {
120 $result = $this->callAPISuccess('payment_processor', 'create', $this->_params);
121 $params = [
122 'id' => $result['id'],
123 ];
124
125 $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__);
126 }
127
128 /**
129 * Check with valid params array.
130 */
131 public function testPaymentProcessorsGet() {
132 $params = $this->_params;
133 $params['user_name'] = 'test@test.com';
134 $this->callAPISuccess('payment_processor', 'create', $params);
135
136 $params = [
137 'user_name' => 'test@test.com',
138 ];
139 $results = $this->callAPISuccess('payment_processor', 'get', $params);
140
141 $this->assertEquals(1, $results['count']);
142 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']);
143 }
144
145 }