-
Notifications
You must be signed in to change notification settings - Fork 3
/
CardPayRequestTest.php
87 lines (72 loc) · 3 KB
/
CardPayRequestTest.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
<?php
declare(strict_types=1);
namespace Message;
use Omnipay\Przelewy24\Message\CardPayRequest;
use Omnipay\Przelewy24\Message\CardPayResponse;
use Omnipay\Tests\TestCase;
use Symfony\Component\HttpFoundation\Response;
class CardPayRequestTest extends TestCase
{
/**
* @var CardPayRequest
*/
private $request;
public function setUp(): void
{
$this->request = new CardPayRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
'transactionId' => '29fa01f8-6bb8-4187-9fb0-ec6e1a62a731',
'number' => '9010100052000004',
'expiry' => '0535',
'cvv' => '1234',
'name' => 'Franek Dolas',
]);
}
public function testGetData(): void
{
$data = $this->request->getData();
$this->assertSame('29fa01f8-6bb8-4187-9fb0-ec6e1a62a731', $data['transactionToken']);
$this->assertSame('9010100052000004', $data['cardNumber']);
$this->assertSame('0535', $data['cardDate']);
$this->assertSame('1234', $data['cvv']);
$this->assertSame('Franek Dolas', $data['clientName']);
}
public function testSendSuccess(): void
{
$this->setMockHttpResponse('CardPaySuccess.txt');
/** @var CardPayResponse $response */
$response = $this->request->send();
$this->assertInstanceOf(CardPayResponse::class, $response);
$this->assertTrue($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertSame('1234567890', $response->getTransactionId());
$this->assertSame('https://this-is-redirect-url.com', $response->getRedirectUrl());
}
public function testSendAuthFailure(): void
{
$this->setMockHttpResponse('CardPayAuthFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(CardPayResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getCode());
$this->assertSame('Incorrect authentication', $response->getMessage());
}
public function testSendInvalidDataFailure(): void
{
$this->setMockHttpResponse('CardPayInvalidDataFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(CardPayResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getCode());
$this->assertSame('Invalid input data', $response->getMessage());
}
public function testSendUnableToPayFailure(): void
{
$this->setMockHttpResponse('CardPayUnableToPayFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(CardPayResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_CONFLICT, $response->getCode());
$this->assertSame('Unable to make payment.', $response->getMessage());
}
}