AdapterOrdersHelperTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Srmklive\PayPal\Tests\Feature;
  3. use Carbon\Carbon;
  4. use PHPUnit\Framework\Attributes\Test;
  5. use PHPUnit\Framework\TestCase;
  6. use Srmklive\PayPal\Services\PayPal as PayPalClient;
  7. use Srmklive\PayPal\Tests\MockClientClasses;
  8. use Srmklive\PayPal\Tests\MockRequestPayloads;
  9. use Srmklive\PayPal\Tests\MockResponsePayloads;
  10. class AdapterOrdersHelperTest extends TestCase
  11. {
  12. use MockClientClasses;
  13. use MockRequestPayloads;
  14. use MockResponsePayloads;
  15. /** @var string */
  16. protected static string $access_token = '';
  17. /** @var PayPalClient */
  18. protected PayPalClient $client;
  19. protected function setUp(): void
  20. {
  21. $this->client = new PayPalClient($this->getApiCredentials());
  22. $this->client->setClient(
  23. $this->mock_http_client(
  24. $this->mockAccessTokenResponse()
  25. )
  26. );
  27. $response = $this->client->getAccessToken();
  28. self::$access_token = $response['access_token'];
  29. parent::setUp();
  30. }
  31. #[Test]
  32. public function it_can_confirm_payment_for_an_order(): void
  33. {
  34. $this->client->setAccessToken([
  35. 'access_token' => self::$access_token,
  36. 'token_type' => 'Bearer',
  37. ]);
  38. $start_date = Carbon::now()->subDays(10)->toDateString();
  39. $this->client = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
  40. ->setBrandName('Test Brand')
  41. ->setStoredPaymentSource(
  42. 'MERCHANT',
  43. 'RECURRING',
  44. 'SUBSEQUENT',
  45. true,
  46. '5TY05013RG002845M',
  47. $start_date,
  48. 'Invoice-005',
  49. 'VISA'
  50. );
  51. $this->client->setClient(
  52. $this->mock_http_client(
  53. $this->mockConfirmOrderResponse()
  54. )
  55. );
  56. $response = $this->client->setupOrderConfirmation('5O190127TN364715T', 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL');
  57. $this->assertNotEmpty($response);
  58. $this->assertArrayHasKey('id', $response);
  59. }
  60. }