1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Call\Masterpass; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use SlevomatCsobGateway\Api\ApiClient; |
9
|
|
|
use SlevomatCsobGateway\Api\Response; |
10
|
|
|
use SlevomatCsobGateway\Api\ResponseCode; |
11
|
|
|
use SlevomatCsobGateway\Call\PaymentStatus; |
12
|
|
|
use SlevomatCsobGateway\Call\ResultCode; |
13
|
|
|
|
14
|
|
|
class StandardExtractRequestTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public function testSend(): void |
18
|
|
|
{ |
19
|
|
|
/** @var ApiClient|MockObject $apiClient */ |
20
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
21
|
|
|
->disableOriginalConstructor() |
22
|
|
|
->getMock(); |
23
|
|
|
|
24
|
|
|
$apiClient->expects(self::once())->method('post') |
25
|
|
|
->with('masterpass/standard/extract', [ |
26
|
|
|
'merchantId' => '012345', |
27
|
|
|
'payId' => '123456789', |
28
|
|
|
'callbackParams' => [ |
29
|
|
|
'mpstatus' => 'success', |
30
|
|
|
'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
31
|
|
|
'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812', |
32
|
|
|
'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d', |
33
|
|
|
], |
34
|
|
|
]) |
35
|
|
|
->willReturn( |
36
|
|
|
new Response(ResponseCode::get(ResponseCode::S200_OK), [ |
37
|
|
|
'payId' => '123456789', |
38
|
|
|
'dttm' => '20140425131559', |
39
|
|
|
'resultCode' => 0, |
40
|
|
|
'resultMessage' => 'OK', |
41
|
|
|
'paymentStatus' => 2, |
42
|
|
|
'checkoutParams' => ['card' => [ |
43
|
|
|
'maskedCln' => '****4145', |
44
|
|
|
'expiration' => '11/19', |
45
|
|
|
'billingAddress' => |
46
|
|
|
[ |
47
|
|
|
'city' => 'Praha 1', |
48
|
|
|
'country' => 'CZ', |
49
|
|
|
'line1' => 'Jindřišská 16', |
50
|
|
|
'postalCode' => '11150', |
51
|
|
|
], |
52
|
|
|
], |
53
|
|
|
'shippingAddress' => |
54
|
|
|
[ |
55
|
|
|
'recipientName' => 'Jan Novák', |
56
|
|
|
'recipientPhoneNumber' => '+420602123456', |
57
|
|
|
'city' => 'Praha 1', |
58
|
|
|
'country' => 'CZ', |
59
|
|
|
'line1' => 'Dlouhá 23', |
60
|
|
|
'postalCode' => '11150', |
61
|
|
|
], |
62
|
|
|
], |
63
|
|
|
]) |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$paymentRequest = new StandardExtractRequest( |
67
|
|
|
'012345', |
68
|
|
|
'123456789', |
69
|
|
|
[ |
70
|
|
|
'mpstatus' => 'success', |
71
|
|
|
'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
72
|
|
|
'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812', |
73
|
|
|
'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d', |
74
|
|
|
] |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$extractResponse = $paymentRequest->send($apiClient); |
78
|
|
|
|
79
|
|
|
self::assertSame('123456789', $extractResponse->getPayId()); |
80
|
|
|
self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $extractResponse->getResponseDateTime()); |
81
|
|
|
self::assertEquals(ResultCode::get(ResultCode::C0_OK), $extractResponse->getResultCode()); |
82
|
|
|
self::assertSame('OK', $extractResponse->getResultMessage()); |
83
|
|
|
self::assertEquals(PaymentStatus::get(PaymentStatus::S2_IN_PROGRESS), $extractResponse->getPaymentStatus()); |
84
|
|
|
self::assertNotNull($extractResponse->getCheckoutParams()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|