BillingPlansTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace Srmklive\PayPal\Tests\Unit\Client;
  3. use GuzzleHttp\Utils;
  4. use PHPUnit\Framework\Attributes\Test;
  5. use PHPUnit\Framework\TestCase;
  6. use Srmklive\PayPal\Tests\MockClientClasses;
  7. use Srmklive\PayPal\Tests\MockRequestPayloads;
  8. use Srmklive\PayPal\Tests\MockResponsePayloads;
  9. class BillingPlansTest extends TestCase
  10. {
  11. use MockClientClasses;
  12. use MockRequestPayloads;
  13. use MockResponsePayloads;
  14. #[Test]
  15. public function it_can_create_a_billing_plan(): void
  16. {
  17. $expectedResponse = $this->mockCreatePlansResponse();
  18. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans';
  19. $expectedParams = [
  20. 'headers' => [
  21. 'Accept' => 'application/json',
  22. 'Accept-Language' => 'en_US',
  23. 'Authorization' => 'Bearer some-token',
  24. ],
  25. 'json' => $this->createPlanParams(),
  26. ];
  27. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
  28. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
  29. }
  30. #[Test]
  31. public function it_can_list_billing_plans(): void
  32. {
  33. $expectedResponse = $this->mockListPlansResponse();
  34. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=PROD-XXCD1234QWER65782&page_size=2&page=1&total_required=true';
  35. $expectedParams = [
  36. 'headers' => [
  37. 'Accept' => 'application/json',
  38. 'Accept-Language' => 'en_US',
  39. 'Authorization' => 'Bearer some-token',
  40. ],
  41. ];
  42. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
  43. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
  44. }
  45. #[Test]
  46. public function it_can_update_a_billing_plan(): void
  47. {
  48. $expectedResponse = '';
  49. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ';
  50. $expectedParams = [
  51. 'headers' => [
  52. 'Accept' => 'application/json',
  53. 'Accept-Language' => 'en_US',
  54. 'Authorization' => 'Bearer some-token',
  55. ],
  56. 'json' => $this->updatePlanParams(),
  57. ];
  58. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
  59. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
  60. }
  61. #[Test]
  62. public function it_can_show_details_for_a_billing_plan(): void
  63. {
  64. $expectedResponse = $this->mockGetPlansResponse();
  65. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-5ML4271244454362WXNWU5NQ';
  66. $expectedParams = [
  67. 'headers' => [
  68. 'Accept' => 'application/json',
  69. 'Accept-Language' => 'en_US',
  70. 'Authorization' => 'Bearer some-token',
  71. ],
  72. ];
  73. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
  74. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
  75. }
  76. #[Test]
  77. public function it_can_activate_a_billing_plan(): void
  78. {
  79. $expectedResponse = '';
  80. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/activate';
  81. $expectedParams = [
  82. 'headers' => [
  83. 'Accept' => 'application/json',
  84. 'Accept-Language' => 'en_US',
  85. 'Authorization' => 'Bearer some-token',
  86. ],
  87. ];
  88. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
  89. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
  90. }
  91. #[Test]
  92. public function it_can_deactivate_a_billing_plan(): void
  93. {
  94. $expectedResponse = '';
  95. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/deactivate';
  96. $expectedParams = [
  97. 'headers' => [
  98. 'Accept' => 'application/json',
  99. 'Accept-Language' => 'en_US',
  100. 'Authorization' => 'Bearer some-token',
  101. ],
  102. ];
  103. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
  104. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
  105. }
  106. #[Test]
  107. public function it_can_update_pricing_for_a_billing_plan(): void
  108. {
  109. $expectedResponse = '';
  110. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-2UF78835G6983425GLSM44MA/update-pricing-schemes';
  111. $expectedParams = [
  112. 'headers' => [
  113. 'Accept' => 'application/json',
  114. 'Accept-Language' => 'en_US',
  115. 'Authorization' => 'Bearer some-token',
  116. ],
  117. 'json' => $this->updatePlanPricingParams(),
  118. ];
  119. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
  120. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
  121. }
  122. }