diff --git a/.travis.yml b/.travis.yml index 90095349..f0946e94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,8 @@ before_install: - echo "memory_limit=4096M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - mkdir -p "${SYLIUS_CACHE_DIR}" + - cp -R migrations/ tests/Application/src/Migrations/ + install: - composer install --no-interaction --prefer-dist - (cd tests/Application && yarn install) diff --git a/README.md b/README.md index 91923211..4477063c 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ # just for now, it will be eventually hardcoded (as we always want to use Sylius PayPal facilitator) PAYPAL_FACILITATOR_URL='https://paypal.sylius.com' ``` + +5. Copy and apply migrations + + ``` + cp -R vendor/sylius/paypal-plugin/migrations/ src/Migrations/ + bin/console doctrine:migrations:migrate -n + ``` > BEWARE! diff --git a/migrations/Version20200907102535.php b/migrations/Version20200907102535.php new file mode 100644 index 00000000..3fda82ff --- /dev/null +++ b/migrations/Version20200907102535.php @@ -0,0 +1,36 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE sylius_paypal_plugin_pay_pal_credentials (id VARCHAR(255) NOT NULL, payment_method_id INT DEFAULT NULL, access_token VARCHAR(255) NOT NULL, creation_time DATETIME NOT NULL, expiration_time DATETIME NOT NULL, INDEX IDX_C56F54AD5AA1164F (payment_method_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE sylius_paypal_plugin_pay_pal_credentials ADD CONSTRAINT FK_C56F54AD5AA1164F FOREIGN KEY (payment_method_id) REFERENCES sylius_payment_method (id)'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE sylius_paypal_plugin_pay_pal_credentials'); + } +} diff --git a/phpstan.neon b/phpstan.neon index 734c5d58..c4dd7445 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,6 +5,7 @@ includes: parameters: reportUnmatchedIgnoredErrors: false checkMissingIterableValueType: false + checkGenericClassInNonGenericObjectType: false excludes_analyse: # Makes PHPStan crash diff --git a/spec/Api/CacheAuthorizeClientApiSpec.php b/spec/Api/CacheAuthorizeClientApiSpec.php new file mode 100644 index 00000000..1260aa6e --- /dev/null +++ b/spec/Api/CacheAuthorizeClientApiSpec.php @@ -0,0 +1,118 @@ +beConstructedWith($payPalCredentialsManager, $payPalCredentialsRepository, $authorizeClientApi); + } + + function it_implements_cache_authorize_client_api_interface(): void + { + $this->shouldImplement(CacheAuthorizeClientApiInterface::class); + } + + function it_returns_cached_access_token_if_it_is_not_expired( + ObjectRepository $payPalCredentialsRepository, + PayPalCredentialsInterface $payPalCredentials, + PaymentMethodInterface $paymentMethod + ): void { + $payPalCredentialsRepository->findOneBy(['paymentMethod' => $paymentMethod])->willReturn($payPalCredentials); + + $payPalCredentials->isExpired()->willReturn(false); + $payPalCredentials->accessToken()->willReturn('TOKEN'); + + $this->authorize($paymentMethod)->shouldReturn('TOKEN'); + } + + function it_gets_access_token_from_api_caches_and_returns_it( + ObjectManager $payPalCredentialsManager, + ObjectRepository $payPalCredentialsRepository, + AuthorizeClientApiInterface $authorizeClientApi, + PaymentMethodInterface $paymentMethod, + GatewayConfigInterface $gatewayConfig + ): void { + $payPalCredentialsRepository->findOneBy(['paymentMethod' => $paymentMethod])->willReturn(null); + + $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); + $gatewayConfig->getConfig()->willReturn(['client_id' => 'CLIENT_ID', 'client_secret' => '$ECRET']); + + $authorizeClientApi->authorize('CLIENT_ID', '$ECRET')->willReturn('TOKEN'); + + $payPalCredentialsManager + ->persist(Argument::that(function (PayPalCredentialsInterface $payPalCredentials) use ($paymentMethod): bool { + return + $payPalCredentials->accessToken() === 'TOKEN' && + $payPalCredentials->creationTime()->format('d-m-Y H:i') === (new \DateTime())->format('d-m-Y H:i') && + $payPalCredentials->expirationTime()->format('d-m-Y H:i') === (new \DateTime())->modify('+3600 seconds')->format('d-m-Y H:i') && + $payPalCredentials->paymentMethod() === $paymentMethod->getWrappedObject() + ; + })) + ->shouldBeCalled() + ; + $payPalCredentialsManager->flush()->shouldBeCalled(); + + $this->authorize($paymentMethod)->shouldReturn('TOKEN'); + } + + function it_returns_expired_token_and_ask_for_a_new_one( + ObjectManager $payPalCredentialsManager, + ObjectRepository $payPalCredentialsRepository, + AuthorizeClientApiInterface $authorizeClientApi, + PaymentMethodInterface $paymentMethod, + GatewayConfigInterface $gatewayConfig, + PayPalCredentialsInterface $payPalCredentials + ): void { + $payPalCredentialsRepository->findOneBy(['paymentMethod' => $paymentMethod])->willReturn($payPalCredentials); + $payPalCredentials->isExpired()->willReturn(true); + + $payPalCredentialsManager->remove($payPalCredentials)->shouldBeCalled(); + $payPalCredentialsManager->flush()->shouldBeCalledTimes(2); + + $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); + $gatewayConfig->getConfig()->willReturn(['client_id' => 'CLIENT_ID', 'client_secret' => '$ECRET']); + + $authorizeClientApi->authorize('CLIENT_ID', '$ECRET')->willReturn('TOKEN'); + + $payPalCredentialsManager + ->persist(Argument::that(function (PayPalCredentialsInterface $payPalCredentials) use ($paymentMethod): bool { + return + $payPalCredentials->accessToken() === 'TOKEN' && + $payPalCredentials->creationTime()->format('d-m-Y H:i') == (new \DateTime())->format('d-m-Y H:i') && + $payPalCredentials->expirationTime()->format('d-m-Y H:i') == (new \DateTime())->modify('+3600 seconds')->format('d-m-Y H:i') && + $payPalCredentials->paymentMethod() === $paymentMethod->getWrappedObject() + ; + })) + ->shouldBeCalled() + ; + $payPalCredentialsManager->flush()->shouldBeCalled(); + + $this->authorize($paymentMethod)->shouldReturn('TOKEN'); + } +} diff --git a/spec/Entity/PayPalCredentialsSpec.php b/spec/Entity/PayPalCredentialsSpec.php new file mode 100644 index 00000000..9f837e6d --- /dev/null +++ b/spec/Entity/PayPalCredentialsSpec.php @@ -0,0 +1,56 @@ +beConstructedWith('123ASD123', $paymentMethod, 'TOKEN', new \DateTime('2020-01-01 10:00:00'), 3600); + } + + function it_implements_pay_pal_credentials_interface(): void + { + $this->shouldImplement(PayPalCredentialsInterface::class); + } + + function it_has_a_payment_method(PaymentMethodInterface $paymentMethod): void + { + $this->paymentMethod()->shouldReturn($paymentMethod); + } + + function it_has_a_access_token(): void + { + $this->accessToken()->shouldReturn('TOKEN'); + } + + function it_has_a_creation_time(): void + { + $this->creationTime()->shouldBeLike(new \DateTime('2020-01-01 10:00:00')); + } + + function it_has_a_expiration_time(): void + { + $this->expirationTime()->shouldBeLike(new \DateTime('2020-01-01 11:00:00')); + } + + function it_can_be_expired(): void + { + $this->isExpired()->shouldReturn(true); + } +} diff --git a/spec/Payum/Action/CaptureActionSpec.php b/spec/Payum/Action/CaptureActionSpec.php index babd9e14..019ad598 100644 --- a/spec/Payum/Action/CaptureActionSpec.php +++ b/spec/Payum/Action/CaptureActionSpec.php @@ -15,21 +15,20 @@ use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; -use Payum\Core\Model\GatewayConfigInterface; use Payum\Core\Request\Capture; use PhpSpec\ObjectBehavior; use Sylius\Bundle\PayumBundle\Request\GetStatus; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; -use Sylius\PayPalPlugin\Api\AuthorizeClientApiInterface; +use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface; use Sylius\PayPalPlugin\Api\CreateOrderApiInterface; use Sylius\PayPalPlugin\Payum\Action\StatusAction; final class CaptureActionSpec extends ObjectBehavior { function let( - AuthorizeClientApiInterface $authorizeClientApi, + CacheAuthorizeClientApiInterface $authorizeClientApi, CreateOrderApiInterface $createOrderApi ): void { $this->beConstructedWith($authorizeClientApi, $createOrderApi); @@ -41,24 +40,21 @@ function it_implements_action_interface(): void } function it_authorizes_seller_send_create_order_request_and_sets_order_response_data_on_payment( - AuthorizeClientApiInterface $authorizeClientApi, + CacheAuthorizeClientApiInterface $authorizeClientApi, CreateOrderApiInterface $createOrderApi, Capture $request, OrderInterface $order, PaymentInterface $payment, - PaymentMethodInterface $paymentMethod, - GatewayConfigInterface $gatewayConfig + PaymentMethodInterface $paymentMethod ): void { $request->getModel()->willReturn($payment); $payment->getMethod()->willReturn($paymentMethod); - $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); - $gatewayConfig->getConfig()->willReturn(['client_id' => 'CLIENT_ID', 'client_secret' => 'CLIENT_SECRET']); $payment->getAmount()->willReturn(1000); $payment->getOrder()->willReturn($order); $order->getCurrencyCode()->willReturn('USD'); - $authorizeClientApi->authorize('CLIENT_ID', 'CLIENT_SECRET')->willReturn('ACCESS_TOKEN'); + $authorizeClientApi->authorize($paymentMethod)->willReturn('ACCESS_TOKEN'); $createOrderApi->create('ACCESS_TOKEN', $payment)->willReturn(['status' => 'CREATED', 'id' => '123123']); $payment->setDetails([ diff --git a/spec/Processor/PayPalPaymentRefundProcessorSpec.php b/spec/Processor/PayPalPaymentRefundProcessorSpec.php index 40ae6765..69429565 100644 --- a/spec/Processor/PayPalPaymentRefundProcessorSpec.php +++ b/spec/Processor/PayPalPaymentRefundProcessorSpec.php @@ -19,14 +19,14 @@ use Prophecy\Argument; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; -use Sylius\PayPalPlugin\Api\AuthorizeClientApiInterface; +use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface; use Sylius\PayPalPlugin\Api\RefundPaymentApiInterface; use Sylius\PayPalPlugin\Exception\PayPalOrderRefundException; use Sylius\PayPalPlugin\Processor\PaymentRefundProcessorInterface; final class PayPalPaymentRefundProcessorSpec extends ObjectBehavior { - function let(AuthorizeClientApiInterface $authorizeClientApi, RefundPaymentApiInterface $refundOrderApi): void + function let(CacheAuthorizeClientApiInterface $authorizeClientApi, RefundPaymentApiInterface $refundOrderApi): void { $this->beConstructedWith($authorizeClientApi, $refundOrderApi); } @@ -37,7 +37,7 @@ function it_implements_payment_refund_processor_interface(): void } function it_fully_refunds_payment_in_pay_pal( - AuthorizeClientApiInterface $authorizeClientApi, + CacheAuthorizeClientApiInterface $authorizeClientApi, RefundPaymentApiInterface $refundOrderApi, PaymentInterface $payment, PaymentMethodInterface $paymentMethod, @@ -46,10 +46,9 @@ function it_fully_refunds_payment_in_pay_pal( $payment->getMethod()->willReturn($paymentMethod); $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); $gatewayConfig->getFactoryName()->willReturn('sylius.pay_pal'); - $gatewayConfig->getConfig()->willReturn(['client_id' => 'CLIENT_ID', 'client_secret' => 'CLIENT_SECRET']); $payment->getDetails()->willReturn(['paypal_payment_id' => '123123']); - $authorizeClientApi->authorize('CLIENT_ID', 'CLIENT_SECRET')->willReturn('TOKEN'); + $authorizeClientApi->authorize($paymentMethod)->willReturn('TOKEN'); $refundOrderApi->refund('TOKEN', '123123')->willReturn(['status' => 'COMPLETED', 'id' => '123123']); $this->refund($payment); @@ -89,7 +88,7 @@ function it_does_nothing_if_payment_is_payment_has_not_pay_pal_payment_id( } function it_throws_exception_if_refund_could_not_be_processed( - AuthorizeClientApiInterface $authorizeClientApi, + CacheAuthorizeClientApiInterface $authorizeClientApi, RefundPaymentApiInterface $refundOrderApi, PaymentInterface $payment, PaymentMethodInterface $paymentMethod, @@ -98,10 +97,9 @@ function it_throws_exception_if_refund_could_not_be_processed( $payment->getMethod()->willReturn($paymentMethod); $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); $gatewayConfig->getFactoryName()->willReturn('sylius.pay_pal'); - $gatewayConfig->getConfig()->willReturn(['client_id' => 'CLIENT_ID', 'client_secret' => 'CLIENT_SECRET']); $payment->getDetails()->willReturn(['paypal_payment_id' => '123123']); - $authorizeClientApi->authorize('CLIENT_ID', 'CLIENT_SECRET')->willReturn('TOKEN'); + $authorizeClientApi->authorize($paymentMethod)->willReturn('TOKEN'); $refundOrderApi->refund('TOKEN', '123123')->willReturn(['status' => 'FAILED']); $this @@ -111,7 +109,7 @@ function it_throws_exception_if_refund_could_not_be_processed( } function it_throws_exception_if_something_went_wrong_during_refunding_payment( - AuthorizeClientApiInterface $authorizeClientApi, + CacheAuthorizeClientApiInterface $authorizeClientApi, RefundPaymentApiInterface $refundOrderApi, PaymentInterface $payment, PaymentMethodInterface $paymentMethod, @@ -120,10 +118,9 @@ function it_throws_exception_if_something_went_wrong_during_refunding_payment( $payment->getMethod()->willReturn($paymentMethod); $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); $gatewayConfig->getFactoryName()->willReturn('sylius.pay_pal'); - $gatewayConfig->getConfig()->willReturn(['client_id' => 'CLIENT_ID', 'client_secret' => 'CLIENT_SECRET']); $payment->getDetails()->willReturn(['paypal_payment_id' => '123123']); - $authorizeClientApi->authorize('CLIENT_ID', 'CLIENT_SECRET')->willReturn('TOKEN'); + $authorizeClientApi->authorize($paymentMethod)->willReturn('TOKEN'); $refundOrderApi->refund('TOKEN', '123123')->willThrow(ClientException::class); $this diff --git a/src/Api/CacheAuthorizeClientApi.php b/src/Api/CacheAuthorizeClientApi.php new file mode 100644 index 00000000..dd2fe948 --- /dev/null +++ b/src/Api/CacheAuthorizeClientApi.php @@ -0,0 +1,74 @@ +payPalCredentialsManager = $payPalCredentialsManager; + $this->payPalCredentialsRepository = $payPalCredentialsRepository; + $this->authorizeClientApi = $authorizeClientApi; + } + + public function authorize(PaymentMethodInterface $paymentMethod): string + { + /** @var PayPalCredentialsInterface|null $payPalCredentials */ + $payPalCredentials = $this->payPalCredentialsRepository->findOneBy(['paymentMethod' => $paymentMethod]); + if ($payPalCredentials !== null && !$payPalCredentials->isExpired()) { + return $payPalCredentials->accessToken(); + } + + if ($payPalCredentials !== null && $payPalCredentials->isExpired()) { + $this->payPalCredentialsManager->remove($payPalCredentials); + $this->payPalCredentialsManager->flush(); + } + + /** @var GatewayConfigInterface $gatewayConfig */ + $gatewayConfig = $paymentMethod->getGatewayConfig(); + $config = $gatewayConfig->getConfig(); + + $token = $this->authorizeClientApi->authorize( + (string) $config['client_id'], (string) $config['client_secret'] + ); + $payPalCredentials = new PayPalCredentials( + Uuid::uuid4()->toString(), $paymentMethod, $token, new \DateTime(), 3600 + ); + + $this->payPalCredentialsManager->persist($payPalCredentials); + $this->payPalCredentialsManager->flush(); + + return $payPalCredentials->accessToken(); + } +} diff --git a/src/Api/CacheAuthorizeClientApiInterface.php b/src/Api/CacheAuthorizeClientApiInterface.php new file mode 100644 index 00000000..7f32e16d --- /dev/null +++ b/src/Api/CacheAuthorizeClientApiInterface.php @@ -0,0 +1,12 @@ +getMethod(); - /** @var GatewayConfigInterface $gatewayConfig */ - $gatewayConfig = $paymentMethod->getGatewayConfig(); - $config = $gatewayConfig->getConfig(); - - $token = $this->authorizeClientApi->authorize($config['client_id'], $config['client_secret']); + $token = $this->authorizeClientApi->authorize($paymentMethod); return $this->orderDetailsApi->get($token, $id); } diff --git a/src/Entity/PayPalCredentials.php b/src/Entity/PayPalCredentials.php new file mode 100644 index 00000000..f9318942 --- /dev/null +++ b/src/Entity/PayPalCredentials.php @@ -0,0 +1,105 @@ +id = $id; + $this->paymentMethod = $paymentMethod; + $this->accessToken = $accessToken; + $this->creationTime = $creationTime; + $this->expirationTime = (clone $creationTime)->modify('+' . $expiresIn . ' seconds'); + } + + public function id(): string + { + return $this->id; + } + + public function paymentMethod(): PaymentMethodInterface + { + return $this->paymentMethod; + } + + public function accessToken(): string + { + return $this->accessToken; + } + + public function creationTime(): \DateTime + { + return $this->creationTime; + } + + public function expirationTime(): \DateTime + { + return $this->expirationTime; + } + + public function isExpired(): bool + { + return new \DateTime() > $this->expirationTime; + } +} diff --git a/src/Entity/PayPalCredentialsInterface.php b/src/Entity/PayPalCredentialsInterface.php new file mode 100644 index 00000000..d547324b --- /dev/null +++ b/src/Entity/PayPalCredentialsInterface.php @@ -0,0 +1,20 @@ +authorizeClientApi = $authorizeClientApi; @@ -47,14 +46,8 @@ public function execute($request): void $payment = $request->getModel(); /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $payment->getMethod(); - /** @var GatewayConfigInterface $gatewayConfig */ - $gatewayConfig = $paymentMethod->getGatewayConfig(); - $config = $gatewayConfig->getConfig(); - $token = $this - ->authorizeClientApi - ->authorize((string) $config['client_id'], (string) $config['client_secret']) - ; + $token = $this->authorizeClientApi->authorize($paymentMethod); $content = $this->createOrderApi->create($token, $payment); if ($content['status'] === 'CREATED') { diff --git a/src/Payum/Action/CompleteOrderAction.php b/src/Payum/Action/CompleteOrderAction.php index 3638b5ee..45785a06 100644 --- a/src/Payum/Action/CompleteOrderAction.php +++ b/src/Payum/Action/CompleteOrderAction.php @@ -15,12 +15,11 @@ use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; -use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Order\StateResolver\StateResolverInterface; -use Sylius\PayPalPlugin\Api\AuthorizeClientApiInterface; +use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface; use Sylius\PayPalPlugin\Api\CompleteOrderApiInterface; use Sylius\PayPalPlugin\Api\UpdateOrderApiInterface; use Sylius\PayPalPlugin\Payum\Request\CompleteOrder; @@ -29,7 +28,7 @@ final class CompleteOrderAction implements ActionInterface { - /** @var AuthorizeClientApiInterface */ + /** @var CacheAuthorizeClientApiInterface */ private $authorizeClientApi; /** @var UpdateOrderApiInterface */ @@ -48,7 +47,7 @@ final class CompleteOrderAction implements ActionInterface private $orderPaymentStateResolver; public function __construct( - AuthorizeClientApiInterface $authorizeClientApi, + CacheAuthorizeClientApiInterface $authorizeClientApi, UpdateOrderApiInterface $updateOrderApi, CompleteOrderApiInterface $completeOrderApi, PayPalAddressProcessor $payPalAddressProcessor, @@ -72,14 +71,7 @@ public function execute($request): void $payment = $request->getModel(); /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $payment->getMethod(); - /** @var GatewayConfigInterface $gatewayConfig */ - $gatewayConfig = $paymentMethod->getGatewayConfig(); - $config = $gatewayConfig->getConfig(); - - $token = $this - ->authorizeClientApi - ->authorize((string) $config['client_id'], (string) $config['client_secret']) - ; + $token = $this->authorizeClientApi->authorize($paymentMethod); $details = $payment->getDetails(); /** @var OrderInterface $order */ diff --git a/src/Processor/PayPalPaymentRefundProcessor.php b/src/Processor/PayPalPaymentRefundProcessor.php index e2011c87..56f2f430 100644 --- a/src/Processor/PayPalPaymentRefundProcessor.php +++ b/src/Processor/PayPalPaymentRefundProcessor.php @@ -17,21 +17,21 @@ use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; -use Sylius\PayPalPlugin\Api\AuthorizeClientApiInterface; +use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface; use Sylius\PayPalPlugin\Api\RefundPaymentApiInterface; use Sylius\PayPalPlugin\Exception\PayPalOrderRefundException; use Webmozart\Assert\Assert; final class PayPalPaymentRefundProcessor implements PaymentRefundProcessorInterface { - /** @var AuthorizeClientApiInterface */ + /** @var CacheAuthorizeClientApiInterface */ private $authorizeClientApi; /** @var RefundPaymentApiInterface */ private $refundOrderApi; public function __construct( - AuthorizeClientApiInterface $authorizeClientApi, + CacheAuthorizeClientApiInterface $authorizeClientApi, RefundPaymentApiInterface $refundOrderApi ) { $this->authorizeClientApi = $authorizeClientApi; @@ -44,7 +44,6 @@ public function refund(PaymentInterface $payment): void $paymentMethod = $payment->getMethod(); /** @var GatewayConfigInterface $gatewayConfig */ $gatewayConfig = $paymentMethod->getGatewayConfig(); - $config = $gatewayConfig->getConfig(); if ($gatewayConfig->getFactoryName() !== 'sylius.pay_pal') { return; @@ -56,7 +55,7 @@ public function refund(PaymentInterface $payment): void } try { - $token = $this->authorizeClientApi->authorize((string) $config['client_id'], (string) $config['client_secret']); + $token = $this->authorizeClientApi->authorize($paymentMethod); $response = $this->refundOrderApi->refund($token, (string) $details['paypal_payment_id']); Assert::same($response['status'], 'COMPLETED'); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 5a95e429..026a6e49 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -98,7 +98,7 @@ class="Sylius\PayPalPlugin\Processor\PayPalPaymentRefundProcessor" public="true" > - + diff --git a/src/Resources/config/services/api.xml b/src/Resources/config/services/api.xml index 328df55e..1b27a03b 100644 --- a/src/Resources/config/services/api.xml +++ b/src/Resources/config/services/api.xml @@ -20,6 +20,23 @@ %env(resolve:PAYPAL_API_BASE_URL)% + + + Sylius\PayPalPlugin\Entity\PayPalCredentials + + + + + + + + - + diff --git a/src/Resources/config/services/payum.xml b/src/Resources/config/services/payum.xml index 694dbe5f..f2c5d90b 100644 --- a/src/Resources/config/services/payum.xml +++ b/src/Resources/config/services/payum.xml @@ -15,13 +15,13 @@ - + - +