Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
676 lars 1
<?php
2
 
3
namespace Srmklive\PayPal\Tests\Feature;
4
 
5
use Carbon\Carbon;
6
use PHPUnit\Framework\TestCase;
7
use Srmklive\PayPal\Services\PayPal as PayPalClient;
8
use Srmklive\PayPal\Tests\MockClientClasses;
9
use Srmklive\PayPal\Tests\MockRequestPayloads;
10
use Srmklive\PayPal\Tests\MockResponsePayloads;
11
 
12
class AdapterFeatureTest extends TestCase
13
{
14
    use MockClientClasses;
15
    use MockRequestPayloads;
16
    use MockResponsePayloads;
17
 
18
    /** @var string */
19
    protected static $access_token = '';
20
 
21
    /** @var string */
22
    protected static $product_id = '';
23
 
24
    /** @var \Srmklive\PayPal\Services\PayPal */
25
    protected $client;
26
 
27
    protected function setUp(): void
28
    {
29
        $this->client = new PayPalClient($this->getApiCredentials());
30
 
31
        parent::setUp();
32
    }
33
 
34
    /** @test */
35
    public function it_returns_error_if_invalid_credentials_are_used_to_get_access_token()
36
    {
37
        $this->client = new PayPalClient($this->getMockCredentials());
38
        $response = $this->client->getAccessToken();
39
 
40
        $this->assertIsArray($response['error']);
41
        $this->assertArrayHasKey('error', $response);
42
    }
43
 
44
    /** @test */
45
    public function it_can_get_access_token()
46
    {
47
        $this->client->setClient(
48
            $this->mock_http_client(
49
                $this->mockAccessTokenResponse()
50
            )
51
        );
52
        $response = $this->client->getAccessToken();
53
 
54
        self::$access_token = $response['access_token'];
55
 
56
        $this->assertArrayHasKey('access_token', $response);
57
        $this->assertNotEmpty($response['access_token']);
58
    }
59
 
60
    /** @test */
61
    public function it_can_create_a_billing_plan()
62
    {
63
        $this->client->setAccessToken([
64
            'access_token'  => self::$access_token,
65
            'token_type'    => 'Bearer',
66
        ]);
67
 
68
        $this->client->setClient(
69
            $this->mock_http_client(
70
                $this->mockCreatePlansResponse()
71
            )
72
        );
73
 
74
        $expectedParams = $this->createPlanParams();
75
 
76
        $response = $this->client->createPlan($expectedParams, 'some-request-id');
77
 
78
        $this->assertNotEmpty($response);
79
        $this->assertArrayHasKey('id', $response);
80
    }
81
 
82
    /** @test */
83
    public function it_can_list_billing_plans()
84
    {
85
        $this->client->setAccessToken([
86
            'access_token'  => self::$access_token,
87
            'token_type'    => 'Bearer',
88
        ]);
89
 
90
        $this->client->setClient(
91
            $this->mock_http_client(
92
                $this->mockListPlansResponse()
93
            )
94
        );
95
 
96
        $response = $this->client->listPlans();
97
 
98
        $this->assertNotEmpty($response);
99
        $this->assertArrayHasKey('plans', $response);
100
    }
101
 
102
    /** @test */
103
    public function it_can_update_a_billing_plan()
104
    {
105
        $this->client->setAccessToken([
106
            'access_token'  => self::$access_token,
107
            'token_type'    => 'Bearer',
108
        ]);
109
 
110
        $this->client->setClient(
111
            $this->mock_http_client(false)
112
        );
113
 
114
        $expectedParams = $this->updatePlanParams();
115
 
116
        $response = $this->client->updatePlan('P-7GL4271244454362WXNWU5NQ', $expectedParams);
117
 
118
        $this->assertEmpty($response);
119
    }
120
 
121
    /** @test */
122
    public function it_can_show_details_for_a_billing_plan()
123
    {
124
        $this->client->setAccessToken([
125
            'access_token'  => self::$access_token,
126
            'token_type'    => 'Bearer',
127
        ]);
128
 
129
        $this->client->setClient(
130
            $this->mock_http_client(
131
                $this->mockGetPlansResponse()
132
            )
133
        );
134
 
135
        $response = $this->client->showPlanDetails('P-5ML4271244454362WXNWU5NQ');
136
 
137
        $this->assertNotEmpty($response);
138
        $this->assertArrayHasKey('id', $response);
139
    }
140
 
141
    /** @test */
142
    public function it_can_activate_a_billing_plan()
143
    {
144
        $this->client->setAccessToken([
145
            'access_token'  => self::$access_token,
146
            'token_type'    => 'Bearer',
147
        ]);
148
 
149
        $this->client->setClient(
150
            $this->mock_http_client(false)
151
        );
152
 
153
        $response = $this->client->activatePlan('P-7GL4271244454362WXNWU5NQ');
154
 
155
        $this->assertEmpty($response);
156
    }
157
 
158
    /** @test */
159
    public function it_can_deactivate_a_billing_plan()
160
    {
161
        $this->client->setAccessToken([
162
            'access_token'  => self::$access_token,
163
            'token_type'    => 'Bearer',
164
        ]);
165
 
166
        $this->client->setClient(
167
            $this->mock_http_client(false)
168
        );
169
 
170
        $response = $this->client->deactivatePlan('P-7GL4271244454362WXNWU5NQ');
171
 
172
        $this->assertEmpty($response);
173
    }
174
 
175
    /** @test */
176
    public function it_can_update_pricing_for_a_billing_plan()
177
    {
178
        $this->client->setAccessToken([
179
            'access_token'  => self::$access_token,
180
            'token_type'    => 'Bearer',
181
        ]);
182
 
183
        $this->client->setClient(
184
            $this->mock_http_client(false)
185
        );
186
 
187
        $expectedParams = $this->updatePlanPricingParams();
188
 
189
        $response = $this->client->updatePlanPricing('P-2UF78835G6983425GLSM44MA', $expectedParams);
190
 
191
        $this->assertEmpty($response);
192
    }
193
 
194
    /** @test */
195
    public function it_can_list_products()
196
    {
197
        $this->client->setAccessToken([
198
            'access_token'  => self::$access_token,
199
            'token_type'    => 'Bearer',
200
        ]);
201
 
202
        $this->client->setClient(
203
            $this->mock_http_client(
204
                $this->mockListCatalogProductsResponse()
205
            )
206
        );
207
 
208
        $response = $this->client->listProducts();
209
 
210
        $this->assertNotEmpty($response);
211
        $this->assertArrayHasKey('products', $response);
212
    }
213
 
214
    /** @test */
215
    public function it_can_create_a_product()
216
    {
217
        $this->client->setAccessToken([
218
            'access_token'  => self::$access_token,
219
            'token_type'    => 'Bearer',
220
        ]);
221
 
222
        $this->client->setClient(
223
            $this->mock_http_client(
224
                $this->mockCreateCatalogProductsResponse()
225
            )
226
        );
227
 
228
        $expectedParams = $this->createProductParams();
229
 
230
        $response = $this->client->createProduct($expectedParams, 'product-request-'.time());
231
 
232
        self::$product_id = $response['id'];
233
 
234
        $this->assertNotEmpty($response);
235
        $this->assertArrayHasKey('id', $response);
236
    }
237
 
238
    /** @test */
239
    public function it_can_update_a_product()
240
    {
241
        $this->client->setAccessToken([
242
            'access_token'  => self::$access_token,
243
            'token_type'    => 'Bearer',
244
        ]);
245
 
246
        $this->client->setClient(
247
            $this->mock_http_client(false)
248
        );
249
 
250
        $expectedParams = $this->updateProductParams();
251
 
252
        $response = $this->client->updateProduct(self::$product_id, $expectedParams);
253
 
254
        $this->assertEmpty($response);
255
    }
256
 
257
    /** @test */
258
    public function it_can_get_details_for_a_product()
259
    {
260
        $this->client->setAccessToken([
261
            'access_token'  => self::$access_token,
262
            'token_type'    => 'Bearer',
263
        ]);
264
 
265
        $this->client->setClient(
266
            $this->mock_http_client(
267
                $this->mockGetCatalogProductsResponse()
268
            )
269
        );
270
 
271
        $response = $this->client->showProductDetails(self::$product_id);
272
 
273
        $this->assertNotEmpty($response);
274
        $this->assertArrayHasKey('id', $response);
275
    }
276
 
277
    /** @test */
278
    public function it_can_list_disputes()
279
    {
280
        $this->client->setAccessToken([
281
            'access_token'  => self::$access_token,
282
            'token_type'    => 'Bearer',
283
        ]);
284
 
285
        $this->client->setClient(
286
            $this->mock_http_client(
287
                $this->mockListDisputesResponse()
288
            )
289
        );
290
 
291
        $response = $this->client->listDisputes();
292
 
293
        $this->assertNotEmpty($response);
294
        $this->assertArrayHasKey('items', $response);
295
    }
296
 
297
    /** @test */
298
    public function it_can_partially_update_a_dispute()
299
    {
300
        $this->client->setAccessToken([
301
            'access_token'  => self::$access_token,
302
            'token_type'    => 'Bearer',
303
        ]);
304
 
305
        $this->client->setClient(
306
            $this->mock_http_client(false)
307
        );
308
 
309
        $expectedParams = $this->updateDisputeParams();
310
 
311
        $response = $this->client->updateDispute($expectedParams, 'PP-D-27803');
312
 
313
        $this->assertEmpty($response);
314
    }
315
 
316
    /** @test */
317
    public function it_can_get_details_for_a_dispute()
318
    {
319
        $this->client->setAccessToken([
320
            'access_token'  => self::$access_token,
321
            'token_type'    => 'Bearer',
322
        ]);
323
 
324
        $this->client->setClient(
325
            $this->mock_http_client(
326
                $this->mockGetDisputesResponse()
327
            )
328
        );
329
 
330
        $response = $this->client->showDisputeDetails('PP-D-4012');
331
 
332
        $this->assertNotEmpty($response);
333
        $this->assertArrayHasKey('dispute_id', $response);
334
    }
335
 
336
    /** @test */
337
    public function it_can_accept_dispute_claim()
338
    {
339
        $this->client->setAccessToken([
340
            'access_token'  => self::$access_token,
341
            'token_type'    => 'Bearer',
342
        ]);
343
 
344
        $this->client->setClient(
345
            $this->mock_http_client(
346
                $this->mockAcceptDisputesClaimResponse()
347
            )
348
        );
349
 
350
        $response = $this->client->acceptDisputeClaim(
351
            'PP-D-4012',
352
            'Full refund to the customer.'
353
        );
354
 
355
        $this->assertNotEmpty($response);
356
        $this->assertArrayHasKey('links', $response);
357
    }
358
 
359
    /** @test */
360
    public function it_can_accept_dispute_offer_resolution()
361
    {
362
        $this->client->setAccessToken([
363
            'access_token'  => self::$access_token,
364
            'token_type'    => 'Bearer',
365
        ]);
366
 
367
        $this->client->setClient(
368
            $this->mock_http_client(
369
                $this->mockAcceptDisputesClaimResponse()
370
            )
371
        );
372
 
373
        $response = $this->client->acceptDisputeOfferResolution(
374
            'PP-D-4012',
375
            'I am ok with the refund offered.'
376
        );
377
 
378
        $this->assertNotEmpty($response);
379
        $this->assertArrayHasKey('links', $response);
380
    }
381
 
382
    /** @test */
383
    public function it_can_acknowledge_item_is_returned_for_raised_dispute()
384
    {
385
        $this->client->setAccessToken([
386
            'access_token'  => self::$access_token,
387
            'token_type'    => 'Bearer',
388
        ]);
389
 
390
        $this->client->setClient(
391
            $this->mock_http_client(
392
                $this->mockAcceptDisputesClaimResponse()
393
            )
394
        );
395
 
396
        $response = $this->client->acknowledgeItemReturned(
397
            'PP-D-4012',
398
            'I have received the item back.',
399
            'ITEM_RECEIVED'
400
        );
401
 
402
        $this->assertNotEmpty($response);
403
        $this->assertArrayHasKey('links', $response);
404
    }
405
 
406
    /** @test */
407
    public function it_can_generate_unique_invoice_number()
408
    {
409
        $this->client->setAccessToken([
410
            'access_token'  => self::$access_token,
411
            'token_type'    => 'Bearer',
412
        ]);
413
 
414
        $this->client->setClient(
415
            $this->mock_http_client(
416
                $this->mockGenerateInvoiceNumberResponse()
417
            )
418
        );
419
 
420
        $response = $this->client->generateInvoiceNumber();
421
 
422
        $this->assertNotEmpty($response);
423
        $this->assertArrayHasKey('invoice_number', $response);
424
    }
425
 
426
    /** @test */
427
    public function it_can_create_a_draft_invoice()
428
    {
429
        $this->client->setAccessToken([
430
            'access_token'  => self::$access_token,
431
            'token_type'    => 'Bearer',
432
        ]);
433
 
434
        $this->client->setClient(
435
            $this->mock_http_client(
436
                $this->mockCreateInvoicesResponse()
437
            )
438
        );
439
 
440
        $expectedParams = $this->createInvoiceParams();
441
 
442
        $response = $this->client->createInvoice($expectedParams);
443
 
444
        $this->assertNotEmpty($response);
445
        $this->assertArrayHasKey('id', $response);
446
    }
447
 
448
    /** @test */
449
    public function it_can_list_invoices()
450
    {
451
        $this->client->setAccessToken([
452
            'access_token'  => self::$access_token,
453
            'token_type'    => 'Bearer',
454
        ]);
455
 
456
        $this->client->setClient(
457
            $this->mock_http_client(
458
                $this->mockListInvoicesResponse()
459
            )
460
        );
461
 
462
        $response = $this->client->listInvoices();
463
 
464
        $this->assertArrayHasKey('total_pages', $response);
465
        $this->assertArrayHasKey('total_items', $response);
466
    }
467
 
468
    /** @test */
469
    public function it_can_delete_an_invoice()
470
    {
471
        $this->client->setAccessToken([
472
            'access_token'  => self::$access_token,
473
            'token_type'    => 'Bearer',
474
        ]);
475
 
476
        $this->client->setClient(
477
            $this->mock_http_client(false)
478
        );
479
 
480
        $response = $this->client->deleteInvoice('INV2-Z56S-5LLA-Q52L-CPZ5');
481
 
482
        $this->assertEmpty($response);
483
    }
484
 
485
    /** @test */
486
    public function it_can_update_an_invoice()
487
    {
488
        $this->client->setAccessToken([
489
            'access_token'  => self::$access_token,
490
            'token_type'    => 'Bearer',
491
        ]);
492
 
493
        $this->client->setClient(
494
            $this->mock_http_client(
495
                $this->mockUpdateInvoicesResponse()
496
            )
497
        );
498
 
499
        $expectedParams = $this->updateInvoiceParams();
500
 
501
        $response = $this->client->updateInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', $expectedParams);
502
 
503
        $this->assertNotEmpty($response);
504
        $this->assertArrayHasKey('id', $response);
505
    }
506
 
507
    /** @test */
508
    public function it_can_show_details_for_an_invoice()
509
    {
510
        $this->client->setAccessToken([
511
            'access_token'  => self::$access_token,
512
            'token_type'    => 'Bearer',
513
        ]);
514
 
515
        $this->client->setClient(
516
            $this->mock_http_client(
517
                $this->mockGetInvoicesResponse()
518
            )
519
        );
520
 
521
        $response = $this->client->showInvoiceDetails('INV2-Z56S-5LLA-Q52L-CPZ5');
522
 
523
        $this->assertNotEmpty($response);
524
        $this->assertArrayHasKey('id', $response);
525
    }
526
 
527
    /** @test */
528
    public function it_can_cancel_an_invoice()
529
    {
530
        $this->client->setAccessToken([
531
            'access_token'  => self::$access_token,
532
            'token_type'    => 'Bearer',
533
        ]);
534
 
535
        $this->client->setClient(
536
            $this->mock_http_client(false)
537
        );
538
 
539
        $expectedParams = $this->cancelInvoiceParams();
540
 
541
        $response = $this->client->cancelInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', $expectedParams);
542
 
543
        $this->assertEmpty($response);
544
    }
545
 
546
    /** @test */
547
    public function it_can_generate_qr_code_for_invoice()
548
    {
549
        $this->client->setAccessToken([
550
            'access_token'  => self::$access_token,
551
            'token_type'    => 'Bearer',
552
        ]);
553
 
554
        $this->client->setClient(
555
            $this->mock_http_client(
556
                $this->mockGenerateInvoiceQRCodeResponse()
557
            )
558
        );
559
 
560
        $response = $this->client->generateQRCodeInvoice('INV2-Z56S-5LLA-Q52L-CPZ5');
561
 
562
        $this->assertNotEmpty($response);
563
    }
564
 
565
    /** @test */
566
    public function it_can_register_payment_for_invoice()
567
    {
568
        $this->client->setAccessToken([
569
            'access_token'  => self::$access_token,
570
            'token_type'    => 'Bearer',
571
        ]);
572
 
573
        $this->client->setClient(
574
            $this->mock_http_client(
575
                $this->mockInvoiceRegisterPaymentResponse()
576
            )
577
        );
578
 
579
        $response = $this->client->registerPaymentInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 10.00);
580
 
581
        $this->assertNotEmpty($response);
582
        $this->assertArrayHasKey('payment_id', $response);
583
    }
