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;
19 protected $_apiversion = 3;
22 public function setUp() {
24 $this->useTransaction(TRUE);
25 // Create dummy processor
27 'name' => 'API_Test_PP_Type',
28 'title' => 'API Test Payment Processor Type',
29 'class_name' => 'CRM_Core_Payment_APITest',
30 'billing_mode' => 'form',
33 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
34 $this->_paymentProcessorType
= $result['id'];
36 'name' => 'API Test PP',
37 'payment_processor_type_id' => $this->_paymentProcessorType
,
38 'class_name' => 'CRM_Core_Payment_APITest',
47 public function testPaymentProcessorCreateWithoutName() {
51 $this->callAPIFailure('payment_processor', 'create', $payProcParams);
55 * Create payment processor.
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']]);
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(),
66 'financial_type_id' => 'Donation',
67 'payment_processor_id' => 'API Test PP',
68 'frequency_interval' => 1,
70 $this->getAndCheck($params, $result['id'], 'PaymentProcessor');
74 * Update payment processor.
76 public function testPaymentProcessorUpdate() {
77 $params = $this->_params
;
78 $result = $this->callAPISuccess('payment_processor', 'create', $params);
79 $this->assertNotNull($result['id']);
82 'id' => $result['id'],
83 'name' => 'Update API Test',
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']]);
90 'id' => $result['id'],
91 'domain_id' => $params['domain_id'],
92 'name' => $updateParams['name'],
93 'payment_processor_type_id' => $params['payment_processor_type_id'],
96 'class_name' => $params['class_name'],
98 'is_recur' => $params['is_recur'],
100 'payment_instrument_id' => 1,
103 $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]);
107 * Test using example code.
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);
117 * Check payment processor delete.
119 public function testPaymentProcessorDelete() {
120 $result = $this->callAPISuccess('payment_processor', 'create', $this->_params
);
122 'id' => $result['id'],
125 $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__
, __FILE__
);
129 * Check with valid params array.
131 public function testPaymentProcessorsGet() {
132 $params = $this->_params
;
133 $params['user_name'] = 'test@test.com';
134 $this->callAPISuccess('payment_processor', 'create', $params);
137 'user_name' => 'test@test.com',
139 $results = $this->callAPISuccess('payment_processor', 'get', $params);
141 $this->assertEquals(1, $results['count']);
142 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']);