Commit | Line | Data |
---|---|---|
21150aae | 1 | <?php |
21150aae CW |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
21150aae | 5 | | | |
7d61e75f TO |
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 | | |
21150aae | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
21150aae | 11 | |
21150aae CW |
12 | /** |
13 | * Class contains api test cases for "civicrm_payment_processor" | |
14 | * | |
acb109b7 | 15 | * @group headless |
21150aae CW |
16 | */ |
17 | class api_v3_PaymentProcessorTest extends CiviUnitTestCase { | |
18 | protected $_paymentProcessorType; | |
21150aae | 19 | protected $_params; |
b7c9bc4c | 20 | |
3209a807 | 21 | /** |
22 | * Set up class. | |
23 | * | |
24 | * @throws \CRM_Core_Exception | |
25 | */ | |
00be9182 | 26 | public function setUp() { |
21150aae | 27 | parent::setUp(); |
208f71f0 | 28 | $this->useTransaction(TRUE); |
21150aae | 29 | // Create dummy processor |
9099cab3 | 30 | $params = [ |
21150aae CW |
31 | 'name' => 'API_Test_PP_Type', |
32 | 'title' => 'API Test Payment Processor Type', | |
33 | 'class_name' => 'CRM_Core_Payment_APITest', | |
34 | 'billing_mode' => 'form', | |
35 | 'is_recur' => 0, | |
9099cab3 | 36 | ]; |
fa7b9efb | 37 | $result = $this->callAPISuccess('payment_processor_type', 'create', $params); |
21150aae | 38 | $this->_paymentProcessorType = $result['id']; |
9099cab3 | 39 | $this->_params = [ |
21150aae CW |
40 | 'name' => 'API Test PP', |
41 | 'payment_processor_type_id' => $this->_paymentProcessorType, | |
42 | 'class_name' => 'CRM_Core_Payment_APITest', | |
43 | 'is_recur' => 0, | |
44 | 'domain_id' => 1, | |
9099cab3 | 45 | ]; |
21150aae CW |
46 | } |
47 | ||
21150aae | 48 | /** |
3209a807 | 49 | * Check create with no name specified. |
21150aae | 50 | */ |
00be9182 | 51 | public function testPaymentProcessorCreateWithoutName() { |
3209a807 | 52 | $this->callAPIFailure('payment_processor', 'create', ['is_active' => 1]); |
21150aae CW |
53 | } |
54 | ||
55 | /** | |
eceb18cc | 56 | * Create payment processor. |
3209a807 | 57 | * |
58 | * @throws \CRM_Core_Exception | |
21150aae | 59 | */ |
00be9182 | 60 | public function testPaymentProcessorCreate() { |
21150aae | 61 | $params = $this->_params; |
fa7b9efb | 62 | $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__); |
8563c1ce | 63 | $this->callAPISuccessGetSingle('EntityFinancialAccount', ['entity_table' => 'civicrm_payment_processor', 'entity_id' => $result['id']]); |
576c8a85 | 64 | |
65 | // Test that the option values are flushed so ths can be used straight away. | |
66 | $this->callAPISuccess('ContributionRecur', 'create', [ | |
67 | 'contact_id' => $this->individualCreate(), | |
68 | 'amount' => 5, | |
69 | 'financial_type_id' => 'Donation', | |
70 | 'payment_processor_id' => 'API Test PP', | |
71 | 'frequency_interval' => 1, | |
72 | ]); | |
8563c1ce | 73 | $this->getAndCheck($params, $result['id'], 'PaymentProcessor'); |
21150aae CW |
74 | } |
75 | ||
29dd4ada JP |
76 | /** |
77 | * Update payment processor. | |
3209a807 | 78 | * |
79 | * @throws \CRM_Core_Exception | |
29dd4ada JP |
80 | */ |
81 | public function testPaymentProcessorUpdate() { | |
82 | $params = $this->_params; | |
83 | $result = $this->callAPISuccess('payment_processor', 'create', $params); | |
84 | $this->assertNotNull($result['id']); | |
85 | ||
9099cab3 | 86 | $updateParams = [ |
29dd4ada JP |
87 | 'id' => $result['id'], |
88 | 'name' => 'Update API Test', | |
9099cab3 | 89 | ]; |
29dd4ada JP |
90 | $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params); |
91 | $this->callAPISuccess('payment_processor', 'create', $updateParams); | |
9099cab3 | 92 | $result = $this->callAPISuccess('payment_processor', 'get', ['id' => $result['id']]); |
29dd4ada | 93 | |
9099cab3 | 94 | $expectedResult = [ |
29dd4ada JP |
95 | 'id' => $result['id'], |
96 | 'domain_id' => $params['domain_id'], | |
97 | 'name' => $updateParams['name'], | |
98 | 'payment_processor_type_id' => $params['payment_processor_type_id'], | |
99 | 'is_default' => 0, | |
100 | 'is_test' => 0, | |
101 | 'class_name' => $params['class_name'], | |
102 | 'billing_mode' => 1, | |
103 | 'is_recur' => $params['is_recur'], | |
104 | 'payment_type' => 1, | |
105 | 'payment_instrument_id' => 1, | |
29adc103 | 106 | 'is_active' => 1, |
9099cab3 | 107 | ]; |
29dd4ada JP |
108 | $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]); |
109 | } | |
110 | ||
21150aae | 111 | /** |
eceb18cc | 112 | * Test using example code. |
21150aae | 113 | */ |
00be9182 | 114 | public function testPaymentProcessorCreateExample() { |
be44cfcb | 115 | require_once 'api/v3/examples/PaymentProcessor/Create.ex.php'; |
21150aae CW |
116 | $result = payment_processor_create_example(); |
117 | $expectedResult = payment_processor_create_expectedresult(); | |
791c263c | 118 | $this->assertAPISuccess($result); |
21150aae CW |
119 | } |
120 | ||
21150aae | 121 | /** |
eceb18cc | 122 | * Check payment processor delete. |
3209a807 | 123 | * |
124 | * @throws \CRM_Core_Exception | |
21150aae | 125 | */ |
00be9182 | 126 | public function testPaymentProcessorDelete() { |
8563c1ce | 127 | $result = $this->callAPISuccess('payment_processor', 'create', $this->_params); |
9099cab3 | 128 | $params = [ |
8563c1ce | 129 | 'id' => $result['id'], |
9099cab3 | 130 | ]; |
21150aae | 131 | |
3c27d467 | 132 | $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__); |
21150aae CW |
133 | } |
134 | ||
21150aae | 135 | /** |
100fef9d | 136 | * Check with valid params array. |
3209a807 | 137 | * |
138 | * @throws \CRM_Core_Exception | |
21150aae | 139 | */ |
00be9182 | 140 | public function testPaymentProcessorsGet() { |
21150aae CW |
141 | $params = $this->_params; |
142 | $params['user_name'] = 'test@test.com'; | |
fa7b9efb | 143 | $this->callAPISuccess('payment_processor', 'create', $params); |
21150aae | 144 | |
9099cab3 | 145 | $params = [ |
21150aae | 146 | 'user_name' => 'test@test.com', |
9099cab3 | 147 | ]; |
fa7b9efb | 148 | $results = $this->callAPISuccess('payment_processor', 'get', $params); |
21150aae | 149 | |
3c27d467 | 150 | $this->assertEquals(1, $results['count']); |
151 | $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']); | |
21150aae | 152 | } |
96025800 | 153 | |
21150aae | 154 | } |