1 | <?php |
||
2 | /** |
||
3 | * Gateway Test |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2022 Pronamic |
||
7 | * @license GPL-3.0-or-later |
||
8 | * @package Pronamic\WordPress\Pay\Gateways\Payvision |
||
9 | */ |
||
10 | |||
11 | namespace Pronamic\WordPress\Pay\Gateways\Payvision; |
||
12 | |||
13 | use Pronamic\WordPress\Http\Factory; |
||
14 | use Pronamic\WordPress\Money\Money; |
||
15 | use Pronamic\WordPress\Pay\Core\PaymentMethods; |
||
16 | use Pronamic\WordPress\Pay\Payments\Payment; |
||
17 | use Pronamic\WordPress\Pay\Payments\PaymentStatus; |
||
18 | |||
19 | /** |
||
20 | * Gateway Test |
||
21 | * |
||
22 | * @author Remco Tolsma |
||
23 | * @version 1.1.0 |
||
24 | * @since 1.0.0 |
||
25 | */ |
||
26 | class GatewayTest extends \WP_UnitTestCase { |
||
27 | /** |
||
28 | * Setup. |
||
29 | */ |
||
30 | public function setUp() { |
||
31 | parent::setUp(); |
||
32 | |||
33 | $this->factory = new Factory(); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Test gateway. |
||
38 | */ |
||
39 | public function test_gateway() { |
||
40 | $config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
||
41 | |||
42 | $gateway = new Gateway( $config ); |
||
43 | |||
44 | $this->assertTrue( $gateway->payment_method_is_required() ); |
||
45 | |||
46 | // iDEAL issuers. |
||
47 | $issuers = $gateway->get_issuers(); |
||
48 | |||
49 | $this->assertCount( 1, $issuers ); |
||
50 | |||
51 | // Payment methods. |
||
52 | $methods = $gateway->get_supported_payment_methods(); |
||
53 | |||
54 | $this->assertCount( 2, $methods ); |
||
55 | $this->assertContains( PaymentMethods::IDEAL, $methods ); |
||
56 | $this->assertContains( PaymentMethods::PAYPAL, $methods ); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Test get payment status. |
||
61 | */ |
||
62 | public function test_get_payment_status() { |
||
63 | $config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
||
64 | |||
65 | $gateway = new Gateway( $config ); |
||
66 | |||
67 | $this->factory->fake( |
||
68 | 'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4d', |
||
69 | __DIR__ . '/../http/get-payment-result-0.http' |
||
70 | ); |
||
71 | |||
72 | $payment = new Payment(); |
||
73 | |||
74 | $payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4d' ); |
||
75 | |||
76 | $gateway->update_status( $payment ); |
||
77 | |||
78 | $this->assertEquals( PaymentStatus::SUCCESS, $payment->get_status() ); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Test get payment status. |
||
83 | */ |
||
84 | public function test_get_payment_status_fake() { |
||
85 | $config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
||
86 | |||
87 | $gateway = new Gateway( $config ); |
||
88 | |||
89 | $this->factory->fake( |
||
90 | 'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4e', |
||
91 | __DIR__ . '/../http/get-payment-by-fake-id.http' |
||
92 | ); |
||
93 | |||
94 | $payment = new Payment(); |
||
95 | |||
96 | $payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
||
97 | |||
98 | $this->expectException( \Throwable::class ); |
||
99 | $this->expectExceptionMessage( |
||
100 | 'Could not JSON decode response, HTTP response: "404 Not Found", HTTP body length: "2", JSON error: "Syntax error".' |
||
101 | ); |
||
102 | |||
103 | $gateway->update_status( $payment ); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Test get payment empty body. |
||
108 | */ |
||
109 | public function test_get_payment_empty_body() { |
||
110 | $config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
||
111 | |||
112 | $gateway = new Gateway( $config ); |
||
113 | |||
114 | $this->factory->fake( |
||
115 | 'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4e', |
||
116 | __DIR__ . '/../http/get-payment-body-empty.http' |
||
117 | ); |
||
118 | |||
119 | $payment = new Payment(); |
||
120 | |||
121 | $payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
||
122 | |||
123 | $this->expectException( \Throwable::class ); |
||
124 | $this->expectExceptionMessage( 'Response is empty, HTTP response: "200 OK".' ); |
||
125 | |||
126 | $gateway->update_status( $payment ); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Test get payment no object. |
||
131 | */ |
||
132 | public function test_get_payment_no_object() { |
||
133 | $config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
||
134 | |||
135 | $gateway = new Gateway( $config ); |
||
136 | |||
137 | $this->factory->fake( |
||
138 | 'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4e', |
||
139 | __DIR__ . '/../http/get-payment-no-object.http' |
||
140 | ); |
||
141 | |||
142 | $payment = new Payment(); |
||
143 | |||
144 | $payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
||
145 | |||
146 | $this->expectException( \Throwable::class ); |
||
147 | $this->expectExceptionMessage( |
||
148 | 'Could not JSON decode Payvision response to an object, HTTP response: "200 OK", HTTP body: "[]".' |
||
149 | ); |
||
150 | |||
151 | $gateway->update_status( $payment ); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Test WordPress error. |
||
156 | */ |
||
157 | public function test_wp_error() { |
||
158 | $config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
||
159 | |||
160 | $gateway = new Gateway( $config ); |
||
161 | |||
162 | $filter = function() { |
||
163 | return new \WP_Error( 'http_request_failed', 'A valid URL was not provided.' ); |
||
164 | }; |
||
165 | |||
166 | \add_filter( 'pre_http_request', $filter ); |
||
167 | |||
168 | $payment = new Payment(); |
||
169 | |||
170 | $payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
||
171 | |||
172 | $this->expectException( \Throwable::class ); |
||
173 | $this->expectExceptionMessage( 'A valid URL was not provided.' ); |
||
174 | |||
175 | $gateway->update_status( $payment ); |
||
176 | |||
177 | \remove_filter( 'pre_http_request', $filter ); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Test post payment. |
||
182 | */ |
||
183 | public function test_post_payment() { |
||
184 | $config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
||
185 | |||
186 | $gateway = new Gateway( $config ); |
||
187 | |||
188 | $this->factory->fake( |
||
189 | 'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments', |
||
190 | __DIR__ . '/../http/post-payment.http' |
||
191 | ); |
||
192 | |||
193 | $payment = new Payment(); |
||
194 | |||
195 | $payment->set_id( 1 ); |
||
196 | |||
197 | $payment->set_total_amount( new Money( '50', 'EUR' ) ); |
||
198 | |||
199 | $gateway->start( $payment ); |
||
200 | |||
201 | $this->assertEquals( |
||
202 | 'https://test.acaptureservices.com/connectors/demo/ideal/simulator/paymentSimulation.ftl;jsessionid=5D94958C082AE32D58841306599361A5.uat01-vm-con02', |
||
203 | $payment->get_action_url() |
||
204 | ); |
||
205 | |||
206 | $this->assertEquals( '0c5b2580-45b9-440b-bef4-1ca016854afd', $payment->get_transaction_id() ); |
||
207 | } |
||
208 | } |
||
209 |