forked from mysiar-org/omnipay-przelewy24v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GatewayTest.php
178 lines (149 loc) · 6.24 KB
/
GatewayTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
declare(strict_types=1);
namespace API;
use Omnipay\Omnipay;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\VarDumper\VarDumper;
class GatewayTest extends TestCase
{
private $gateway;
public function setUp(): void
{
$settings = [
'merchantId' => getenv('P24V1_MERCHANT_ID'),
'posId' => getenv('P24V1_POS_ID'),
'crc' => getenv('P24V1_CRC'),
'reportKey' => getenv('P24V1_REPORT_KEY'),
'language' => getenv('P24V1_LANGUAGE'),
'testMode' => true,
];
$this->gateway = Omnipay::create('Przelewy24');
$this->gateway->initialize($settings);
}
public function testAccess(): void
{
$response = $this->gateway->testAccess()->send();
$this->assertSame(Response::HTTP_OK, $response->getCode());
$this->assertSame('', $response->getMessage());
$this->assertTrue($response->isSuccessful());
$this->gateway->setReportKey('dummy');
$response = $this->gateway->testAccess()->send();
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getCode());
$this->assertSame('Incorrect authentication', $response->getMessage());
}
public function testMethods(): void
{
$response = $this->gateway->methods()->send();
$this->assertSame(Response::HTTP_OK, $response->getCode());
$this->assertSame('', $response->getMessage());
$this->assertTrue($response->isSuccessful());
$this->assertGreaterThan(0, count($response->getMethods()));
}
public function testPurchase(): void
{
$sessionId = $this->randomString();
$response = $this->gateway->purchase([
'sessionId' => $sessionId,
'amount' => '10.66',
'currency' => 'PLN',
'description' => 'Transaction description',
'email' => '[email protected]',
'country' => 'PL',
'returnUrl' => 'https://omnipay-przelewy24v1.requestcatcher.com/return',
'notifyUrl' => 'https://omnipay-przelewy24v1.requestcatcher.com/notify',
])->send();
VarDumper::dump($sessionId);
VarDumper::dump($response->getRedirectUrl());
VarDumper::dump($response->getMessage());
$this->assertSame(Response::HTTP_OK, $response->getCode());
$this->assertSame('', $response->getMessage());
$this->assertTrue($response->isSuccessful());
$this->assertContains('https://sandbox.przelewy24.pl/trnRequest/', $response->getRedirectUrl());
$this->assertSame(35, strlen($response->getToken()));
}
/*
* sequence to run this test
* 1. run testPurchase
* 2. use redirect url to commit transaction
* 3. check request catcher for payload
* 4. fill below sessionId & transactionId (orderId in payload) value
*/
public function testComplete(): void
{
$this->markTestSkipped('Comment this out if you want complete purchase as per above comment description');
$sessionId = 'u6ipAwPFXJiVTqG';
$transactionId = '317213045';
$response = $this->gateway->completePurchase([
'sessionId' => $sessionId,
'amount' => '10.66',
'currency' => 'PLN',
'transactionId' => $transactionId,
])->send();
VarDumper::dump($response->getCode());
VarDumper::dump($response->getMessage());
$this->assertSame(Response::HTTP_OK, $response->getCode());
$this->assertTrue($response->isSuccessful());
}
public function testPurchaseInfo(): void
{
$sessionId = '20c62d6b-5ff0-46a0-97eb-eea0dd5b4a93'; // real existing session
$response = $this->gateway->purchaseInfo([
'sessionId' => $sessionId,
])->send();
VarDumper::dump($response->getCode());
VarDumper::dump($response->getInfo());
$this->assertSame(Response::HTTP_OK, $response->getCode());
$this->assertTrue($response->isSuccessful());
$this->assertCount(18, $response->getInfo());
$response = $this->gateway->purchaseInfo('not-existing')->send();
$this->assertSame(Response::HTTP_NOT_FOUND, $response->getCode());
}
public function testPurchaseCard(): void
{
$sessionId = $this->randomString();
$request = $this->gateway->purchase([
'sessionId' => $sessionId,
'amount' => '10.66',
'currency' => 'PLN',
'description' => 'Transaction description - card',
'email' => '[email protected]',
'name' => 'Franek Dolas',
'country' => 'PL',
'returnUrl' => 'https://omnipay-przelewy24v1.requestcatcher.com/return',
'notifyUrl' => 'https://omnipay-przelewy24v1.requestcatcher.com/notify',
'cardNotifyUrl' => 'https://omnipay-przelewy24v1.requestcatcher.com/notifyCard',
'channel' => 1,
]);
$response = $request->send();
VarDumper::dump($sessionId);
VarDumper::dump($response->getRedirectUrl());
VarDumper::dump($response->getMessage());
$this->assertSame(Response::HTTP_OK, $response->getCode());
$this->assertSame('', $response->getMessage());
$this->assertTrue($response->isSuccessful());
$this->assertContains('https://sandbox.przelewy24.pl/trnRequest/', $response->getRedirectUrl());
$this->assertSame(35, strlen($response->getToken()));
}
public function testCardInfo(): void
{
$transactionId = '317229535';
$this->markTestSkipped('Comment this out if you have payment with credit card');
$response = $this->gateway->cardInfo([
'transactionId' => $transactionId,
])->send();
dump($response->getCode());
dump($response->getInfo());
}
private function randomString(int $length = 15): string
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; ++$i) {
$randomString .= $characters[random_int(0, $charactersLength - 1)];
}
return $randomString;
}
}