Merge pull request #14974 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTest.php
CommitLineData
21150aae 1<?php
21150aae
CW
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
21150aae 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
21150aae
CW
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
21150aae 27
21150aae
CW
28/**
29 * Class contains api test cases for "civicrm_payment_processor"
30 *
acb109b7 31 * @group headless
21150aae
CW
32 */
33class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
34 protected $_paymentProcessorType;
fa7b9efb 35 protected $_apiversion = 3;
21150aae 36 protected $_params;
b7c9bc4c 37
00be9182 38 public function setUp() {
21150aae 39 parent::setUp();
208f71f0 40 $this->useTransaction(TRUE);
21150aae 41 // Create dummy processor
9099cab3 42 $params = [
21150aae
CW
43 'name' => 'API_Test_PP_Type',
44 'title' => 'API Test Payment Processor Type',
45 'class_name' => 'CRM_Core_Payment_APITest',
46 'billing_mode' => 'form',
47 'is_recur' => 0,
9099cab3 48 ];
fa7b9efb 49 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
21150aae 50 $this->_paymentProcessorType = $result['id'];
9099cab3 51 $this->_params = [
21150aae
CW
52 'name' => 'API Test PP',
53 'payment_processor_type_id' => $this->_paymentProcessorType,
54 'class_name' => 'CRM_Core_Payment_APITest',
55 'is_recur' => 0,
56 'domain_id' => 1,
9099cab3 57 ];
21150aae
CW
58 }
59
21150aae 60 /**
eceb18cc 61 * Check with no name.
21150aae 62 */
00be9182 63 public function testPaymentProcessorCreateWithoutName() {
9099cab3 64 $payProcParams = [
21150aae 65 'is_active' => 1,
9099cab3 66 ];
3c27d467 67 $this->callAPIFailure('payment_processor', 'create', $payProcParams);
21150aae
CW
68 }
69
70 /**
eceb18cc 71 * Create payment processor.
21150aae 72 */
00be9182 73 public function testPaymentProcessorCreate() {
21150aae 74 $params = $this->_params;
fa7b9efb 75 $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__);
8563c1ce 76 $this->callAPISuccessGetSingle('EntityFinancialAccount', ['entity_table' => 'civicrm_payment_processor', 'entity_id' => $result['id']]);
576c8a85 77
78 // Test that the option values are flushed so ths can be used straight away.
79 $this->callAPISuccess('ContributionRecur', 'create', [
80 'contact_id' => $this->individualCreate(),
81 'amount' => 5,
82 'financial_type_id' => 'Donation',
83 'payment_processor_id' => 'API Test PP',
84 'frequency_interval' => 1,
85 ]);
8563c1ce 86 $this->getAndCheck($params, $result['id'], 'PaymentProcessor');
21150aae
CW
87 }
88
29dd4ada
JP
89 /**
90 * Update payment processor.
91 */
92 public function testPaymentProcessorUpdate() {
93 $params = $this->_params;
94 $result = $this->callAPISuccess('payment_processor', 'create', $params);
95 $this->assertNotNull($result['id']);
96
9099cab3 97 $updateParams = [
29dd4ada
JP
98 'id' => $result['id'],
99 'name' => 'Update API Test',
9099cab3 100 ];
29dd4ada
JP
101 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
102 $this->callAPISuccess('payment_processor', 'create', $updateParams);
9099cab3 103 $result = $this->callAPISuccess('payment_processor', 'get', ['id' => $result['id']]);
29dd4ada 104
9099cab3 105 $expectedResult = [
29dd4ada
JP
106 'id' => $result['id'],
107 'domain_id' => $params['domain_id'],
108 'name' => $updateParams['name'],
109 'payment_processor_type_id' => $params['payment_processor_type_id'],
110 'is_default' => 0,
111 'is_test' => 0,
112 'class_name' => $params['class_name'],
113 'billing_mode' => 1,
114 'is_recur' => $params['is_recur'],
115 'payment_type' => 1,
116 'payment_instrument_id' => 1,
29adc103 117 'is_active' => 1,
9099cab3 118 ];
29dd4ada
JP
119 $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]);
120 }
121
21150aae 122 /**
eceb18cc 123 * Test using example code.
21150aae 124 */
00be9182 125 public function testPaymentProcessorCreateExample() {
3ec6e38d 126 require_once 'api/v3/examples/PaymentProcessor/Create.php';
21150aae
CW
127 $result = payment_processor_create_example();
128 $expectedResult = payment_processor_create_expectedresult();
791c263c 129 $this->assertAPISuccess($result);
21150aae
CW
130 }
131
21150aae 132 /**
eceb18cc 133 * Check payment processor delete.
21150aae 134 */
00be9182 135 public function testPaymentProcessorDelete() {
8563c1ce 136 $result = $this->callAPISuccess('payment_processor', 'create', $this->_params);
9099cab3 137 $params = [
8563c1ce 138 'id' => $result['id'],
9099cab3 139 ];
21150aae 140
3c27d467 141 $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__);
21150aae
CW
142 }
143
21150aae 144 /**
100fef9d 145 * Check with valid params array.
21150aae 146 */
00be9182 147 public function testPaymentProcessorsGet() {
21150aae
CW
148 $params = $this->_params;
149 $params['user_name'] = 'test@test.com';
fa7b9efb 150 $this->callAPISuccess('payment_processor', 'create', $params);
21150aae 151
9099cab3 152 $params = [
21150aae 153 'user_name' => 'test@test.com',
9099cab3 154 ];
fa7b9efb 155 $results = $this->callAPISuccess('payment_processor', 'get', $params);
21150aae 156
3c27d467 157 $this->assertEquals(1, $results['count']);
158 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']);
21150aae 159 }
96025800 160
21150aae 161}