3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Class contains api test cases for "civicrm_payment_processor"
17 class api_v3_PaymentProcessorTest
extends CiviUnitTestCase
{
18 protected $_paymentProcessorType;
24 * @throws \CRM_Core_Exception
26 public function setUp() {
28 $this->useTransaction(TRUE);
29 // Create dummy processor
31 'name' => 'API_Test_PP_Type',
32 'title' => 'API Test Payment Processor Type',
33 'class_name' => 'CRM_Core_Payment_APITest',
34 'billing_mode' => 'form',
36 'payment_instrument_id' => 2,
38 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
39 $this->_paymentProcessorType
= $result['id'];
41 'name' => 'API Test PP',
42 'payment_processor_type_id' => $this->_paymentProcessorType
,
43 'class_name' => 'CRM_Core_Payment_APITest',
50 * Check create with no name specified.
51 * @dataProvider versionThreeAndFour
53 public function testPaymentProcessorCreateWithoutName($version) {
54 $this->_apiversion
= $version;
55 $this->callAPIFailure('payment_processor', 'create', ['is_active' => 1]);
59 * Create payment processor.
60 * @dataProvider versionThreeAndFour
62 * @throws \CRM_Core_Exception
64 public function testPaymentProcessorCreate($version) {
65 $this->_apiversion
= $version;
66 $params = $this->_params
;
67 $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__
, __FILE__
);
68 $this->callAPISuccessGetSingle('EntityFinancialAccount', ['entity_table' => 'civicrm_payment_processor', 'entity_id' => $result['id']]);
70 // Test that the option values are flushed so ths can be used straight away.
71 $this->callAPISuccess('ContributionRecur', 'create', [
72 'contact_id' => $this->individualCreate(),
74 'financial_type_id' => 'Donation',
75 'payment_processor_id' => 'API Test PP',
76 'frequency_interval' => 1,
78 $this->getAndCheck($params, $result['id'], 'PaymentProcessor');
79 $this->assertEquals(2, $result['values'][$result['id']]['payment_instrument_id']);
83 * Update payment processor.
84 * @dataProvider versionThreeAndFour
86 * @throws \CRM_Core_Exception
88 public function testPaymentProcessorUpdate($version) {
89 $this->_apiversion
= $version;
90 $params = $this->_params
;
91 $params['payment_instrument_id'] = 1;
92 $result = $this->callAPISuccess('payment_processor', 'create', $params);
93 $this->assertNotNull($result['id']);
96 'id' => $result['id'],
97 'name' => 'Update API Test',
99 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
100 $this->callAPISuccess('payment_processor', 'create', $updateParams);
101 $result = $this->callAPISuccess('payment_processor', 'get', ['id' => $result['id']]);
104 'id' => $result['id'],
105 'domain_id' => $params['domain_id'],
106 'name' => $updateParams['name'],
107 'payment_processor_type_id' => $params['payment_processor_type_id'],
110 'class_name' => $params['class_name'],
112 'is_recur' => $params['is_recur'],
114 'payment_instrument_id' => 1,
117 if ($version === 4) {
118 // In APIv3 If a field is default NULL it is not returned.
119 foreach ($result['values'][$result['id']] as $field => $value) {
120 if (is_null($value)) {
121 unset($result['values'][$result['id']][$field]);
125 $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]);
129 * Test using example code.
131 public function testPaymentProcessorCreateExample() {
132 require_once 'api/v3/examples/PaymentProcessor/Create.ex.php';
133 $result = payment_processor_create_example();
134 $expectedResult = payment_processor_create_expectedresult();
135 $this->assertAPISuccess($result);
139 * Check payment processor delete.
140 * @dataProvider versionThreeAndFour
142 * @throws \CRM_Core_Exception
144 public function testPaymentProcessorDelete($version) {
145 $this->_apiversion
= $version;
146 $result = $this->callAPISuccess('payment_processor', 'create', $this->_params
);
148 'id' => $result['id'],
151 $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__
, __FILE__
);
155 * Check with valid params array.
156 * @dataProvider versionThreeAndFour
158 * @throws \CRM_Core_Exception
160 public function testPaymentProcessorsGet($version) {
161 $this->_apiversion
= $version;
162 $params = $this->_params
;
163 $params['user_name'] = 'test@test.com';
164 $this->callAPISuccess('payment_processor', 'create', $params);
167 'user_name' => 'test@test.com',
169 $results = $this->callAPISuccess('payment_processor', 'get', $params);
171 $this->assertEquals(1, $results['count']);
172 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']);