| 676 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Srmklive\PayPal\Tests\Unit\Adapter;
|
|
|
4 |
|
|
|
5 |
use PHPUnit\Framework\TestCase;
|
|
|
6 |
use Srmklive\PayPal\Tests\MockClientClasses;
|
|
|
7 |
use Srmklive\PayPal\Tests\MockRequestPayloads;
|
|
|
8 |
use Srmklive\PayPal\Tests\MockResponsePayloads;
|
|
|
9 |
|
|
|
10 |
class InvoicesTest extends TestCase
|
|
|
11 |
{
|
|
|
12 |
use MockClientClasses;
|
|
|
13 |
use MockRequestPayloads;
|
|
|
14 |
use MockResponsePayloads;
|
|
|
15 |
|
|
|
16 |
/** @test */
|
|
|
17 |
public function it_can_generate_unique_invoice_number()
|
|
|
18 |
{
|
|
|
19 |
$expectedResponse = $this->mockGenerateInvoiceNumberResponse();
|
|
|
20 |
|
|
|
21 |
$expectedMethod = 'generateInvoiceNumber';
|
|
|
22 |
|
|
|
23 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
24 |
|
|
|
25 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
26 |
$mockClient->getAccessToken();
|
|
|
27 |
|
|
|
28 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}());
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
/** @test */
|
|
|
32 |
public function it_can_create_a_draft_invoice()
|
|
|
33 |
{
|
|
|
34 |
$expectedResponse = $this->mockCreateInvoicesResponse();
|
|
|
35 |
|
|
|
36 |
$expectedParams = $this->createInvoiceParams();
|
|
|
37 |
|
|
|
38 |
$expectedMethod = 'createInvoice';
|
|
|
39 |
|
|
|
40 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
41 |
|
|
|
42 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
43 |
$mockClient->getAccessToken();
|
|
|
44 |
|
|
|
45 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/** @test */
|
|
|
49 |
public function it_can_list_current_invoices()
|
|
|
50 |
{
|
|
|
51 |
$expectedResponse = $this->mockListInvoicesResponse();
|
|
|
52 |
|
|
|
53 |
$expectedMethod = 'listInvoices';
|
|
|
54 |
|
|
|
55 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
56 |
|
|
|
57 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
58 |
$mockClient->getAccessToken();
|
|
|
59 |
|
|
|
60 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(1, 2, true));
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/** @test */
|
|
|
64 |
public function it_can_delete_an_invoice()
|
|
|
65 |
{
|
|
|
66 |
$expectedResponse = '';
|
|
|
67 |
|
|
|
68 |
$expectedMethod = 'deleteInvoice';
|
|
|
69 |
|
|
|
70 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
71 |
|
|
|
72 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
73 |
$mockClient->getAccessToken();
|
|
|
74 |
|
|
|
75 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5'));
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/** @test */
|
|
|
79 |
public function it_can_update_an_invoice()
|
|
|
80 |
{
|
|
|
81 |
$expectedResponse = $this->mockUpdateInvoicesResponse();
|
|
|
82 |
|
|
|
83 |
$expectedParams = $this->updateInvoiceParams();
|
|
|
84 |
|
|
|
85 |
$expectedMethod = 'updateInvoice';
|
|
|
86 |
|
|
|
87 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
88 |
|
|
|
89 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
90 |
$mockClient->getAccessToken();
|
|
|
91 |
|
|
|
92 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', $expectedParams));
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/** @test */
|
|
|
96 |
public function it_can_show_details_for_an_invoice()
|
|
|
97 |
{
|
|
|
98 |
$expectedResponse = $this->mockGetInvoicesResponse();
|
|
|
99 |
|
|
|
100 |
$expectedMethod = 'showInvoiceDetails';
|
|
|
101 |
|
|
|
102 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
103 |
|
|
|
104 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
105 |
$mockClient->getAccessToken();
|
|
|
106 |
|
|
|
107 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5'));
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/** @test */
|
|
|
111 |
public function it_can_cancel_an_invoice()
|
|
|
112 |
{
|
|
|
113 |
$expectedResponse = '';
|
|
|
114 |
|
|
|
115 |
$expectedParams = $this->cancelInvoiceParams();
|
|
|
116 |
|
|
|
117 |
$expectedMethod = 'cancelInvoice';
|
|
|
118 |
|
|
|
119 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
120 |
|
|
|
121 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
122 |
$mockClient->getAccessToken();
|
|
|
123 |
|
|
|
124 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', $expectedParams));
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
/** @test */
|
|
|
128 |
public function it_can_generate_qr_code_for_invoice()
|
|
|
129 |
{
|
|
|
130 |
$expectedResponse = $this->mockGenerateInvoiceQRCodeResponse();
|
|
|
131 |
|
|
|
132 |
$expectedMethod = 'generateQRCodeInvoice';
|
|
|
133 |
|
|
|
134 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
135 |
|
|
|
136 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
137 |
$mockClient->getAccessToken();
|
|
|
138 |
|
|
|
139 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', 400, 400));
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
/** @test */
|
|
|
143 |
public function it_can_register_payment_for_invoice()
|
|
|
144 |
{
|
|
|
145 |
$expectedResponse = $this->mockInvoiceRegisterPaymentResponse();
|
|
|
146 |
|
|
|
147 |
$expectedMethod = 'registerPaymentInvoice';
|
|
|
148 |
|
|
|
149 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
150 |
|
|
|
151 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
152 |
$mockClient->getAccessToken();
|
|
|
153 |
|
|
|
154 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 10.00));
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
/** @test */
|
|
|
158 |
public function it_can_delete_payment_for_invoice()
|
|
|
159 |
{
|
|
|
160 |
$expectedResponse = '';
|
|
|
161 |
|
|
|
162 |
$expectedMethod = 'deleteExternalPaymentInvoice';
|
|
|
163 |
|
|
|
164 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
165 |
|
|
|
166 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
167 |
$mockClient->getAccessToken();
|
|
|
168 |
|
|
|
169 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-86F38350LX4353815'));
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/** @test */
|
|
|
173 |
public function it_can_refund_payment_for_invoice()
|
|
|
174 |
{
|
|
|
175 |
$expectedResponse = $this->mockInvoiceRefundPaymentResponse();
|
|
|
176 |
|
|
|
177 |
$expectedMethod = 'refundInvoice';
|
|
|
178 |
|
|
|
179 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
180 |
|
|
|
181 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
182 |
$mockClient->getAccessToken();
|
|
|
183 |
|
|
|
184 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 5.00));
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
/** @test */
|
|
|
188 |
public function it_can_delete_refund_for_invoice()
|
|
|
189 |
{
|
|
|
190 |
$expectedResponse = '';
|
|
|
191 |
|
|
|
192 |
$expectedMethod = 'deleteRefundInvoice';
|
|
|
193 |
|
|
|
194 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
195 |
|
|
|
196 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
197 |
$mockClient->getAccessToken();
|
|
|
198 |
|
|
|
199 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-2LG703375E477444T'));
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
/** @test */
|
|
|
203 |
public function it_can_send_an_invoice()
|
|
|
204 |
{
|
|
|
205 |
$expectedResponse = '';
|
|
|
206 |
|
|
|
207 |
$expectedMethod = 'sendInvoice';
|
|
|
208 |
|
|
|
209 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
210 |
|
|
|
211 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
212 |
$mockClient->getAccessToken();
|
|
|
213 |
|
|
|
214 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(
|
|
|
215 |
'INV2-Z56S-5LLA-Q52L-CPZ5',
|
|
|
216 |
'Reminder: Payment due for the invoice #ABC-123',
|
|
|
217 |
'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.',
|
|
|
218 |
true,
|
|
|
219 |
true,
|
|
|
220 |
[
|
|
|
221 |
'customer-a@example.com',
|
|
|
222 |
'customer@example.com',
|
|
|
223 |
]
|
|
|
224 |
));
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
/** @test */
|
|
|
228 |
public function it_can_send_reminder_for_an_invoice()
|
|
|
229 |
{
|
|
|
230 |
$expectedResponse = '';
|
|
|
231 |
|
|
|
232 |
$expectedMethod = 'sendInvoiceReminder';
|
|
|
233 |
|
|
|
234 |
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
|
|
|
235 |
|
|
|
236 |
$mockClient->setApiCredentials($this->getMockCredentials());
|
|
|
237 |
$mockClient->getAccessToken();
|
|
|
238 |
|
|
|
239 |
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(
|
|
|
240 |
'INV2-Z56S-5LLA-Q52L-CPZ5',
|
|
|
241 |
'Reminder: Payment due for the invoice #ABC-123',
|
|
|
242 |
'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.',
|
|
|
243 |
true,
|
|
|
244 |
true,
|
|
|
245 |
[
|
|
|
246 |
'customer-a@example.com',
|
|
|
247 |
'customer@example.com',
|
|
|
248 |
]
|
|
|
249 |
));
|
|
|
250 |
}
|
|
|
251 |
}
|