| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace Srmklive\PayPal\Tests\Unit\Client;
- use GuzzleHttp\Utils;
- use PHPUnit\Framework\Attributes\Test;
- use PHPUnit\Framework\TestCase;
- use Srmklive\PayPal\Tests\MockClientClasses;
- use Srmklive\PayPal\Tests\MockRequestPayloads;
- use Srmklive\PayPal\Tests\MockResponsePayloads;
- class BillingPlansTest extends TestCase
- {
- use MockClientClasses;
- use MockRequestPayloads;
- use MockResponsePayloads;
- #[Test]
- public function it_can_create_a_billing_plan(): void
- {
- $expectedResponse = $this->mockCreatePlansResponse();
- $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans';
- $expectedParams = [
- 'headers' => [
- 'Accept' => 'application/json',
- 'Accept-Language' => 'en_US',
- 'Authorization' => 'Bearer some-token',
- ],
- 'json' => $this->createPlanParams(),
- ];
- $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
- $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
- }
- #[Test]
- public function it_can_list_billing_plans(): void
- {
- $expectedResponse = $this->mockListPlansResponse();
- $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=PROD-XXCD1234QWER65782&page_size=2&page=1&total_required=true';
- $expectedParams = [
- 'headers' => [
- 'Accept' => 'application/json',
- 'Accept-Language' => 'en_US',
- 'Authorization' => 'Bearer some-token',
- ],
- ];
- $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
- $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
- }
- #[Test]
- public function it_can_update_a_billing_plan(): void
- {
- $expectedResponse = '';
- $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ';
- $expectedParams = [
- 'headers' => [
- 'Accept' => 'application/json',
- 'Accept-Language' => 'en_US',
- 'Authorization' => 'Bearer some-token',
- ],
- 'json' => $this->updatePlanParams(),
- ];
- $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
- $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
- }
- #[Test]
- public function it_can_show_details_for_a_billing_plan(): void
- {
- $expectedResponse = $this->mockGetPlansResponse();
- $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-5ML4271244454362WXNWU5NQ';
- $expectedParams = [
- 'headers' => [
- 'Accept' => 'application/json',
- 'Accept-Language' => 'en_US',
- 'Authorization' => 'Bearer some-token',
- ],
- ];
- $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
- $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
- }
- #[Test]
- public function it_can_activate_a_billing_plan(): void
- {
- $expectedResponse = '';
- $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/activate';
- $expectedParams = [
- 'headers' => [
- 'Accept' => 'application/json',
- 'Accept-Language' => 'en_US',
- 'Authorization' => 'Bearer some-token',
- ],
- ];
- $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
- $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
- }
- #[Test]
- public function it_can_deactivate_a_billing_plan(): void
- {
- $expectedResponse = '';
- $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/deactivate';
- $expectedParams = [
- 'headers' => [
- 'Accept' => 'application/json',
- 'Accept-Language' => 'en_US',
- 'Authorization' => 'Bearer some-token',
- ],
- ];
- $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
- $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
- }
- #[Test]
- public function it_can_update_pricing_for_a_billing_plan(): void
- {
- $expectedResponse = '';
- $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-2UF78835G6983425GLSM44MA/update-pricing-schemes';
- $expectedParams = [
- 'headers' => [
- 'Accept' => 'application/json',
- 'Accept-Language' => 'en_US',
- 'Authorization' => 'Bearer some-token',
- ],
- 'json' => $this->updatePlanPricingParams(),
- ];
- $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
- $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
- }
- }
|