| 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 SubscriptionsTest extends TestCase
|
|
|
12 |
{
|
|
|
13 |
use MockClientClasses;
|
|
|
14 |
use MockRequestPayloads;
|
|
|
15 |
use MockResponsePayloads;
|
|
|
16 |
|
|
|
17 |
/** @test */
|
|
|
18 |
public function it_can_create_a_subscription()
|
|
|
19 |
{
|
|
|
20 |
$expectedResponse = $this->mockCreateSubscriptionResponse();
|
|
|
21 |
|
|
|
22 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions';
|
|
|
23 |
$expectedParams = [
|
|
|
24 |
'headers' => [
|
|
|
25 |
'Accept' => 'application/json',
|
|
|
26 |
'Accept-Language' => 'en_US',
|
|
|
27 |
'Authorization' => 'Bearer some-token',
|
|
|
28 |
],
|
|
|
29 |
'json' => $this->mockCreateSubscriptionParams(),
|
|
|
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_update_a_subscription()
|
|
|
39 |
{
|
|
|
40 |
$expectedResponse = '';
|
|
|
41 |
|
|
|
42 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G';
|
|
|
43 |
$expectedParams = [
|
|
|
44 |
'headers' => [
|
|
|
45 |
'Accept' => 'application/json',
|
|
|
46 |
'Accept-Language' => 'en_US',
|
|
|
47 |
'Authorization' => 'Bearer some-token',
|
|
|
48 |
],
|
|
|
49 |
'json' => $this->mockUpdateSubscriptionParams(),
|
|
|
50 |
];
|
|
|
51 |
|
|
|
52 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
|
|
|
53 |
|
|
|
54 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/** @test */
|
|
|
58 |
public function it_can_show_details_for_a_subscription()
|
|
|
59 |
{
|
|
|
60 |
$expectedResponse = $this->mockGetSubscriptionDetailsResponse();
|
|
|
61 |
|
|
|
62 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G';
|
|
|
63 |
$expectedParams = [
|
|
|
64 |
'headers' => [
|
|
|
65 |
'Accept' => 'application/json',
|
|
|
66 |
'Accept-Language' => 'en_US',
|
|
|
67 |
'Authorization' => 'Bearer some-token',
|
|
|
68 |
],
|
|
|
69 |
];
|
|
|
70 |
|
|
|
71 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
72 |
|
|
|
73 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/** @test */
|
|
|
77 |
public function it_can_activate_a_subscription()
|
|
|
78 |
{
|
|
|
79 |
$expectedResponse = '';
|
|
|
80 |
|
|
|
81 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/activate';
|
|
|
82 |
$expectedParams = [
|
|
|
83 |
'headers' => [
|
|
|
84 |
'Accept' => 'application/json',
|
|
|
85 |
'Accept-Language' => 'en_US',
|
|
|
86 |
'Authorization' => 'Bearer some-token',
|
|
|
87 |
],
|
|
|
88 |
'json' => $this->mockActivateSubscriptionParams(),
|
|
|
89 |
];
|
|
|
90 |
|
|
|
91 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
92 |
|
|
|
93 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/** @test */
|
|
|
97 |
public function it_can_cancel_a_subscription()
|
|
|
98 |
{
|
|
|
99 |
$expectedResponse = '';
|
|
|
100 |
|
|
|
101 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/cancel';
|
|
|
102 |
$expectedParams = [
|
|
|
103 |
'headers' => [
|
|
|
104 |
'Accept' => 'application/json',
|
|
|
105 |
'Accept-Language' => 'en_US',
|
|
|
106 |
'Authorization' => 'Bearer some-token',
|
|
|
107 |
],
|
|
|
108 |
'json' => $this->mockCancelSubscriptionParams(),
|
|
|
109 |
];
|
|
|
110 |
|
|
|
111 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
112 |
|
|
|
113 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/** @test */
|
|
|
117 |
public function it_can_suspend_a_subscription()
|
|
|
118 |
{
|
|
|
119 |
$expectedResponse = '';
|
|
|
120 |
|
|
|
121 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/suspend';
|
|
|
122 |
$expectedParams = [
|
|
|
123 |
'headers' => [
|
|
|
124 |
'Accept' => 'application/json',
|
|
|
125 |
'Accept-Language' => 'en_US',
|
|
|
126 |
'Authorization' => 'Bearer some-token',
|
|
|
127 |
],
|
|
|
128 |
'json' => $this->mockSuspendSubscriptionParams(),
|
|
|
129 |
];
|
|
|
130 |
|
|
|
131 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
132 |
|
|
|
133 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
/** @test */
|
|
|
137 |
public function it_can_capture_payment_for_a_subscription()
|
|
|
138 |
{
|
|
|
139 |
$expectedResponse = '';
|
|
|
140 |
|
|
|
141 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/capture';
|
|
|
142 |
$expectedParams = [
|
|
|
143 |
'headers' => [
|
|
|
144 |
'Accept' => 'application/json',
|
|
|
145 |
'Accept-Language' => 'en_US',
|
|
|
146 |
'Authorization' => 'Bearer some-token',
|
|
|
147 |
],
|
|
|
148 |
'json' => $this->mockCaptureSubscriptionPaymentParams(),
|
|
|
149 |
];
|
|
|
150 |
|
|
|
151 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
152 |
|
|
|
153 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
/** @test */
|
|
|
157 |
public function it_can_update_quantity_or_product_for_a_subscription()
|
|
|
158 |
{
|
|
|
159 |
$expectedResponse = $this->mockUpdateSubscriptionItemsResponse();
|
|
|
160 |
|
|
|
161 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/revise';
|
|
|
162 |
$expectedParams = [
|
|
|
163 |
'headers' => [
|
|
|
164 |
'Accept' => 'application/json',
|
|
|
165 |
'Accept-Language' => 'en_US',
|
|
|
166 |
'Authorization' => 'Bearer some-token',
|
|
|
167 |
],
|
|
|
168 |
'json' => $this->mockUpdateSubscriptionItemsParams(),
|
|
|
169 |
];
|
|
|
170 |
|
|
|
171 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
172 |
|
|
|
173 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
/** @test */
|
|
|
177 |
public function it_can_list_transactions_for_a_subscription()
|
|
|
178 |
{
|
|
|
179 |
$expectedResponse = $this->mockListSubscriptionTransactionsResponse();
|
|
|
180 |
|
|
|
181 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/transactions?start_time=2018-01-21T07:50:20.940Z&end_time=2018-08-21T07:50:20.940Z';
|
|
|
182 |
$expectedParams = [
|
|
|
183 |
'headers' => [
|
|
|
184 |
'Accept' => 'application/json',
|
|
|
185 |
'Accept-Language' => 'en_US',
|
|
|
186 |
'Authorization' => 'Bearer some-token',
|
|
|
187 |
],
|
|
|
188 |
];
|
|
|
189 |
|
|
|
190 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
191 |
|
|
|
192 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
193 |
}
|
|
|
194 |
}
|