-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApplePayAuthorizeRequestTest.php
More file actions
158 lines (139 loc) · 5.22 KB
/
ApplePayAuthorizeRequestTest.php
File metadata and controls
158 lines (139 loc) · 5.22 KB
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
<?php
namespace Omnipay\Vindicia\Message;
use Omnipay\Vindicia\TestFramework\Mocker;
use Omnipay\Vindicia\TestFramework\DataFaker;
use Omnipay\Tests\TestCase;
class ApplePayAuthorizeRequestTest extends TestCase
{
/**
* @return void
*/
public function setUp(): void
{
// Gateway parameters.
$this->faker = new DataFaker();
$this->pemCertPath = $this->faker->path();
$this->keyCertPath = $this->faker->path();
$this->keyCertPassword = $this->faker->password();
// Request parameters.
$this->validationUrl = $this->faker->url();
$this->merchantIdentifier = $this->faker->transactionId();
$this->displayName = $this->faker->username();
$this->applicationUrl = $this->faker->url();
$this->request = new ApplePayAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'pemCertPath' => $this->pemCertPath,
'keyCertPath' => $this->keyCertPath,
'keyCertPassword' => $this->keyCertPassword,
'validationUrl' => $this->validationUrl,
'merchantIdentifier' => $this->merchantIdentifier,
'displayName' => $this->displayName,
'applicationUrl' => $this->applicationUrl
)
);
}
/**
* @return void
*/
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame($this->merchantIdentifier, $data['merchantIdentifier']);
$this->assertSame($this->displayName, $data['displayName']);
$this->assertSame('web', $data['initiative']);
$this->assertSame($this->applicationUrl, $data['initiativeContext']);
}
/**
* @return void
*/
public function testValidationUrl()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\ApplePayAuthorizeRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setValidationUrl($this->validationUrl));
$this->assertEquals($this->validationUrl, $request->getValidationUrl());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The validationUrl parameter is required
* @return void
*/
public function testValidationUrlRequired()
{
$this->request->setValidationUrl(null);
$this->request->getData();
}
/**
* @return void
*/
public function testMerchantIdentifier()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\ApplePayAuthorizeRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setMerchantIdentifier($this->merchantIdentifier));
$this->assertSame($this->merchantIdentifier, $request->getMerchantIdentifier());
}
/**
* @return void
*/
public function testDisplayName()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\ApplePayAuthorizeRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setDisplayName($this->displayName));
$this->assertSame($this->displayName, $request->getDisplayName());
}
/**
* @return void
*/
public function testApplicationUrl()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\ApplePayAuthorizeRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setApplicationUrl($this->applicationUrl));
$this->assertSame($this->applicationUrl, $request->getApplicationUrl());
}
/**
* @return void
*/
public function testSendSuccess()
{
// We use a .txt file since the entire response isn't json, only the message.
$this->setMockHttpResponse('ApplePayAuthorizeRequestSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('OK', $response->getMessage());
$this->assertSame('200', $response->getCode());
$this->assertJsonStringEqualsJsonString(
json_encode(
array(
'epochTimestamp' => 1234567890,
'expiresAt' => 123456789000,
'merchantSessionIdentifier' => 'SSH1234567890',
'nonce' => 'd12345',
'merchantIdentifier' => 'SSHDC1234567890IJK',
'domainName' => 'abcd.com',
'displayName' => 'Abcd',
'signature' => '1234567890'
)
),
$response->getPaymentSessionObject()
);
}
/**
* @return void
*/
public function testSendFailure()
{
// We use a .txt file since the entire response isn't json, only the message.
$this->setMockHttpResponse('ApplePayAuthorizeRequestFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertSame('400', $response->getCode());
$this->assertSame('Not Found', $response->getMessage());
$this->assertEmpty(
$response->getPaymentSessionObject()
);
}
}