584
 
585
    /** @test */
586
    public function it_can_delete_payment_for_invoice()
587
    {
588
        $this->client->setAccessToken([
589
            'access_token'  => self::$access_token,
590
            'token_type'    => 'Bearer',
591
        ]);
592
 
593
        $this->client->setClient(
594
            $this->mock_http_client(false)
595
        );
596
 
597
        $response = $this->client->deleteExternalPaymentInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-86F38350LX4353815');
598
 
599
        $this->assertEmpty($response);
600
    }
601
 
602
    /** @test */
603
    public function it_can_refund_payment_for_invoice()
604
    {
605
        $this->client->setAccessToken([
606
            'access_token'  => self::$access_token,
607
            'token_type'    => 'Bearer',
608
        ]);
609
 
610
        $this->client->setClient(
611
            $this->mock_http_client(
612
                $this->mockInvoiceRefundPaymentResponse()
613
            )
614
        );
615
 
616
        $response = $this->client->refundInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 5.00);
617
 
618
        $this->assertNotEmpty($response);
619
        $this->assertArrayHasKey('refund_id', $response);
620
    }
621
 
622
    /** @test */
623
    public function it_can_delete_refund_for_invoice()
624
    {
625
        $this->client->setAccessToken([
626
            'access_token'  => self::$access_token,
627
            'token_type'    => 'Bearer',
628
        ]);
629
 
630
        $this->client->setClient(
631
            $this->mock_http_client(false)
632
        );
633
 
634
        $response = $this->client->deleteRefundInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-2LG703375E477444T');
635
 
636
        $this->assertEmpty($response);
637
    }
