| 676 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Srmklive\PayPal\Tests\Unit\Client;
|
|
|
4 |
|
|
|
5 |
use GuzzleHttp\Utils;
|
|
|
6 |
use PHPUnit\Framework\TestCase;
|
|
|
7 |
use Srmklive\PayPal\Tests\MockClientClasses;
|
|
|
8 |
use Srmklive\PayPal\Tests\MockRequestPayloads;
|
|
|
9 |
use Srmklive\PayPal\Tests\MockResponsePayloads;
|
|
|
10 |
|
|
|
11 |
class InvoicesTest extends TestCase
|
|
|
12 |
{
|
|
|
13 |
use MockClientClasses;
|
|
|
14 |
use MockRequestPayloads;
|
|
|
15 |
use MockResponsePayloads;
|
|
|
16 |
|
|
|
17 |
/** @test */
|
|
|
18 |
public function it_can_generate_unique_invoice_number()
|
|
|
19 |
{
|
|
|
20 |
$expectedResponse = $this->mockGenerateInvoiceNumberResponse();
|
|
|
21 |
|
|
|
22 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/generate-next-invoice-number';
|
|
|
23 |
$expectedParams = [
|
|
|
24 |
'headers' => [
|
|
|
25 |
'Accept' => 'application/json',
|
|
|
26 |
'Accept-Language' => 'en_US',
|
|
|
27 |
'Authorization' => 'Bearer some-token',
|
|
|
28 |
],
|
|
|
29 |
];
|
|
|
30 |
|
|
|
31 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
32 |
|
|
|
33 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
/** @test */
|
|
|
37 |
public function it_can_create_a_draft_invoice()
|
|
|
38 |
{
|
|
|
39 |
$expectedResponse = $this->mockCreateInvoicesResponse();
|
|
|
40 |
|
|
|
41 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices';
|
|
|
42 |
$expectedParams = [
|
|
|
43 |
'headers' => [
|
|
|
44 |
'Accept' => 'application/json',
|
|
|
45 |
'Accept-Language' => 'en_US',
|
|
|
46 |
'Authorization' => 'Bearer some-token',
|
|
|
47 |
],
|
|
|
48 |
'json' => $this->createInvoiceParams(),
|
|
|
49 |
];
|
|
|
50 |
|
|
|
51 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
52 |
|
|
|
53 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/** @test */
|
|
|
57 |
public function it_can_list_current_invoices()
|
|
|
58 |
{
|
|
|
59 |
$expectedResponse = $this->mockListInvoicesResponse();
|
|
|
60 |
|
|
|
61 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true';
|
|
|
62 |
$expectedParams = [
|
|
|
63 |
'headers' => [
|
|
|
64 |
'Accept' => 'application/json',
|
|
|
65 |
'Accept-Language' => 'en_US',
|
|
|
66 |
'Authorization' => 'Bearer some-token',
|
|
|
67 |
],
|
|
|
68 |
];
|
|
|
69 |
|
|
|
70 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
71 |
|
|
|
72 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/** @test */
|
|
|
76 |
public function it_can_delete_an_invoice()
|
|
|
77 |
{
|
|
|
78 |
$expectedResponse = '';
|
|
|
79 |
|
|
|
80 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
|
|
|
81 |
$expectedParams = [
|
|
|
82 |
'headers' => [
|
|
|
83 |
'Accept' => 'application/json',
|
|
|
84 |
'Accept-Language' => 'en_US',
|
|
|
85 |
'Authorization' => 'Bearer some-token',
|
|
|
86 |
],
|
|
|
87 |
];
|
|
|
88 |
|
|
|
89 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete');
|
|
|
90 |
|
|
|
91 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/** @test */
|
|
|
95 |
public function it_can_update_an_invoice()
|
|
|
96 |
{
|
|
|
97 |
$expectedResponse = $this->mockUpdateInvoicesResponse();
|
|
|
98 |
|
|
|
99 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
|
|
|
100 |
$expectedParams = [
|
|
|
101 |
'headers' => [
|
|
|
102 |
'Accept' => 'application/json',
|
|
|
103 |
'Accept-Language' => 'en_US',
|
|
|
104 |
'Authorization' => 'Bearer some-token',
|
|
|
105 |
],
|
|
|
106 |
'json' => $this->updateInvoiceParams(),
|
|
|
107 |
];
|
|
|
108 |
|
|
|
109 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'put');
|
|
|
110 |
|
|
|
111 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->put($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/** @test */
|
|
|
115 |
public function it_can_show_details_for_an_invoice()
|
|
|
116 |
{
|
|
|
117 |
$expectedResponse = $this->mockGetInvoicesResponse();
|
|
|
118 |
|
|
|
119 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
|
|
|
120 |
$expectedParams = [
|
|
|
121 |
'headers' => [
|
|
|
122 |
'Accept' => 'application/json',
|
|
|
123 |
'Accept-Language' => 'en_US',
|
|
|
124 |
'Authorization' => 'Bearer some-token',
|
|
|
125 |
],
|
|
|
126 |
];
|
|
|
127 |
|
|
|
128 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
129 |
|
|
|
130 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
/** @test */
|
|
|
134 |
public function it_can_cancel_an_invoice()
|
|
|
135 |
{
|
|
|
136 |
$expectedResponse = '';
|
|
|
137 |
|
|
|
138 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/cancel';
|
|
|
139 |
$expectedParams = [
|
|
|
140 |
'headers' => [
|
|
|
141 |
'Accept' => 'application/json',
|
|
|
142 |
'Accept-Language' => 'en_US',
|
|
|
143 |
'Authorization' => 'Bearer some-token',
|
|
|
144 |
],
|
|
|
145 |
'json' => $this->cancelInvoiceParams(),
|
|
|
146 |
];
|
|
|
147 |
|
|
|
148 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
149 |
|
|
|
150 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
/** @test */
|
|
|
154 |
public function it_can_generate_qr_code_for_invoice()
|
|
|
155 |
{
|
|
|
156 |
$expectedResponse = $this->mockGenerateInvoiceNumberResponse();
|
|
|
157 |
|
|
|
158 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/generate-qr-code';
|
|
|
159 |
$expectedParams = [
|
|
|
160 |
'headers' => [
|
|
|
161 |
'Accept' => 'application/json',
|
|
|
162 |
'Accept-Language' => 'en_US',
|
|
|
163 |
'Authorization' => 'Bearer some-token',
|
|
|
164 |
],
|
|
|
165 |
'json' => $this->generateQRCodeInvoiceParams(),
|
|
|
166 |
];
|
|
|
167 |
|
|
|
168 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
169 |
|
|
|
170 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
/** @test */
|
|
|
174 |
public function it_can_register_payment_for_invoice()
|
|
|
175 |
{
|
|
|
176 |
$expectedResponse = $this->mockInvoiceRegisterPaymentResponse();
|
|
|
177 |
|
|
|
178 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments';
|
|
|
179 |
$expectedParams = [
|
|
|
180 |
'headers' => [
|
|
|
181 |
'Accept' => 'application/json',
|
|
|
182 |
'Accept-Language' => 'en_US',
|
|
|
183 |
'Authorization' => 'Bearer some-token',
|
|
|
184 |
],
|
|
|
185 |
'json' => $this->registerInvoicePaymentParams(),
|
|
|
186 |
];
|
|
|
187 |
|
|
|
188 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
189 |
|
|
|
190 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
/** @test */
|
|
|
194 |
public function it_can_delete_payment_for_invoice()
|
|
|
195 |
{
|
|
|
196 |
$expectedResponse = '';
|
|
|
197 |
|
|
|
198 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments/EXTR-86F38350LX4353815';
|
|
|
199 |
$expectedParams = [
|
|
|
200 |
'headers' => [
|
|
|
201 |
'Accept' => 'application/json',
|
|
|
202 |
'Accept-Language' => 'en_US',
|
|
|
203 |
'Authorization' => 'Bearer some-token',
|
|
|
204 |
],
|
|
|
205 |
];
|
|
|
206 |
|
|
|
207 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete');
|
|
|
208 |
|
|
|
209 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/** @test */
|
|
|
213 |
public function it_can_refund_payment_for_invoice()
|
|
|
214 |
{
|
|
|
215 |
$expectedResponse = $this->mockInvoiceRefundPaymentResponse();
|
|
|
216 |
|
|
|
217 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/refunds';
|
|
|
218 |
$expectedParams = [
|
|
|
219 |
'headers' => [
|
|
|
220 |
'Accept' => 'application/json',
|
|
|
221 |
'Accept-Language' => 'en_US',
|
|
|
222 |
'Authorization' => 'Bearer some-token',
|
|
|
223 |
],
|
|
|
224 |
'json' => $this->refundInvoicePaymentParams(),
|
|
|
225 |
];
|
|
|
226 |
|
|
|
227 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
228 |
|
|
|
229 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
/** @test */
|
|
|
233 |
public function it_can_delete_refund_for_invoice()
|
|
|
234 |
{
|
|
|
235 |
$expectedResponse = '';
|
|
|
236 |
|
|
|
237 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-333R-YUQL-YNNN-D7WF/refunds/EXTR-2LG703375E477444T';
|
|
|
238 |
$expectedParams = [
|
|
|
239 |
'headers' => [
|
|
|
240 |
'Accept' => 'application/json',
|
|
|
241 |
'Accept-Language' => 'en_US',
|
|
|
242 |
'Authorization' => 'Bearer some-token',
|
|
|
243 |
],
|
|
|
244 |
];
|
|
|
245 |
|
|
|
246 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete');
|
|
|
247 |
|
|
|
248 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
/** @test */
|
|
|
252 |
public function it_can_send_an_invoice()
|
|
|
253 |
{
|
|
|
254 |
$expectedResponse = '';
|
|
|
255 |
|
|
|
256 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-EHNV-LJ5S-A7DZ-V6NJ/send';
|
|
|
257 |
$expectedParams = [
|
|
|
258 |
'headers' => [
|
|
|
259 |
'Accept' => 'application/json',
|
|
|
260 |
'Accept-Language' => 'en_US',
|
|
|
261 |
'Authorization' => 'Bearer some-token',
|
|
|
262 |
],
|
|
|
263 |
'json' => $this->sendInvoiceParams(),
|
|
|
264 |
];
|
|
|
265 |
|
|
|
266 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
267 |
|
|
|
268 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
/** @test */
|
|
|
272 |
public function it_can_send_reminder_for_an_invoice()
|
|
|
273 |
{
|
|
|
274 |
$expectedResponse = '';
|
|
|
275 |
|
|
|
276 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/remind';
|
|
|
277 |
$expectedParams = [
|
|
|
278 |
'headers' => [
|
|
|
279 |
'Accept' => 'application/json',
|
|
|
280 |
'Accept-Language' => 'en_US',
|
|
|
281 |
'Authorization' => 'Bearer some-token',
|
|
|
282 |
],
|
|
|
283 |
'json' => $this->sendInvoiceReminderParams(),
|
|
|
284 |
];
|
|
|
285 |
|
|
|
286 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
287 |
|
|
|
288 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
289 |
}
|
|
|
290 |
}
|