| 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 BillingPlansTest extends TestCase
|
|
|
12 |
{
|
|
|
13 |
use MockClientClasses;
|
|
|
14 |
use MockRequestPayloads;
|
|
|
15 |
use MockResponsePayloads;
|
|
|
16 |
|
|
|
17 |
/** @test */
|
|
|
18 |
public function it_can_create_a_billing_plan()
|
|
|
19 |
{
|
|
|
20 |
$expectedResponse = $this->mockCreatePlansResponse();
|
|
|
21 |
|
|
|
22 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans';
|
|
|
23 |
$expectedParams = [
|
|
|
24 |
'headers' => [
|
|
|
25 |
'Accept' => 'application/json',
|
|
|
26 |
'Accept-Language' => 'en_US',
|
|
|
27 |
'Authorization' => 'Bearer some-token',
|
|
|
28 |
],
|
|
|
29 |
'json' => $this->createPlanParams(),
|
|
|
30 |
];
|
|
|
31 |
|
|
|
32 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
33 |
|
|
|
34 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/** @test */
|
|
|
38 |
public function it_can_list_billing_plans()
|
|
|
39 |
{
|
|
|
40 |
$expectedResponse = $this->mockListPlansResponse();
|
|
|
41 |
|
|
|
42 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=PROD-XXCD1234QWER65782&page_size=2&page=1&total_required=true';
|
|
|
43 |
$expectedParams = [
|
|
|
44 |
'headers' => [
|
|
|
45 |
'Accept' => 'application/json',
|
|
|
46 |
'Accept-Language' => 'en_US',
|
|
|
47 |
'Authorization' => 'Bearer some-token',
|
|
|
48 |
],
|
|
|
49 |
];
|
|
|
50 |
|
|
|
51 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
52 |
|
|
|
53 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/** @test */
|
|
|
57 |
public function it_can_update_a_billing_plan()
|
|
|
58 |
{
|
|
|
59 |
$expectedResponse = '';
|
|
|
60 |
|
|
|
61 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ';
|
|
|
62 |
$expectedParams = [
|
|
|
63 |
'headers' => [
|
|
|
64 |
'Accept' => 'application/json',
|
|
|
65 |
'Accept-Language' => 'en_US',
|
|
|
66 |
'Authorization' => 'Bearer some-token',
|
|
|
67 |
],
|
|
|
68 |
'json' => $this->updatePlanParams(),
|
|
|
69 |
];
|
|
|
70 |
|
|
|
71 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
|
|
|
72 |
|
|
|
73 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/** @test */
|
|
|
77 |
public function it_can_show_details_for_a_billing_plan()
|
|
|
78 |
{
|
|
|
79 |
$expectedResponse = $this->mockGetPlansResponse();
|
|
|
80 |
|
|
|
81 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-5ML4271244454362WXNWU5NQ';
|
|
|
82 |
$expectedParams = [
|
|
|
83 |
'headers' => [
|
|
|
84 |
'Accept' => 'application/json',
|
|
|
85 |
'Accept-Language' => 'en_US',
|
|
|
86 |
'Authorization' => 'Bearer some-token',
|
|
|
87 |
],
|
|
|
88 |
];
|
|
|
89 |
|
|
|
90 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
91 |
|
|
|
92 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/** @test */
|
|
|
96 |
public function it_can_activate_a_billing_plan()
|
|
|
97 |
{
|
|
|
98 |
$expectedResponse = '';
|
|
|
99 |
|
|
|
100 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/activate';
|
|
|
101 |
$expectedParams = [
|
|
|
102 |
'headers' => [
|
|
|
103 |
'Accept' => 'application/json',
|
|
|
104 |
'Accept-Language' => 'en_US',
|
|
|
105 |
'Authorization' => 'Bearer some-token',
|
|
|
106 |
],
|
|
|
107 |
];
|
|
|
108 |
|
|
|
109 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
110 |
|
|
|
111 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/** @test */
|
|
|
115 |
public function it_can_deactivate_a_billing_plan()
|
|
|
116 |
{
|
|
|
117 |
$expectedResponse = '';
|
|
|
118 |
|
|
|
119 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/deactivate';
|
|
|
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, 'post');
|
|
|
129 |
|
|
|
130 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
/** @test */
|
|
|
134 |
public function it_can_update_pricing_for_a_billing_plan()
|
|
|
135 |
{
|
|
|
136 |
$expectedResponse = '';
|
|
|
137 |
|
|
|
138 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-2UF78835G6983425GLSM44MA/update-pricing-schemes';
|
|
|
139 |
$expectedParams = [
|
|
|
140 |
'headers' => [
|
|
|
141 |
'Accept' => 'application/json',
|
|
|
142 |
'Accept-Language' => 'en_US',
|
|
|
143 |
'Authorization' => 'Bearer some-token',
|
|
|
144 |
],
|
|
|
145 |
'json' => $this->updatePlanPricingParams(),
|
|
|
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 |
}
|