3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class contains api test cases for "civicrm_payment_processor"
33 class api_v3_PaymentProcessorTest
extends CiviUnitTestCase
{
34 protected $_paymentProcessorType;
35 protected $_apiversion = 3;
41 * @throws \CRM_Core_Exception
43 public function setUp() {
45 $this->useTransaction(TRUE);
46 // Create dummy processor
48 'name' => 'API_Test_PP_Type',
49 'title' => 'API Test Payment Processor Type',
50 'class_name' => 'CRM_Core_Payment_APITest',
51 'billing_mode' => 'form',
54 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
55 $this->_paymentProcessorType
= $result['id'];
57 'name' => 'API Test PP',
58 'payment_processor_type_id' => $this->_paymentProcessorType
,
59 'class_name' => 'CRM_Core_Payment_APITest',
68 public function testPaymentProcessorCreateWithoutName() {
72 $this->callAPIFailure('payment_processor', 'create', $payProcParams);
76 * Create payment processor.
80 public function testPaymentProcessorCreate() {
81 $params = $this->_params
;
82 $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__
, __FILE__
);
83 $this->callAPISuccessGetSingle('EntityFinancialAccount', ['entity_table' => 'civicrm_payment_processor', 'entity_id' => $result['id']]);
85 // Test that the option values are flushed so ths can be used straight away.
86 $this->callAPISuccess('ContributionRecur', 'create', [
87 'contact_id' => $this->individualCreate(),
89 'financial_type_id' => 'Donation',
90 'payment_processor_id' => 'API Test PP',
91 'frequency_interval' => 1,
93 $this->getAndCheck($params, $result['id'], 'PaymentProcessor');
97 * Update payment processor.
99 * @throws \CRM_Core_Exception
101 public function testPaymentProcessorUpdate() {
102 $params = $this->_params
;
103 $result = $this->callAPISuccess('payment_processor', 'create', $params);
104 $this->assertNotNull($result['id']);
107 'id' => $result['id'],
108 'name' => 'Update API Test',
110 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
111 $this->callAPISuccess('payment_processor', 'create', $updateParams);
112 $result = $this->callAPISuccess('payment_processor', 'get', ['id' => $result['id']]);
115 'id' => $result['id'],
116 'domain_id' => $params['domain_id'],
117 'name' => $updateParams['name'],
118 'payment_processor_type_id' => $params['payment_processor_type_id'],
121 'class_name' => $params['class_name'],
123 'is_recur' => $params['is_recur'],
125 'payment_instrument_id' => 1,
128 $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]);
132 * Test using example code.
134 public function testPaymentProcessorCreateExample() {
135 require_once 'api/v3/examples/PaymentProcessor/Create.ex.php';
136 $result = payment_processor_create_example();
137 $expectedResult = payment_processor_create_expectedresult();
138 $this->assertAPISuccess($result);
142 * Check payment processor delete.
144 * @throws \CRM_Core_Exception
146 public function testPaymentProcessorDelete() {
147 $result = $this->callAPISuccess('payment_processor', 'create', $this->_params
);
149 'id' => $result['id'],
152 $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__
, __FILE__
);
156 * Check with valid params array.
158 * @throws \CRM_Core_Exception
160 public function testPaymentProcessorsGet() {
161 $params = $this->_params
;
162 $params['user_name'] = 'test@test.com';
163 $this->callAPISuccess('payment_processor', 'create', $params);
166 'user_name' => 'test@test.com',
168 $results = $this->callAPISuccess('payment_processor', 'get', $params);
170 $this->assertEquals(1, $results['count']);
171 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']);
175 * Test the processor passed to the hook can access the relevant variables.
177 * @throws \CRM_Core_Exception
178 * @throws \CiviCRM_API3_Exception
180 public function testPaymentProcessorPay() {
181 $this->hookClass
->setHook('civicrm_alterPaymentProcessorParams', [$this, 'hook_civicrm_alterPaymentProcessorParams']);
182 $processor = $this->dummyProcessorCreate();
183 $this->callAPISuccess('PaymentProcessor', 'pay', [
184 'payment_processor_id' => $processor->getID(),
185 'contribution_id' => 10,
187 'contribution_recur_id' => 3,
193 * Implements civicrm_alterPaymentProcessorParams hook.
195 * @param \CRM_Core_Payment_Dummy $paymentObject
197 public function hook_civicrm_alterPaymentProcessorParams($paymentObject) {
198 $this->assertEquals(10, $paymentObject->getContributionID());
199 $this->assertEquals(2, $paymentObject->getInvoiceID());
200 $this->assertEquals(3, $paymentObject->getContributionRecurID());