1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lamoda\Payture\InPayClient\Tests\EndToEnd; |
4
|
|
|
|
5
|
|
|
use Lamoda\Payture\InPayClient\SessionType; |
6
|
|
|
use Lamoda\Payture\InPayClient\TerminalResponse; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @coversNothing |
10
|
|
|
*/ |
11
|
|
|
final class TwoStepPaymentTerminalTest extends AbstractTerminalTestCase |
12
|
|
|
{ |
13
|
|
|
private const ORDER_PRICE = 10000; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Keep the test suite with deprecated payStatus. |
17
|
|
|
*/ |
18
|
|
|
public function testPaytureInPayApiWithPayStatus(): void |
19
|
|
|
{ |
20
|
|
|
$orderId = self::generateOrderId(); |
21
|
|
|
|
22
|
|
|
$response = $this->initPayment($orderId); |
23
|
|
|
$sessionId = $response->getSessionId(); |
24
|
|
|
|
25
|
|
|
$response = $this->getTerminal()->payStatus($orderId); |
|
|
|
|
26
|
|
|
self::assertTrue($response->isSuccess()); |
27
|
|
|
|
28
|
|
|
$url = $this->getTerminal()->createPaymentUrl($sessionId); |
29
|
|
|
|
30
|
|
|
$this->pay($url, $orderId, self::ORDER_PRICE); |
31
|
|
|
$response = $this->getTerminal()->payStatus($orderId); |
|
|
|
|
32
|
|
|
self::assertTrue($response->isAuthorizedState()); |
33
|
|
|
|
34
|
|
|
$response = $this->getTerminal()->charge($orderId, self::ORDER_PRICE); |
35
|
|
|
self::assertTrue($response->isSuccess()); |
36
|
|
|
$response = $this->getTerminal()->payStatus($orderId); |
|
|
|
|
37
|
|
|
self::assertTrue($response->isChargedState()); |
38
|
|
|
|
39
|
|
|
$response = $this->getTerminal()->refund($orderId, self::ORDER_PRICE); |
40
|
|
|
self::assertTrue($response->isSuccess()); |
41
|
|
|
$response = $this->getTerminal()->payStatus($orderId); |
|
|
|
|
42
|
|
|
self::assertTrue($response->isRefundedState()); |
43
|
|
|
self::assertNotEmpty($response->getRrn()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testPaytureInPayApi(): void |
47
|
|
|
{ |
48
|
|
|
$orderId = self::generateOrderId(); |
49
|
|
|
|
50
|
|
|
$response = $this->initPayment($orderId); |
51
|
|
|
$sessionId = $response->getSessionId(); |
52
|
|
|
|
53
|
|
|
$url = $this->getTerminal()->createPaymentUrl($sessionId); |
54
|
|
|
|
55
|
|
|
$this->pay($url, $orderId, self::ORDER_PRICE); |
56
|
|
|
$response = $this->getTerminal()->getState($orderId); |
57
|
|
|
self::assertNotEmpty($response->getRrn()); |
58
|
|
|
self::assertTrue($response->isAuthorizedState()); |
59
|
|
|
|
60
|
|
|
$response = $this->getTerminal()->charge($orderId, self::ORDER_PRICE); |
61
|
|
|
self::assertTrue($response->isSuccess()); |
62
|
|
|
$response = $this->getTerminal()->getState($orderId); |
63
|
|
|
self::assertTrue($response->isChargedState()); |
64
|
|
|
self::assertNotEmpty($response->getRrn()); |
65
|
|
|
|
66
|
|
|
$response = $this->getTerminal()->refund($orderId, self::ORDER_PRICE); |
67
|
|
|
self::assertTrue($response->isSuccess()); |
68
|
|
|
$response = $this->getTerminal()->getState($orderId); |
69
|
|
|
self::assertTrue($response->isRefundedState()); |
70
|
|
|
self::assertNotEmpty($response->getRrn()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function initPayment(string $orderId): TerminalResponse |
74
|
|
|
{ |
75
|
|
|
return $this->getTerminal()->init( |
76
|
|
|
SessionType::BLOCK(), |
77
|
|
|
$orderId, |
78
|
|
|
'Auto Test purchase', |
79
|
|
|
self::ORDER_PRICE, |
80
|
|
|
'127.0.0.1', |
81
|
|
|
'https://github.com/lamoda' |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This method has been deprecated.