638
 
639
    /** @test */
640
    public function it_can_send_an_invoice()
641
    {
642
        $this->client->setAccessToken([
643
            'access_token'  => self::$access_token,
644
            'token_type'    => 'Bearer',
645
        ]);
646
 
647
        $this->client->setClient(
648
            $this->mock_http_client(false)
649
        );
650
 
651
        $response = $this->client->sendInvoice(
652
            'INV2-Z56S-5LLA-Q52L-CPZ5',
653
            'Payment due for the invoice #ABC-123',
654
            'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.',
655
            true,
656
            true,
657
            [
658
                'customer-a@example.com',
659
                'customer@example.com',
660
            ]
661
        );
662
 
663
        $this->assertEmpty($response);
664
    }
665
 
666
    /** @test */
667
    public function it_can_send_reminder_for_an_invoice()
668
    {
669
        $this->client->setAccessToken([
670
            'access_token'  => self::$access_token,
671
            'token_type'    => 'Bearer',
672
        ]);
673
 
674
        $this->client->setClient(
675
            $this->mock_http_client(false)
676
        );
677
 
678
        $response = $this->client->sendInvoiceReminder(
679
            'INV2-Z56S-5LLA-Q52L-CPZ5',
680
            'Reminder: Payment due for the invoice #ABC-123',
681
            'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.',
682
            true,
683
            true,
684
            [
685
                'customer-a@example.com',
686
                'customer@example.com',
687
            ]
688
        );
689
 
690
        $this->assertEmpty($response);
691
    }
692
 
693
    /** @test */
694
    public function it_can_create_invoice_template()
695
    {
696
        $this->client->setAccessToken([
697
            'access_token'  => self::$access_token,
698
            'token_type'    => 'Bearer',
699
        ]);
700
 
701
        $this->client->setClient(
702
            $this->mock_http_client(
703
                $this->mockCreateInvoiceTemplateResponse()
704
            )
705
        );
706
 
707
        $expectedParams = $this->mockCreateInvoiceTemplateParams();
708
 
709
        $response = $this->client->createInvoiceTemplate($expectedParams);
710
 
711
        $this->assertNotEmpty($response);
712
        $this->assertArrayHasKey('id', $response);
713
    }
714
 
715
    /** @test */
716
    public function it_can_list_invoice_templates()
717
    {
718
        $this->client->setAccessToken([
719
            'access_token'  => self::$access_token,
720
            'token_type'    => 'Bearer',
721
        ]);
722
 
723
        $this->client->setClient(
724
            $this->mock_http_client(
725
                $this->mockListInvoiceTemplateResponse()
726
            )
727
        );
728
 
729
        $response = $this->client->listInvoiceTemplates();
730
 
731
        $this->assertNotEmpty($response);
732
        $this->assertArrayHasKey('templates', $response);
733
    }
734
 
735
    /** @test */
736
    public function it_can_delete_an_invoice_template()
737
    {
738
        $this->client->setAccessToken([
739
            'access_token'  => self::$access_token,
740
            'token_type'    => 'Bearer',
741
        ]);
742
 
743
        $this->client->setClient(
744
            $this->mock_http_client(false)
745
        );
746
 
747
        $response = $this->client->deleteInvoiceTemplate('TEMP-19V05281TU309413B');
748
 
749
        $this->assertEmpty($response);
750
    }
751
 
752
    /** @test */
753
    public function it_can_update_an_invoice_template()
754
    {
755
        $this->client->setAccessToken([
756
            'access_token'  => self::$access_token,
757
            'token_type'    => 'Bearer',
758
        ]);
759
 
760
        $this->client->setClient(
761
            $this->mock_http_client(
762
                $this->mockUpdateInvoiceTemplateResponse()
763
            )
764
        );
765
 
766
        $expectedParams = $this->mockUpdateInvoiceTemplateParams();
767
 
768
        $response = $this->client->updateInvoiceTemplate('TEMP-19V05281TU309413B', $expectedParams);
769
 
770
        $this->assertNotEmpty($response);
771
        $this->assertArrayHasKey('id', $response);
772
    }
773
 
774
    /** @test */
775
    public function it_can_get_details_for_an_invoice_template()
776
    {
777
        $this->client->setAccessToken([
778
            'access_token'  => self::$access_token,
779
            'token_type'    => 'Bearer',
780
        ]);
781
 
782
        $this->client->setClient(
783
            $this->mock_http_client(
784
                $this->mockGetInvoiceTemplateResponse()
785
            )
786
        );
787
 
788
        $response = $this->client->showInvoiceTemplateDetails('TEMP-19V05281TU309413B');
789
 
790
        $this->assertNotEmpty($response);
791
        $this->assertArrayHasKey('id', $response);
792
    }
793
 
794
    /** @test */
795
    public function it_can_search_invoices()
796
    {
797
        $this->client->setAccessToken([
798
            'access_token'  => self::$access_token,
799
            'token_type'    => 'Bearer',
800
        ]);
801
 
802
        $this->client->setClient(
803
            $this->mock_http_client(
804
                $this->mockSearchInvoicesResponse()
805
            )
806
        );
807
 
808
        $response = $this->client->searchInvoices();
809
 
810
        $this->assertArrayHasKey('total_pages', $response);
811
        $this->assertArrayHasKey('total_items', $response);
812
    }
813
 
814
    /** @test */
815
    public function it_can_search_invoices_with_custom_filters()
816
    {
817
        $this->client->setAccessToken([
818
            'access_token'  => self::$access_token,
819
            'token_type'    => 'Bearer',
820
        ]);
821
 
822
        $this->client->setClient(
823
            $this->mock_http_client(
824
                $this->mockSearchInvoicesResponse()
825
            )
826
        );
827
 
828
        $response = $this->client
829
            ->addInvoiceFilterByRecipientEmail('bill-me@example.com')
830
            ->addInvoiceFilterByRecipientFirstName('John')
831
            ->addInvoiceFilterByRecipientLastName('Doe')
832
            ->addInvoiceFilterByRecipientBusinessName('Acme Inc.')
833
            ->addInvoiceFilterByInvoiceNumber('#123')
834
            ->addInvoiceFilterByInvoiceStatus(['PAID', 'MARKED_AS_PAID'])
835
            ->addInvoiceFilterByReferenceorMemo('deal-ref')
836
            ->addInvoiceFilterByCurrencyCode('USD')
837
            ->addInvoiceFilterByAmountRange(30, 50)
838
            ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'invoice_date')
839
            ->addInvoiceFilterByArchivedStatus(false)
840
            ->addInvoiceFilterByFields(['items', 'payments', 'refunds'])
841
            ->searchInvoices();
842
 
843
        $this->assertArrayHasKey('total_pages', $response);
844
        $this->assertArrayHasKey('total_items', $response);
845
        $this->assertArrayHasKey('items', $response);
846
    }
847
 
848
    /** @test */
849
    public function it_throws_exception_on_search_invoices_with_invalid_status()
850
    {
851
        $this->client->setAccessToken([
852
            'access_token'  => self::$access_token,
853
            'token_type'    => 'Bearer',
854
        ]);
855
 
856
        $this->client->setClient(
857
            $this->mock_http_client(
858
                $this->mockSearchInvoicesResponse()
859
            )
860
        );
861
 
862
        $this->expectException(\Exception::class);
863
 
864
        $response = $this->client
865
            ->addInvoiceFilterByInvoiceStatus(['DECLINED'])
866
            ->searchInvoices();
867
    }
868
 
869
    /** @test */
870
    public function it_throws_exception_on_search_invoices_with_invalid_amount_ranges()
871
    {
872
        $this->client->setAccessToken([
873
            'access_token'  => self::$access_token,
874
            'token_type'    => 'Bearer',
875
        ]);
876
 
877
        $this->client->setClient(
878
            $this->mock_http_client(
879
                $this->mockSearchInvoicesResponse()
880
            )
881
        );
882
 
883
        $filters = $this->invoiceSearchParams();
884
 
885
        $this->expectException(\Exception::class);
886
 
887
        $response = $this->client
888
            ->addInvoiceFilterByAmountRange(50, 30)
889
            ->searchInvoices();
890
    }
891
 
892
    /** @test */
893
    public function it_throws_exception_on_search_invoices_with_invalid_date_ranges()
894
    {
895
        $this->client->setAccessToken([
896
            'access_token'  => self::$access_token,
897
            'token_type'    => 'Bearer',
898
        ]);
899
 
900
        $this->client->setClient(
901
            $this->mock_http_client(
902
                $this->mockSearchInvoicesResponse()
903
            )
904
        );
905
 
906
        $filters = $this->invoiceSearchParams();
907
 
908
        $this->expectException(\Exception::class);
909
 
910
        $response = $this->client
911
            ->addInvoiceFilterByDateRange('2018-07-01', '2018-06-21', 'invoice_date')
912
            ->searchInvoices();
913
    }
914
 
915
    /** @test */
916
    public function it_throws_exception_on_search_invoices_with_invalid_date_range_type()
917
    {
918
        $this->client->setAccessToken([
919
            'access_token'  => self::$access_token,
920
            'token_type'    => 'Bearer',
921
        ]);
922
 
923
        $this->client->setClient(
924
            $this->mock_http_client(
925
                $this->mockSearchInvoicesResponse()
926
            )
927
        );
928
 
929
        $filters = $this->invoiceSearchParams();
930
 
931
        $this->expectException(\Exception::class);
932
 
933
        $response = $this->client
934
            ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'declined_date')
935
            ->searchInvoices();
936
    }
937
 
938
    /** @test */
939
    public function it_can_get_user_profile_details()
940
    {
941
        $this->client->setAccessToken([
942
            'access_token'  => self::$access_token,
943
            'token_type'    => 'Bearer',
944
        ]);
945
 
946
        $this->client->setClient(
947
            $this->mock_http_client(
948
                $this->mockShowProfileInfoResponse()
949
            )
950
        );
951
 
952
        $response = $this->client->showProfileInfo();
953
 
954
        $this->assertArrayHasKey('user_id', $response);
955
        $this->assertArrayHasKey('payer_id', $response);
956
        $this->assertArrayHasKey('emails', $response);
957
    }
958
 
959
    /** @test */
960
    public function it_can_create_merchant_applications()
961
    {
962
        $this->client->setAccessToken([
963
            'access_token'  => self::$access_token,
964
            'token_type'    => 'Bearer',
965
        ]);
966
 
967
        $this->client->setClient(
968
            $this->mock_http_client(
969
                $this->mockCreateMerchantApplicationResponse()
970
            )
971
        );
972
 
973
        $response = $this->client->createMerchantApplication(
974
            'AGGREGATOR',
975
            [
976
                'https://example.com/callback',
977
                'https://example.com/callback2',
978
            ],
979
            [
980
                'facilitator@example.com',
981
                'merchant@example.com',
982
            ],
983
            'WDJJHEBZ4X2LY',
984
            'some-open-id'
985
        );
986
 
987
        $this->assertArrayHasKey('client_name', $response);
988
        $this->assertArrayHasKey('contacts', $response);
989
        $this->assertArrayHasKey('redirect_uris', $response);
990
    }
991
 
992
    /** @test */
993
    public function it_can_set_account_properties()
994
    {
995
        $this->client->setAccessToken([
996
            'access_token'  => self::$access_token,
997
            'token_type'    => 'Bearer',
998
        ]);
999
 
1000
        $this->client->setClient(
1001
            $this->mock_http_client('')
1002
        );
1003
 
1004
        $response = $this->client->setAccountProperties($this->mockSetAccountPropertiesParams());
1005
 
1006
        $this->assertEmpty($response);
1007
    }
1008
 
1009
    /** @test */
1010
    public function it_can_disable_account_properties()
1011
    {
1012
        $this->client->setAccessToken([
1013
            'access_token'  => self::$access_token,
1014
            'token_type'    => 'Bearer',
1015
        ]);
1016
 
1017
        $this->client->setClient(
1018
            $this->mock_http_client(
1019
                $this->mockUpdateOrdersResponse()
1020
            )
1021
        );
1022
 
1023
        $response = $this->client->disableAccountProperties();
1024
 
1025
        $this->assertEmpty($response);
1026
    }
1027
 
1028
    /** @test */
1029
    public function it_can_get_client_token()
1030
    {
1031
        $this->client->setAccessToken([
1032
            'access_token'  => self::$access_token,
1033
            'token_type'    => 'Bearer',
1034
        ]);
1035
 
1036
        $this->client->setClient(
1037
            $this->mock_http_client(
1038
                $this->mockGetClientTokenResponse()
1039
            )
1040
        );
1041
 
1042
        $response = $this->client->getClientToken();
1043
 
1044
        $this->assertArrayHasKey('client_token', $response);
1045
    }
1046
 
1047
    /** @test  */
1048
    public function it_can_create_orders()
1049
    {
1050
        $this->client->setAccessToken([
1051
            'access_token'  => self::$access_token,
1052
            'token_type'    => 'Bearer',
1053
        ]);
1054
 
1055
        $this->client->setClient(
1056
            $this->mock_http_client(
1057
                $this->mockCreateOrdersResponse()
1058
            )
1059
        );
1060
 
1061
        $filters = $this->createOrderParams();
1062
 
1063
        $response = $this->client->createOrder($filters);
1064
 
1065
        $this->assertArrayHasKey('status', $response);
1066
        $this->assertArrayHasKey('id', $response);
1067
        $this->assertArrayHasKey('links', $response);
1068
    }
1069
 
1070
    /** @test  */
1071
    public function it_can_update_orders()
1072
    {
1073
        $this->client->setAccessToken([
1074
            'access_token'  => self::$access_token,
1075
            'token_type'    => 'Bearer',
1076
        ]);
1077
 
1078
        $this->client->setClient(
1079
            $this->mock_http_client(
1080
                $this->mockUpdateOrdersResponse()
1081
            )
1082
        );
1083
 
1084
        $order_id = '5O190127TN364715T';
1085
        $filters = $this->updateOrderParams();
1086
 
1087
        $response = $this->client->updateOrder($order_id, $filters);
1088
 
1089
        $this->assertNotEmpty($response);
1090
    }
1091
 
1092
    /** @test  */
1093
    public function it_can_get_order_details()
1094
    {
1095
        $this->client->setAccessToken([
1096
            'access_token'  => self::$access_token,
1097
            'token_type'    => 'Bearer',
1098
        ]);
1099
 
1100
        $this->client->setClient(
1101
            $this->mock_http_client(
1102
                $this->mockOrderDetailsResponse()
1103
            )
1104
        );
1105
 
1106
        $order_id = '5O190127TN364715T';
1107
        $response = $this->client->showOrderDetails($order_id);
1108
 
1109
        $this->assertArrayHasKey('status', $response);
1110
        $this->assertArrayHasKey('id', $response);
1111
        $this->assertArrayHasKey('intent', $response);
1112
        $this->assertArrayHasKey('payment_source', $response);
1113
        $this->assertArrayHasKey('purchase_units', $response);
1114
        $this->assertArrayHasKey('create_time', $response);
1115
        $this->assertArrayHasKey('links', $response);
1116
    }
1117
 
1118
    /** @test  */
1119
    public function it_can_authorize_payment_for_an_order()
1120
    {
1121
        $this->client->setAccessToken([
1122
            'access_token'  => self::$access_token,
1123
            'token_type'    => 'Bearer',
1124
        ]);
1125
 
1126
        $this->client->setClient(
1127
            $this->mock_http_client(
1128
                $this->mockOrderPaymentAuthorizedResponse()
1129
            )
1130
        );
1131
 
1132
        $order_id = '5O190127TN364715T';
1133
        $response = $this->client->authorizePaymentOrder($order_id);
1134
 
1135
        $this->assertArrayHasKey('status', $response);
1136
        $this->assertArrayHasKey('id', $response);
1137
        $this->assertArrayHasKey('payer', $response);
1138
        $this->assertArrayHasKey('purchase_units', $response);
1139
        $this->assertArrayHasKey('links', $response);
1140
    }
1141
 
1142
    /** @test */
1143
    public function it_can_create_partner_referral()
1144
    {
1145
        $this->client->setAccessToken([
1146
            'access_token'  => self::$access_token,
1147
            'token_type'    => 'Bearer',
1148
        ]);
1149
 
1150
        $this->client->setClient(
1151
            $this->mock_http_client(
1152
                $this->mockCreatePartnerReferralsResponse()
1153
            )
1154
        );
1155
 
1156
        $expectedParams = $this->mockCreatePartnerReferralParams();
1157
 
1158
        $response = $this->client->createPartnerReferral($expectedParams);
1159
 
1160
        $this->assertArrayHasKey('links', $response);
1161
    }
1162
 
1163
    /** @test */
1164
    public function it_can_get_referral_details()
1165
    {
1166
        $this->client->setAccessToken([
1167
            'access_token'  => self::$access_token,
1168
            'token_type'    => 'Bearer',
1169
        ]);
1170
 
1171
        $this->client->setClient(
1172
            $this->mock_http_client(
1173
                $this->mockShowReferralDataResponse()
1174
            )
1175
        );
1176
 
1177
        $partner_referral_id = 'ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0=';
1178
 
1179
        $response = $this->client->showReferralData($partner_referral_id);
1180
 
1181
        $this->assertArrayHasKey('partner_referral_id', $response);
1182
        $this->assertArrayHasKey('referral_data', $response);
1183
    }
1184
 
1185
    /** @test */
1186
    public function it_can_list_web_experience_profiles()
1187
    {
1188
        $this->client->setAccessToken([
1189
            'access_token'  => self::$access_token,
1190
            'token_type'    => 'Bearer',
1191
        ]);
1192
 
1193
        $this->client->setClient(
1194
            $this->mock_http_client(
1195
                $this->mockListWebProfilesResponse()
1196
            )
1197
        );
1198
 
1199
        $response = $this->client->listWebExperienceProfiles();
1200
 
1201
        $this->assertNotEmpty($response);
1202
        $this->assertArrayHasKey('id', collect($response)->first());
1203
    }
1204
 
1205
    /** @test */
1206
    public function it_can_create_web_experience_profile()
1207
    {
1208
        $this->client->setAccessToken([
1209
            'access_token'  => self::$access_token,
1210
            'token_type'    => 'Bearer',
1211
        ]);
1212
 
1213
        $this->client->setClient(
1214
            $this->mock_http_client(
1215
                $this->mockWebProfileResponse()
1216
            )
1217
        );
1218
 
1219
        $expectedParams = $this->mockCreateWebProfileParams();
1220
 
1221
        $response = $this->client->createWebExperienceProfile($expectedParams, 'some-request-id');
1222
 
1223
        $this->assertNotEmpty($response);
1224
        $this->assertArrayHasKey('name', $response);
1225
    }
1226
 
1227
    /** @test */
1228
    public function it_can_delete_web_experience_profile()
1229
    {
1230
        $expectedResponse = '';
1231
 
1232
        $this->client->setAccessToken([
1233
            'access_token'  => self::$access_token,
1234
            'token_type'    => 'Bearer',
1235
        ]);
1236
 
1237
        $this->client->setClient(
1238
            $this->mock_http_client($expectedResponse)
1239
        );
1240
 
1241
        $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
1242
 
1243
        $response = $this->client->deleteWebExperienceProfile($expectedParams);
1244
 
1245
        $this->assertEmpty($response);
1246
    }
1247
 
1248
    /** @test */
1249
    public function it_can_partially_update_web_experience_profile()
1250
    {
1251
        $expectedResponse = '';
1252
 
1253
        $expectedParams = $this->partiallyUpdateWebProfileParams();
1254
 
1255
        $this->client->setAccessToken([
1256
            'access_token'  => self::$access_token,
1257
            'token_type'    => 'Bearer',
1258
        ]);
1259
 
1260
        $this->client->setClient(
1261
            $this->mock_http_client($expectedResponse)
1262
        );
1263
 
1264
        $response = $this->client->patchWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams);
1265
 
1266
        $this->assertEmpty($response);
1267
    }
1268
 
1269
    /** @test */
1270
    public function it_can_fully_update_web_experience_profile()
1271
    {
1272
        $expectedResponse = '';
1273
 
1274
        $expectedParams = $this->updateWebProfileParams();
1275
 
1276
        $this->client->setAccessToken([
1277
            'access_token'  => self::$access_token,
1278
            'token_type'    => 'Bearer',
1279
        ]);
1280
 
1281
        $this->client->setClient(
1282
            $this->mock_http_client($expectedResponse)
1283
        );
1284
 
1285
        $response = $this->client->updateWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams);
1286
 
1287
        $this->assertEmpty($response);
1288
    }
1289
 
1290
    /** @test */
1291
    public function it_can_get_web_experience_profile_details()
1292
    {
1293
        $expectedResponse = $this->mockWebProfileResponse();
1294
 
1295
        $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
1296
 
1297
        $this->client->setAccessToken([
1298
            'access_token'  => self::$access_token,
1299
            'token_type'    => 'Bearer',
1300
        ]);
1301
 
1302
        $this->client->setClient(
1303
            $this->mock_http_client($expectedResponse)
1304
        );
1305
 
1306
        $response = $this->client->showWebExperienceProfileDetails($expectedParams);
1307
 
1308
        $this->assertNotEmpty($response);
1309
        $this->assertArrayHasKey('name', $response);
1310
    }
1311
 
1312
    /** @test  */
1313
    public function it_can_capture_payment_for_an_order()
1314
    {
1315
        $this->client->setAccessToken([
1316
            'access_token'  => self::$access_token,
1317
            'token_type'    => 'Bearer',
1318
        ]);
1319
 
1320
        $this->client->setClient(
1321
            $this->mock_http_client(
1322
                $this->mockOrderPaymentCapturedResponse()
1323
            )
1324
        );
1325
 
1326
        $order_id = '5O190127TN364715T';
1327
        $response = $this->client->capturePaymentOrder($order_id);
1328
 
1329
        $this->assertArrayHasKey('status', $response);
1330
        $this->assertArrayHasKey('id', $response);
1331
        $this->assertArrayHasKey('payer', $response);
1332
        $this->assertArrayHasKey('purchase_units', $response);
1333
        $this->assertArrayHasKey('links', $response);
1334
    }
1335
 
1336
    /** @test */
1337
    public function it_can_show_details_for_an_authorized_payment()
1338
    {
1339
        $this->client->setAccessToken([
1340
            'access_token'  => self::$access_token,
1341
            'token_type'    => 'Bearer',
1342
        ]);
1343
 
1344
        $this->client->setClient(
1345
            $this->mock_http_client(
1346
                $this->mockGetAuthorizedPaymentDetailsResponse()
1347
            )
1348
        );
1349
 
1350
        $response = $this->client->showAuthorizedPaymentDetails('0VF52814937998046');
1351
 
1352
        $this->assertNotEmpty($response);
1353
        $this->assertArrayHasKey('id', $response);
1354
    }
1355
 
1356
    /** @test */
1357
    public function it_can_capture_an_authorized_payment()
1358
    {
1359
        $this->client->setAccessToken([
1360
            'access_token'  => self::$access_token,
1361
            'token_type'    => 'Bearer',
1362
        ]);
1363
 
1364
        $this->client->setClient(
1365
            $this->mock_http_client(
1366
                $this->mockCaptureAuthorizedPaymentResponse()
1367
            )
1368
        );
1369
 
1370
        $response = $this->client->captureAuthorizedPayment(
1371
            '0VF52814937998046',
1372
            'INVOICE-123',
1373
            10.99,
1374
            'Payment is due'
1375
        );
1376
 
1377
        $this->assertNotEmpty($response);
1378
        $this->assertArrayHasKey('id', $response);
1379
    }
1380
 
1381
    /** @test */
1382
    public function it_can_reauthorize_an_authorized_payment()
1383
    {
1384
        $this->client->setAccessToken([
1385
            'access_token'  => self::$access_token,
1386
            'token_type'    => 'Bearer',
1387
        ]);
1388
 
1389
        $this->client->setClient(
1390
            $this->mock_http_client(
1391
                $this->mockReAuthorizeAuthorizedPaymentResponse()
1392
            )
1393
        );
1394
 
1395
        $response = $this->client->reAuthorizeAuthorizedPayment('0VF52814937998046', 10.99);
1396
 
1397
        $this->assertNotEmpty($response);
1398
        $this->assertArrayHasKey('id', $response);
1399
    }
1400
 
1401
    /** @test */
1402
    public function it_can_void_an_authorized_payment()
1403
    {
1404
        $this->client->setAccessToken([
1405
            'access_token'  => self::$access_token,
1406
            'token_type'    => 'Bearer',
1407
        ]);
1408
 
1409
        $this->client->setClient(
1410
            $this->mock_http_client(false)
1411
        );
1412
 
1413
        $response = $this->client->voidAuthorizedPayment('0VF52814937998046');
1414
 
1415
        $this->assertEmpty($response);
1416
    }
1417
 
1418
    /** @test */
1419
    public function it_can_show_details_for_a_captured_payment()
1420
    {
1421
        $this->client->setAccessToken([
1422
            'access_token'  => self::$access_token,
1423
            'token_type'    => 'Bearer',
1424
        ]);
1425
 
1426
        $this->client->setClient(
1427
            $this->mock_http_client(
1428
                $this->mockGetCapturedPaymentDetailsResponse()
1429
            )
1430
        );
1431
 
1432
        $response = $this->client->showCapturedPaymentDetails('2GG279541U471931P');
1433
 
1434
        $this->assertNotEmpty($response);
1435
        $this->assertArrayHasKey('id', $response);
1436
    }
1437
 
1438
    /** @test */
1439
    public function it_can_refund_a_captured_payment()
1440
    {
1441
        $this->client->setAccessToken([
1442
            'access_token'  => self::$access_token,
1443
            'token_type'    => 'Bearer',
1444
        ]);
1445
 
1446
        $this->client->setClient(
1447
            $this->mock_http_client(
1448
                $this->mockRefundCapturedPaymentResponse()
1449
            )
1450
        );
1451
 
1452
        $response = $this->client->refundCapturedPayment(
1453
            '2GG279541U471931P',
1454
            'INVOICE-123',
1455
            10.99,
1456
            'Defective product'
1457
        );
1458
 
1459
        $this->assertNotEmpty($response);
1460
        $this->assertArrayHasKey('id', $response);
1461
    }
1462
 
1463
    /** @test */
1464
    public function it_can_show_details_for_a_refund()
1465
    {
1466
        $this->client->setAccessToken([
1467
            'access_token'  => self::$access_token,
1468
            'token_type'    => 'Bearer',
1469
        ]);
1470
 
1471
        $this->client->setClient(
1472
            $this->mock_http_client(
1473
                $this->mockGetRefundDetailsResponse()
1474
            )
1475
        );
1476
 
1477
        $response = $this->client->showRefundDetails('1JU08902781691411');
1478
 
1479
        $this->assertNotEmpty($response);
1480
        $this->assertArrayHasKey('id', $response);
1481
    }
1482
 
1483
    /** @test */
1484
    public function it_can_create_batch_payout()
1485
    {
1486
        $expectedResponse = $this->mockCreateBatchPayoutResponse();
1487
 
1488
        $expectedParams = $this->mockCreateBatchPayoutParams();
1489
 
1490
        $this->client->setAccessToken([
1491
            'access_token'  => self::$access_token,
1492
            'token_type'    => 'Bearer',
1493
        ]);
1494
 
1495
        $this->client->setClient(
1496
            $this->mock_http_client($expectedResponse)
1497
        );
1498
 
1499
        $response = $this->client->createBatchPayout($expectedParams);
1500
 
1501
        $this->assertNotEmpty($response);
1502
        $this->assertArrayHasKey('batch_header', $response);
1503
    }
1504
 
1505
    /** @test */
1506
    public function it_can_show_batch_payout_details()
1507
    {
1508
        $expectedResponse = $this->showBatchPayoutResponse();
1509
 
1510
        $expectedParams = 'FYXMPQTX4JC9N';
1511
 
1512
        $this->client->setAccessToken([
1513
            'access_token'  => self::$access_token,
1514
            'token_type'    => 'Bearer',
1515
        ]);
1516
 
1517
        $this->client->setClient(
1518
            $this->mock_http_client($expectedResponse)
1519
        );
1520
 
1521
        $response = $this->client->showBatchPayoutDetails($expectedParams);
1522
 
1523
        $this->assertNotEmpty($response);
1524
        $this->assertArrayHasKey('batch_header', $response);
1525
        $this->assertArrayHasKey('items', $response);
1526
    }
1527
 
1528
    /** @test */
1529
    public function it_can_show_batch_payout_item_details()
1530
    {
1531
        $expectedResponse = $this->showBatchPayoutItemResponse();
1532
 
1533
        $expectedParams = '8AELMXH8UB2P8';
1534
 
1535
        $this->client->setAccessToken([
1536
            'access_token'  => self::$access_token,
1537
            'token_type'    => 'Bearer',
1538
        ]);
1539
 
1540
        $this->client->setClient(
1541
            $this->mock_http_client($expectedResponse)
1542
        );
1543
 
1544
        $response = $this->client->showPayoutItemDetails($expectedParams);
1545
 
1546
        $this->assertNotEmpty($response);
1547
        $this->assertArrayHasKey('payout_item_id', $response);
1548
        $this->assertArrayHasKey('payout_batch_id', $response);
1549
        $this->assertArrayHasKey('payout_item', $response);
1550
    }
1551
 
1552
    /** @test */
1553
    public function it_can_cancel_unclaimed_batch_payout_item()
1554
    {
1555
        $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse();
1556
 
1557
        $expectedParams = '8AELMXH8UB2P8';
1558
 
1559
        $this->client->setAccessToken([
1560
            'access_token'  => self::$access_token,
1561
            'token_type'    => 'Bearer',
1562
        ]);
1563
 
1564
        $this->client->setClient(
1565
            $this->mock_http_client($expectedResponse)
1566
        );
1567
 
1568
        $response = $this->client->cancelUnclaimedPayoutItem($expectedParams);
1569
 
1570
        $this->assertNotEmpty($response);
1571
        $this->assertArrayHasKey('payout_item_id', $response);
1572
        $this->assertArrayHasKey('payout_batch_id', $response);
1573
        $this->assertArrayHasKey('payout_item', $response);
1574
    }
1575
 
1576
    /** @test */
1577
    public function it_can_create_referenced_batch_payout()
1578
    {
1579
        $expectedResponse = $this->mockCreateReferencedBatchPayoutResponse();
1580
 
1581
        $expectedParams = $this->mockCreateReferencedBatchPayoutParams();
1582
 
1583
        $this->client->setAccessToken([
1584
            'access_token'  => self::$access_token,
1585
            'token_type'    => 'Bearer',
1586
        ]);
1587
 
1588
        $this->client->setClient(
1589
            $this->mock_http_client($expectedResponse)
1590
        );
1591
 
1592
        $response = $this->client->createReferencedBatchPayout($expectedParams, 'some-request-id', 'some-attribution-id');
1593
 
1594
        $this->assertNotEmpty($response);
1595
        $this->assertArrayHasKey('links', $response);
1596
    }
1597
 
1598
    /** @test */
1599
    public function it_can_list_items_referenced_in_batch_payout()
1600
    {
1601
        $expectedResponse = $this->mockShowReferencedBatchPayoutResponse();
1602
 
1603
        $expectedParams = 'KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E=';
1604
 
1605
        $this->client->setAccessToken([
1606
            'access_token'  => self::$access_token,
1607
            'token_type'    => 'Bearer',
1608
        ]);
1609
 
1610
        $this->client->setClient(
1611
            $this->mock_http_client($expectedResponse)
1612
        );
1613
 
1614
        $response = $this->client->listItemsReferencedInBatchPayout($expectedParams);
1615
 
1616
        $this->assertNotEmpty($response);
1617
        $this->assertArrayHasKey('links', $response);
1618
    }
1619
 
1620
    /** @test */
1621
    public function it_can_create_referenced_batch_payout_item()
1622
    {
1623
        $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse();
1624
 
1625
        $expectedParams = $this->mockCreateReferencedBatchPayoutItemParams();
1626
 
1627
        $this->client->setAccessToken([
1628
            'access_token'  => self::$access_token,
1629
            'token_type'    => 'Bearer',
1630
        ]);
1631
 
1632
        $this->client->setClient(
1633
            $this->mock_http_client($expectedResponse)
1634
        );
1635
 
1636
        $response = $this->client->createReferencedBatchPayoutItem($expectedParams, 'some-request-id', 'some-attribution-id');
1637
 
1638
        $this->assertNotEmpty($response);
1639
        $this->assertArrayHasKey('links', $response);
1640
    }
1641
 
1642
    /** @test */
1643
    public function it_can_show_referenced_payout_item_details()
1644
    {
1645
        $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse();
1646
 
1647
        $expectedParams = 'CDZEC5MJ8R5HY';
1648
 
1649
        $this->client->setAccessToken([
1650
            'access_token'  => self::$access_token,
1651
            'token_type'    => 'Bearer',
1652
        ]);
1653
 
1654
        $this->client->setClient(
1655
            $this->mock_http_client($expectedResponse)
1656
        );
1657
 
1658
        $response = $this->client->showReferencedPayoutItemDetails($expectedParams, 'some-attribution-id');
1659
 
1660
        $this->assertNotEmpty($response);
1661
        $this->assertArrayHasKey('item_id', $response);
1662
        $this->assertArrayHasKey('reference_id', $response);
1663
    }
1664
 
1665
    /** @test */
1666
    public function it_can_list_transactions()
1667
    {
1668
        $this->client->setAccessToken([
1669
            'access_token'  => self::$access_token,
1670
            'token_type'    => 'Bearer',
1671
        ]);
1672
 
1673
        $this->client->setClient(
1674
            $this->mock_http_client(
1675
                $this->mockListTransactionsResponse()
1676
            )
1677
        );
1678
 
1679
        $filters = [
1680
            'start_date'    => Carbon::now()->toIso8601String(),
1681
            'end_date'      => Carbon::now()->subDays(30)->toIso8601String(),
1682
        ];
1683
 
1684
        $response = $this->client->listTransactions($filters);
1685
 
1686
        $this->assertArrayHasKey('transaction_details', $response);
1687
        $this->assertGreaterThan(0, sizeof($response['transaction_details']));
1688
    }
1689
 
1690
    /** @test */
1691
    public function it_can_list_account_balances()
1692
    {
1693
        $this->client->setAccessToken([
1694
            'access_token'  => self::$access_token,
1695
            'token_type'    => 'Bearer',
1696
        ]);
1697
 
1698
        $this->client->setClient(
1699
            $this->mock_http_client(
1700
                $this->mockListBalancesResponse()
1701
            )
1702
        );
1703
 
1704
        $date = Carbon::now()->subDays(30)->toIso8601String();
1705
 
1706
        $response = $this->client->listBalances($date);
1707
 
1708
        $this->assertNotEmpty($response);
1709
    }
1710
 
1711
    /** @test */
1712
    public function it_can_list_account_balances_for_a_different_currency()
1713
    {
1714
        $this->client->setAccessToken([
1715
            'access_token'  => self::$access_token,
1716
            'token_type'    => 'Bearer',
1717
        ]);
1718
 
1719
        $this->client->setClient(
1720
            $this->mock_http_client(
1721
                $this->mockListBalancesResponse()
1722
            )
1723
        );
1724
 
1725
        $date = Carbon::now()->subDays(30)->toIso8601String();
1726
 
1727
        $response = $this->client->listBalances($date, 'EUR');
1728
 
1729
        $this->assertNotEmpty($response);
1730
    }
1731
 
1732
    /** @test */
1733
    public function it_can_create_a_subscription()
1734
    {
1735
        $this->client->setAccessToken([
1736
            'access_token'  => self::$access_token,
1737
            'token_type'    => 'Bearer',
1738
        ]);
1739
 
1740
        $this->client->setClient(
1741
            $this->mock_http_client(
1742
                $this->mockCreateSubscriptionResponse()
1743
            )
1744
        );
1745
 
1746
        $expectedParams = $this->mockCreateSubscriptionParams();
1747
 
1748
        $response = $this->client->createSubscription($expectedParams);
1749
 
1750
        $this->assertNotEmpty($response);
1751
        $this->assertArrayHasKey('id', $response);
1752
    }
1753
 
1754
    /** @test */
1755
    public function it_can_update_a_subscription()
1756
    {
1757
        $this->client->setAccessToken([
1758
            'access_token'  => self::$access_token,
1759
            'token_type'    => 'Bearer',
1760
        ]);
1761
 
1762
        $this->client->setClient(
1763
            $this->mock_http_client(false)
1764
        );
1765
 
1766
        $expectedParams = $this->mockUpdateSubscriptionParams();
1767
 
1768
        $response = $this->client->updateSubscription('I-BW452GLLEP1G', $expectedParams);
1769
 
1770
        $this->assertEmpty($response);
1771
    }
1772
 
1773
    /** @test */
1774
    public function it_can_show_details_for_a_subscription()
1775
    {
1776
        $this->client->setAccessToken([
1777
            'access_token'  => self::$access_token,
1778
            'token_type'    => 'Bearer',
1779
        ]);
1780
 
1781
        $this->client->setClient(
1782
            $this->mock_http_client(
1783
                $this->mockGetSubscriptionDetailsResponse()
1784
            )
1785
        );
1786
 
1787
        $response = $this->client->showSubscriptionDetails('I-BW452GLLEP1G');
1788
 
1789
        $this->assertNotEmpty($response);
1790
        $this->assertArrayHasKey('id', $response);
1791
    }
1792
 
1793
    /** @test */
1794
    public function it_can_activate_a_subscription()
1795
    {
1796
        $this->client->setAccessToken([
1797
            'access_token'  => self::$access_token,
1798
            'token_type'    => 'Bearer',
1799
        ]);
1800
 
1801
        $this->client->setClient(
1802
            $this->mock_http_client(false)
1803
        );
1804
 
1805
        $response = $this->client->activateSubscription('I-BW452GLLEP1G', 'Reactivating the subscription');
1806
 
1807
        $this->assertEmpty($response);
1808
    }
1809
 
1810
    /** @test */
1811
    public function it_can_cancel_a_subscription()
1812
    {
1813
        $this->client->setAccessToken([
1814
            'access_token'  => self::$access_token,
1815
            'token_type'    => 'Bearer',
1816
        ]);
1817
 
1818
        $this->client->setClient(
1819
            $this->mock_http_client(false)
1820
        );
1821
 
1822
        $response = $this->client->cancelSubscription('I-BW452GLLEP1G', 'Not satisfied with the service');
1823
 
1824
        $this->assertEmpty($response);
1825
    }
1826
 
1827
    /** @test */
1828
    public function it_can_suspend_a_subscription()
1829
    {
1830
        $this->client->setAccessToken([
1831
            'access_token'  => self::$access_token,
1832
            'token_type'    => 'Bearer',
1833
        ]);
1834
 
1835
        $this->client->setClient(
1836
            $this->mock_http_client(false)
1837
        );
1838
 
1839
        $response = $this->client->suspendSubscription('I-BW452GLLEP1G', 'Item out of stock');
1840
 
1841
        $this->assertEmpty($response);
1842
    }
1843
 
1844
    /** @test */
1845
    public function it_can_capture_payment_for_a_subscription()
1846
    {
1847
        $this->client->setAccessToken([
1848
            'access_token'  => self::$access_token,
1849
            'token_type'    => 'Bearer',
1850
        ]);
1851
 
1852
        $this->client->setClient(
1853
            $this->mock_http_client(false)
1854
        );
1855
 
1856
        $response = $this->client->captureSubscriptionPayment('I-BW452GLLEP1G', 'Charging as the balance reached the limit', 100);
1857
 
1858
        $this->assertEmpty($response);
1859
    }
1860
 
1861
    /** @test */
1862
    public function it_can_update_quantity_or_product_for_a_subscription()
1863
    {
1864
        $this->client->setAccessToken([
1865
            'access_token'  => self::$access_token,
1866
            'token_type'    => 'Bearer',
1867
        ]);
1868
 
1869
        $this->client->setClient(
1870
            $this->mock_http_client(
1871
                $this->mockUpdateSubscriptionItemsResponse()
1872
            )
1873
        );
1874
 
1875
        $expectedParams = $this->mockUpdateSubscriptionItemsParams();
1876
 
1877
        $response = $this->client->reviseSubscription('I-BW452GLLEP1G', $expectedParams);
1878
 
1879
        $this->assertNotEmpty($response);
1880
        $this->assertArrayHasKey('plan_id', $response);
1881
    }
1882
 
1883
    /** @test */
1884
    public function it_can_list_transactions_for_a_subscription()
1885
    {
1886
        $this->client->setAccessToken([
1887
            'access_token'  => self::$access_token,
1888
            'token_type'    => 'Bearer',
1889
        ]);
1890
 
1891
        $this->client->setClient(
1892
            $this->mock_http_client(
1893
                $this->mockListSubscriptionTransactionsResponse()
1894
            )
1895
        );
1896
 
1897
        $response = $this->client->listSubscriptionTransactions('I-BW452GLLEP1G', '2018-01-21T07:50:20.940Z', '2018-08-22T07:50:20.940Z');
1898
 
1899
        $this->assertNotEmpty($response);
1900
        $this->assertEquals($response, $this->mockListSubscriptionTransactionsResponse());
1901
    }
1902
 
1903
    /** @test */
1904
    public function it_can_get_tracking_details_for_tracking_id()
1905
    {
1906
        $this->client->setAccessToken([
1907
            'access_token'  => self::$access_token,
1908
            'token_type'    => 'Bearer',
1909
        ]);
1910
 
1911
        $this->client->setClient(
1912
            $this->mock_http_client(
1913
                $this->mockGetTrackingDetailsResponse()
1914
            )
1915
        );
1916
 
1917
        $response = $this->client->showTrackingDetails('8MC585209K746392H-443844607820');
1918
 
1919
        $this->assertNotEmpty($response);
1920
        $this->assertEquals($response, $this->mockGetTrackingDetailsResponse());
1921
        $this->assertArrayHasKey('tracking_number', $response);
1922
    }
1923
 
1924
    /** @test */
