1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Gateway Test |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2021 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\TaxedMoney; |
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(); |
|
|
|
|
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( 1, $methods ); |
55
|
|
|
$this->assertContains( PaymentMethods::IDEAL, $methods ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Test get payment status. |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function test_get_payment_status() { |
|
|
|
|
62
|
|
|
$config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
63
|
|
|
|
64
|
|
|
$gateway = new Gateway( $config ); |
65
|
|
|
|
66
|
|
|
$this->factory->fake( |
67
|
|
|
'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4d', |
68
|
|
|
__DIR__ . '/../http/get-payment-result-0.http' |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$payment = new Payment(); |
72
|
|
|
|
73
|
|
|
$payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4d' ); |
74
|
|
|
|
75
|
|
|
$gateway->update_status( $payment ); |
76
|
|
|
|
77
|
|
|
$this->assertEquals( PaymentStatus::SUCCESS, $payment->get_status() ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Test get payment status. |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function test_get_payment_status_fake() { |
|
|
|
|
84
|
|
|
$config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
85
|
|
|
|
86
|
|
|
$gateway = new Gateway( $config ); |
87
|
|
|
|
88
|
|
|
$this->factory->fake( |
89
|
|
|
'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4e', |
90
|
|
|
__DIR__ . '/../http/get-payment-by-fake-id.http' |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$payment = new Payment(); |
94
|
|
|
|
95
|
|
|
$payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
96
|
|
|
|
97
|
|
|
$this->expectException( \Throwable::class ); |
98
|
|
|
$this->expectExceptionMessage( |
99
|
|
|
'Could not JSON decode response, HTTP response: "404 Not Found", HTTP body length: "2", JSON error: "Syntax error".' |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$gateway->update_status( $payment ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Test get payment empty body. |
107
|
|
|
*/ |
108
|
|
View Code Duplication |
public function test_get_payment_empty_body() { |
|
|
|
|
109
|
|
|
$config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
110
|
|
|
|
111
|
|
|
$gateway = new Gateway( $config ); |
112
|
|
|
|
113
|
|
|
$this->factory->fake( |
114
|
|
|
'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4e', |
115
|
|
|
__DIR__ . '/../http/get-payment-body-empty.http' |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$payment = new Payment(); |
119
|
|
|
|
120
|
|
|
$payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
121
|
|
|
|
122
|
|
|
$this->expectException( \Throwable::class ); |
123
|
|
|
$this->expectExceptionMessage( 'Response is empty, HTTP response: "200 OK".' ); |
124
|
|
|
|
125
|
|
|
$gateway->update_status( $payment ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Test get payment no object. |
130
|
|
|
*/ |
131
|
|
View Code Duplication |
public function test_get_payment_no_object() { |
|
|
|
|
132
|
|
|
$config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
133
|
|
|
|
134
|
|
|
$gateway = new Gateway( $config ); |
135
|
|
|
|
136
|
|
|
$this->factory->fake( |
137
|
|
|
'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/00a502ba-d289-4ee1-a43e-3c4e1de76b4e', |
138
|
|
|
__DIR__ . '/../http/get-payment-no-object.http' |
139
|
|
|
); |
140
|
|
|
|
141
|
|
|
$payment = new Payment(); |
142
|
|
|
|
143
|
|
|
$payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
144
|
|
|
|
145
|
|
|
$this->expectException( \Throwable::class ); |
146
|
|
|
$this->expectExceptionMessage( |
147
|
|
|
'Could not JSON decode Payvision response to an object, HTTP response: "200 OK", HTTP body: "[]".' |
148
|
|
|
); |
149
|
|
|
|
150
|
|
|
$gateway->update_status( $payment ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Test WordPress error. |
155
|
|
|
*/ |
156
|
|
|
public function test_wp_error() { |
157
|
|
|
$config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
158
|
|
|
|
159
|
|
|
$gateway = new Gateway( $config ); |
160
|
|
|
|
161
|
|
|
$filter = function() { |
162
|
|
|
return new \WP_Error( 'http_request_failed', 'A valid URL was not provided.' ); |
163
|
|
|
}; |
164
|
|
|
|
165
|
|
|
\add_filter( 'pre_http_request', $filter ); |
166
|
|
|
|
167
|
|
|
$payment = new Payment(); |
168
|
|
|
|
169
|
|
|
$payment->set_transaction_id( '00a502ba-d289-4ee1-a43e-3c4e1de76b4e' ); |
170
|
|
|
|
171
|
|
|
$this->expectException( \Throwable::class ); |
172
|
|
|
$this->expectExceptionMessage( 'A valid URL was not provided.' ); |
173
|
|
|
|
174
|
|
|
$gateway->update_status( $payment ); |
175
|
|
|
|
176
|
|
|
\remove_filter( 'pre_http_request', $filter ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Test post payment. |
181
|
|
|
*/ |
182
|
|
|
public function test_post_payment() { |
183
|
|
|
$config = new Config( Gateway::MODE_TEST, '123456', 'Test', '●●●●●●●●', '1' ); |
184
|
|
|
|
185
|
|
|
$gateway = new Gateway( $config ); |
186
|
|
|
|
187
|
|
|
$this->factory->fake( |
188
|
|
|
'https://stagconnect.acehubpaymentservices.com/gateway/v3/payments', |
189
|
|
|
__DIR__ . '/../http/post-payment.http' |
190
|
|
|
); |
191
|
|
|
|
192
|
|
|
$payment = new Payment(); |
193
|
|
|
|
194
|
|
|
$payment->set_id( 1 ); |
195
|
|
|
|
196
|
|
|
$payment->set_total_amount( new TaxedMoney( 50, 'EUR' ) ); |
197
|
|
|
|
198
|
|
|
$gateway->start( $payment ); |
199
|
|
|
|
200
|
|
|
$this->assertEquals( |
201
|
|
|
'https://test.acaptureservices.com/connectors/demo/ideal/simulator/paymentSimulation.ftl;jsessionid=5D94958C082AE32D58841306599361A5.uat01-vm-con02', |
202
|
|
|
$payment->get_action_url() |
203
|
|
|
); |
204
|
|
|
|
205
|
|
|
$this->assertEquals( '0c5b2580-45b9-440b-bef4-1ca016854afd', $payment->get_transaction_id() ); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: