AdapterBillingPlansPricingHelpersTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Srmklive\PayPal\Tests\Feature;
  3. use PHPUnit\Framework\Attributes\Test;
  4. use PHPUnit\Framework\TestCase;
  5. use Srmklive\PayPal\Services\PayPal as PayPalClient;
  6. use Srmklive\PayPal\Tests\MockClientClasses;
  7. use Srmklive\PayPal\Tests\MockResponsePayloads;
  8. class AdapterBillingPlansPricingHelpersTest extends TestCase
  9. {
  10. use MockClientClasses;
  11. use MockResponsePayloads;
  12. /** @var string */
  13. protected static string $access_token = '';
  14. /** @var PayPalClient */
  15. protected PayPalClient $client;
  16. protected function setUp(): void
  17. {
  18. $this->client = new PayPalClient($this->getApiCredentials());
  19. $this->client->setClient(
  20. $this->mock_http_client(
  21. $this->mockAccessTokenResponse()
  22. )
  23. );
  24. $response = $this->client->getAccessToken();
  25. self::$access_token = $response['access_token'];
  26. parent::setUp();
  27. }
  28. #[Test]
  29. public function it_can_update_pricing_schemes_for_a_billing_plan(): void
  30. {
  31. $this->client->setAccessToken([
  32. 'access_token' => self::$access_token,
  33. 'token_type' => 'Bearer',
  34. ]);
  35. $this->client = $this->client->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
  36. ->addPricingScheme('DAY', 7, 0, true)
  37. ->addPricingScheme('MONTH', 1, 100);
  38. $this->client->setClient(
  39. $this->mock_http_client(false)
  40. );
  41. $response = $this->client->processBillingPlanPricingUpdates();
  42. $this->assertEmpty($response);
  43. }
  44. #[Test]
  45. public function it_can_set_custom_limits_when_listing_billing_plans(): void
  46. {
  47. $this->client->setAccessToken([
  48. 'access_token' => self::$access_token,
  49. 'token_type' => 'Bearer',
  50. ]);
  51. $this->client = $this->client->setPageSize(30)
  52. ->showTotals(true);
  53. $this->client->setClient(
  54. $this->mock_http_client(
  55. $this->mockListPlansResponse()
  56. )
  57. );
  58. $response = $this->client->setCurrentPage(1)->listPlans();
  59. $this->assertNotEmpty($response);
  60. $this->assertArrayHasKey('plans', $response);
  61. }
  62. }