1925
    public function it_can_update_tracking_details_for_tracking_id()
1926
    {
1927
        $this->client->setAccessToken([
1928
            'access_token'  => self::$access_token,
1929
            'token_type'    => 'Bearer',
1930
        ]);
1931
 
1932
        $this->client->setClient(
1933
            $this->mock_http_client(false)
1934
        );
1935
 
1936
        $response = $this->client->updateTrackingDetails(
1937
            '8MC585209K746392H-443844607820',
1938
            $this->mockUpdateTrackingDetailsParams()
1939
        );
1940
 
1941
        $this->assertEmpty($response);
1942
    }
1943
 
1944
    /** @test */
1945
    public function it_can_create_tracking_in_batches()
1946
    {
1947
        $this->client->setAccessToken([
1948
            'access_token'  => self::$access_token,
1949
            'token_type'    => 'Bearer',
1950
        ]);
1951
 
1952
        $this->client->setClient(
1953
            $this->mock_http_client(
1954
                $this->mockCreateTrackinginBatchesResponse()
1955
            )
1956
        );
1957
 
1958
        $expectedParams = $this->mockCreateTrackinginBatchesParams();
1959
 
1960
        $response = $this->client->addBatchTracking($expectedParams);
1961
 
1962
        $this->assertNotEmpty($response);
1963
        $this->assertArrayHasKey('tracker_identifiers', $response);
1964
    }
1965
 
1966
    /** @test */
1967
    public function it_can_list_web_hooks_event_types()
1968
    {
1969
        $this->client->setAccessToken([
1970
            'access_token'  => self::$access_token,
1971
            'token_type'    => 'Bearer',
1972
        ]);
1973
 
1974
        $this->client->setClient(
1975
            $this->mock_http_client(
1976
                $this->mockListWebHookEventsTypesResponse()
1977
            )
1978
        );
1979
 
1980
        $response = $this->client->listEventTypes();
1981
 
1982
        $this->assertNotEmpty($response);
1983
        $this->assertArrayHasKey('event_types', $response);
1984
    }
1985
 
1986
    /** @test */
1987
    public function it_can_list_web_hooks_events()
1988
    {
1989
        $this->client->setAccessToken([
1990
            'access_token'  => self::$access_token,
1991
            'token_type'    => 'Bearer',
1992
        ]);
1993
 
1994
        $this->client->setClient(
1995
            $this->mock_http_client(
1996
                $this->mockWebHookEventsListResponse()
1997
            )
1998
        );
1999
 
2000
        $response = $this->client->listEvents();
2001
 
2002
        $this->assertNotEmpty($response);
2003
        $this->assertArrayHasKey('events', $response);
2004
    }
2005
 
2006
    /** @test */
2007
    public function it_can_show_details_for_a_web_hooks_event()
2008
    {
2009
        $this->client->setAccessToken([
2010
            'access_token'  => self::$access_token,
2011
            'token_type'    => 'Bearer',
2012
        ]);
2013
 
2014
        $this->client->setClient(
2015
            $this->mock_http_client(
2016
                $this->mockGetWebHookEventResponse()
2017
            )
2018
        );
2019
 
2020
        $response = $this->client->showEventDetails('8PT597110X687430LKGECATA');
2021
 
2022
        $this->assertNotEmpty($response);
2023
        $this->assertArrayHasKey('id', $response);
2024
    }
2025
 
2026
    /** @test */
2027
    public function it_can_resend_notification_for_a_web_hooks_event()
2028
    {
2029
        $this->client->setAccessToken([
2030
            'access_token'  => self::$access_token,
2031
            'token_type'    => 'Bearer',
2032
        ]);
2033
 
2034
        $this->client->setClient(
2035
            $this->mock_http_client(
2036
                $this->mockResendWebHookEventNotificationResponse()
2037
            )
2038
        );
2039
 
2040
        $expectedParams = ['12334456'];
2041
 
2042
        $response = $this->client->resendEventNotification('8PT597110X687430LKGECATA', $expectedParams);
2043
 
2044
        $this->assertNotEmpty($response);
2045
        $this->assertArrayHasKey('id', $response);
2046
    }
2047
 
2048
    /** @test */
2049
    public function it_can_create_a_web_hook()
2050
    {
2051
        $this->client->setAccessToken([
2052
            'access_token'  => self::$access_token,
2053
            'token_type'    => 'Bearer',
2054
        ]);
2055
 
2056
        $this->client->setClient(
2057
            $this->mock_http_client(
2058
                $this->mockCreateWebHookResponse()
2059
            )
2060
        );
2061
 
2062
        $response = $this->client->createWebHook(
2063
            'https://example.com/example_webhook',
2064
            ['PAYMENT.AUTHORIZATION.CREATED', 'PAYMENT.AUTHORIZATION.VOIDED']
2065
        );
2066
 
2067
        $this->assertNotEmpty($response);
2068
        $this->assertArrayHasKey('event_types', $response);
2069
    }
2070
 
2071
    /** @test */
2072
    public function it_can_list_web_hooks()
2073
    {
2074
        $this->client->setAccessToken([
2075
            'access_token'  => self::$access_token,
2076
            'token_type'    => 'Bearer',
2077
        ]);
2078
 
2079
        $this->client->setClient(
2080
            $this->mock_http_client(
2081
                $this->mockListWebHookResponse()
2082
            )
2083
        );
2084
 
2085
        $response = $this->client->listWebHooks();
2086
 
2087
        $this->assertNotEmpty($response);
2088
        $this->assertArrayHasKey('webhooks', $response);
2089
    }
2090
 
2091
    /** @test */
2092
    public function it_can_delete_a_web_hook()
2093
    {
2094
        $this->client->setAccessToken([
2095
            'access_token'  => self::$access_token,
2096
            'token_type'    => 'Bearer',
2097
        ]);
2098
 
2099
        $this->client->setClient(
2100
            $this->mock_http_client(false)
2101
        );
2102
 
2103
        $response = $this->client->deleteWebHook('5GP028458E2496506');
2104
 
2105
        $this->assertEmpty($response);
2106
    }
2107
 
2108
    /** @test */
2109
    public function it_can_update_a_web_hook()
2110
    {
2111
        $this->client->setAccessToken([
2112
            'access_token'  => self::$access_token,
2113
            'token_type'    => 'Bearer',
2114
        ]);
2115
 
2116
        $this->client->setClient(
2117
            $this->mock_http_client(
2118
                $this->mockUpdateWebHookResponse()
2119
            )
2120
        );
2121
 
2122
        $expectedParams = $this->mockUpdateWebHookParams();
2123
 
2124
        $response = $this->client->updateWebHook('0EH40505U7160970P', $expectedParams);
2125
 
2126
        $this->assertNotEmpty($response);
2127
        $this->assertArrayHasKey('event_types', $response);
2128
    }
2129
 
2130
    /** @test */
2131
    public function it_can_show_details_for_a_web_hook()
2132
    {
2133
        $this->client->setAccessToken([
2134
            'access_token'  => self::$access_token,
2135
            'token_type'    => 'Bearer',
2136
        ]);
2137
 
2138
        $this->client->setClient(
2139
            $this->mock_http_client(
2140
                $this->mockGetWebHookResponse()
2141
            )
2142
        );
2143
 
2144
        $response = $this->client->showWebHookDetails('0EH40505U7160970P');
2145
 
2146
        $this->assertNotEmpty($response);
2147
        $this->assertArrayHasKey('event_types', $response);
2148
    }
2149
 
2150
    /** @test */
2151
    public function it_can_list_events_for_web_hooks()
2152
    {
2153
        $this->client->setAccessToken([
2154
            'access_token'  => self::$access_token,
2155
            'token_type'    => 'Bearer',
2156
        ]);
2157
 
2158
        $this->client->setClient(
2159
            $this->mock_http_client(
2160
                $this->mockListWebHookEventsResponse()
2161
            )
2162
        );
2163
 
2164
        $response = $this->client->listWebHookEvents('0EH40505U7160970P');
2165
 
2166
        $this->assertNotEmpty($response);
2167
        $this->assertArrayHasKey('event_types', $response);
2168
    }
2169
 
2170
    /** @test */
2171
    public function it_can_verify_web_hook_signature()
2172
    {
2173
        $this->client->setAccessToken([
2174
            'access_token'  => self::$access_token,
2175
            'token_type'    => 'Bearer',
2176
        ]);
2177
 
2178
        $this->client->setClient(
2179
            $this->mock_http_client(
2180
                $this->mockVerifyWebHookSignatureResponse()
2181
            )
2182
        );
2183
 
2184
        $expectedParams = $this->mockVerifyWebHookSignatureParams();
2185
 
2186
        $response = $this->client->verifyWebHook($expectedParams);
2187
 
2188
        $this->assertNotEmpty($response);
2189
        $this->assertArrayHasKey('verification_status', $response);
2190
    }
2191
}