diff --git a/assets/admin/entrypoint.js b/assets/admin/entrypoint.js index 25037da5..9ccfccbe 100644 --- a/assets/admin/entrypoint.js +++ b/assets/admin/entrypoint.js @@ -1,2 +1 @@ // Mandatory by test application -// whereas it's useless diff --git a/assets/settings/constants.scss b/assets/settings/constants.scss deleted file mode 100644 index c125ab01..00000000 --- a/assets/settings/constants.scss +++ /dev/null @@ -1,9 +0,0 @@ -$white: #ffffff; -$lightgrey: #cccccc; -$greyish: #66727f; -$darkgrey: #222426; -$black: #000000; -$green: #81bc00; -$neongreen: #21ba45; -$red: #db2828; -$paypluggreen: #8fd2b8; diff --git a/assets/shop/entrypoint.js b/assets/shop/entrypoint.js index 25037da5..9ccfccbe 100644 --- a/assets/shop/entrypoint.js +++ b/assets/shop/entrypoint.js @@ -1,2 +1 @@ // Mandatory by test application -// whereas it's useless diff --git a/config/config.yml b/config/config.yml index a106e595..fb713c19 100644 --- a/config/config.yml +++ b/config/config.yml @@ -1,5 +1,4 @@ imports: - { resource: "state_machine.yml" } - { resource: "resources.yaml" } -# - { resource: "ui.yaml" } - { resource: "twig_hooks/*.yaml" } diff --git a/config/services/gateway.xml b/config/services/gateway.xml index 1dc4b421..eeda89e7 100644 --- a/config/services/gateway.xml +++ b/config/services/gateway.xml @@ -1,10 +1,20 @@ - + + + + PayPlug\SyliusPayPlugPlugin\Gateway\PayPlugGatewayFactory + + - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/twig_hooks/shop.yaml b/config/twig_hooks/shop.yaml index 2fd86c0e..678b7e3c 100644 --- a/config/twig_hooks/shop.yaml +++ b/config/twig_hooks/shop.yaml @@ -25,15 +25,6 @@ sylius_twig_hooks: template: '@PayPlugSyliusPayPlugPlugin/shared/modal/index.html.twig' priority: 0 - # TODO: check if this is possible only on select_payment page - 'sylius_shop.checkout#stylesheets': - select_payment_css: - template: '@PayPlugSyliusPayPlugPlugin/stylesheets/select_payment_css.html.twig' - - 'sylius_shop.order#stylesheets': - select_payment_css: - template: '@PayPlugSyliusPayPlugPlugin/stylesheets/select_payment_css.html.twig' - 'sylius_shop.shared.form.select_payment.payment': choice: template: '@PayPlugSyliusPayPlugPlugin/shared/form/select_payment/payment/choice.html.twig' diff --git a/config/ui.yaml b/config/ui.yaml deleted file mode 100644 index f6d595ad..00000000 --- a/config/ui.yaml +++ /dev/null @@ -1,33 +0,0 @@ -sylius_ui: - events: - sylius.shop.product.show.right_sidebar: - blocks: - pay_with_oney: - template: '@PayPlugSyliusPayPlugPlugin/oney/product/pay_with_oney.html.twig' - priority: 29 # After price widget - context: - legacy_event: 'sonata.block.event.sylius.shop.product.show.after_price' - sylius.shop.cart.summary.totals: - blocks: - pay_with_oney: - template: '@PayPlugSyliusPayPlugPlugin/oney/cart/pay_with_oney.html.twig' - sylius.shop.layout.javascripts: - blocks: - webfontloader: - template: '@PayPlugSyliusPayPlugPlugin/javascripts/webfont_loader.html.twig' - oney_common: - template: '@PayPlugSyliusPayPlugPlugin/javascripts/oney_common.html.twig' - sylius.shop.layout.stylesheets: - blocks: - oney_common: - template: '@PayPlugSyliusPayPlugPlugin/stylesheets/oney_common.html.twig' - sylius.admin.payment_method.create.stylesheets: &cssEvt - blocks: - payment_methods_css: - template: '@PayPlugSyliusPayPlugPlugin/stylesheets/payment_method_css.html.twig' - sylius.admin.payment_method.update.stylesheets: *cssEvt - sylius.shop.checkout.select_payment.before_form: &selectPayment - blocks: - select_payment_js: - template: '@PayPlugSyliusPayPlugPlugin/javascripts/select_payment_js.html.twig' - sylius.shop.order.select_payment.before_form: *selectPayment diff --git a/src/Command/Handler/CapturePaymentRequestHandler.php b/src/Command/Handler/CapturePaymentRequestHandler.php index 262ea466..71bcf9dd 100644 --- a/src/Command/Handler/CapturePaymentRequestHandler.php +++ b/src/Command/Handler/CapturePaymentRequestHandler.php @@ -4,6 +4,7 @@ namespace PayPlug\SyliusPayPlugPlugin\Command\Handler; +use Payplug\Exception\HttpException; use PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClientFactoryInterface; use PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClientInterface; use PayPlug\SyliusPayPlugPlugin\Command\CapturePaymentRequest; @@ -40,6 +41,23 @@ public function __invoke(CapturePaymentRequest $capturePaymentRequest): void throw new \LogicException('Payment method is not set for the payment.'); } + if (PayPlugApiClientInterface::STATUS_CREATED === ($payment->getDetails()['status'] ?? null)) { + $paymentRequest->setResponseData([ + 'retry' => true, + 'message' => 'Payment already created', + 'payment_id' => $payment->getDetails()['payment_id'] ?? 'unknown', + 'redirect_url' => $payment->getDetails()['redirect_url'] ?? null, // @phpstan-ignore-line + ]); + + $this->stateMachine->apply( + $paymentRequest, + PaymentRequestTransitions::GRAPH, + PaymentRequestTransitions::TRANSITION_COMPLETE, + ); + + return; + } + $client = $this->apiClientFactory->createForPaymentMethod($method); $data = $this->paymentDataCreator->create($payment)->getArrayCopy(); @@ -53,13 +71,26 @@ public function __invoke(CapturePaymentRequest $capturePaymentRequest): void $data['notification_url'] = $notificationUrl; $paymentRequest->setPayload($data); - $payplugPayment = $client->createPayment($data); + + try { + $payplugPayment = $client->createPayment($data); + } catch (HttpException $exception) { + $paymentRequest->setResponseData(\json_decode($exception->getHttpResponse(), true)); // @phpstan-ignore-line + $this->stateMachine->apply( + $paymentRequest, + PaymentRequestTransitions::GRAPH, + PaymentRequestTransitions::TRANSITION_FAIL, + ); + + return; + } $arrayPayplugPayment = (array) $payplugPayment; $payment->setDetails([ ...$payment->getDetails(), 'status' => PayPlugApiClientInterface::STATUS_CREATED, 'payment_id' => $payplugPayment->__get('id'), 'payplug_response' => $arrayPayplugPayment, + 'redirect_url' => $payplugPayment->hosted_payment->payment_url, // @phpstan-ignore-line ]); $paymentRequest->setResponseData(array_merge($arrayPayplugPayment, [ diff --git a/src/DependencyInjection/PayPlugSyliusPayPlugExtension.php b/src/DependencyInjection/PayPlugSyliusPayPlugExtension.php index 2793e114..1154226a 100644 --- a/src/DependencyInjection/PayPlugSyliusPayPlugExtension.php +++ b/src/DependencyInjection/PayPlugSyliusPayPlugExtension.php @@ -25,9 +25,7 @@ public function load(array $configs, ContainerBuilder $container): void $xmlloader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__, 2) . '/config/services')); $ymlloader->load('services.yaml'); - // TODO: migrate to YAML $xmlloader->load('client.xml'); - $xmlloader->load('gateway.xml'); } public function prepend(ContainerBuilder $container): void @@ -42,12 +40,10 @@ private function prependTwigExtension(ContainerBuilder $container): void return; } - // TODO: check if still mandatory on v2 $container->prependExtensionConfig('twig', [ 'form_themes' => [ '@PayPlugSyliusPayPlugPlugin/form/form_gateway_config_row.html.twig', '@PayPlugSyliusPayPlugPlugin/form/sylius_checkout_select_payment_row.html.twig', - '@PayPlugSyliusPayPlugPlugin/form/complete_info_popin.html.twig', ], ]); } diff --git a/src/Entity/CardsOwnerInterface.php b/src/Entity/CardsOwnerInterface.php index 1a5ff0f1..996e1975 100644 --- a/src/Entity/CardsOwnerInterface.php +++ b/src/Entity/CardsOwnerInterface.php @@ -13,5 +13,5 @@ interface CardsOwnerInterface */ public function getCards(): Collection; - public function addCard(Card $card): static; + public function addCard(Card $card): self; } diff --git a/src/Gateway/Validator/Constraints/IsCanSaveCards.php b/src/Gateway/Validator/Constraints/IsCanSaveCards.php deleted file mode 100644 index d9a9124e..00000000 --- a/src/Gateway/Validator/Constraints/IsCanSaveCards.php +++ /dev/null @@ -1,23 +0,0 @@ -context->getRoot()->getData()->getGatewayConfig()->getConfig()['secretKey']; - - try { - if ($value) { - $checker = new PermissionCanSaveCardsChecker($this->apiClientFactory->create(PayPlugGatewayFactory::FACTORY_NAME, $secretKey)); - if (false === $checker->isEnabled()) { - $this->context->buildViolation($constraint->message)->addViolation(); - } - } - - return; - } catch (UnauthorizedException | \LogicException) { - return; - } - } -} diff --git a/src/PayPlugSyliusPayPlugPlugin.php b/src/PayPlugSyliusPayPlugPlugin.php index b6730ff9..c4117743 100644 --- a/src/PayPlugSyliusPayPlugPlugin.php +++ b/src/PayPlugSyliusPayPlugPlugin.php @@ -11,7 +11,7 @@ final class PayPlugSyliusPayPlugPlugin extends Bundle { use SyliusPluginTrait; - public const VERSION = '1.11.0'; + public const VERSION = '2.x-dev'; public function getPath(): string { diff --git a/templates/javascripts/oney_common.html.twig b/templates/javascripts/oney_common.html.twig deleted file mode 100644 index 6370e61a..00000000 --- a/templates/javascripts/oney_common.html.twig +++ /dev/null @@ -1 +0,0 @@ -{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/payplugsyliuspayplugplugin/assets/shop/oney_common/index.js'} %} diff --git a/templates/javascripts/select_payment_js.html.twig b/templates/javascripts/select_payment_js.html.twig deleted file mode 100644 index 84d44572..00000000 --- a/templates/javascripts/select_payment_js.html.twig +++ /dev/null @@ -1 +0,0 @@ -{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/payplugsyliuspayplugplugin/assets/shop/payment/index.js'} %} diff --git a/templates/javascripts/webfont_loader.html.twig b/templates/javascripts/webfont_loader.html.twig deleted file mode 100644 index 3c3c060c..00000000 --- a/templates/javascripts/webfont_loader.html.twig +++ /dev/null @@ -1 +0,0 @@ -{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js'} %} diff --git a/templates/stylesheets/oney_common.html.twig b/templates/stylesheets/oney_common.html.twig deleted file mode 100644 index c55ea177..00000000 --- a/templates/stylesheets/oney_common.html.twig +++ /dev/null @@ -1 +0,0 @@ -{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/payplugsyliuspayplugplugin/assets/shop/oney_common/index.css'} %} diff --git a/templates/stylesheets/payment_method_css.html.twig b/templates/stylesheets/payment_method_css.html.twig deleted file mode 100644 index a3a71c36..00000000 --- a/templates/stylesheets/payment_method_css.html.twig +++ /dev/null @@ -1 +0,0 @@ -{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/payplugsyliuspayplugplugin/assets/admin/payment_method/index.css'} %} diff --git a/templates/stylesheets/saved_cards.html.twig b/templates/stylesheets/saved_cards.html.twig deleted file mode 100644 index 19671027..00000000 --- a/templates/stylesheets/saved_cards.html.twig +++ /dev/null @@ -1 +0,0 @@ - diff --git a/templates/stylesheets/select_payment_css.html.twig b/templates/stylesheets/select_payment_css.html.twig deleted file mode 100644 index a3475eca..00000000 --- a/templates/stylesheets/select_payment_css.html.twig +++ /dev/null @@ -1 +0,0 @@ - diff --git a/translations/messages.en.yml b/translations/messages.en.yml index 44ca681b..79820a27 100644 --- a/translations/messages.en.yml +++ b/translations/messages.en.yml @@ -123,7 +123,7 @@ payplug_sylius_payplug_plugin: base_currency_not_euro: | Channel #channel_code#: #payment_method# is only available on channels with EURO as a currency only_one_gateway_allowed: | - Please note that the %gateway_title% payment method has already been set. To change it, go to your payment methods. + Please note that the %gateway_title% payment method has already been set. To change it, go to your payment methods. one_click_enable: Enable One click one_click_help: | Allow your customers to save their credit card details for later diff --git a/translations/messages.fr.yml b/translations/messages.fr.yml index ee8e9289..90bd5b09 100644 --- a/translations/messages.fr.yml +++ b/translations/messages.fr.yml @@ -143,7 +143,7 @@ payplug_sylius_payplug_plugin: base_currency_not_euro: | Canal #channel_code# : #payment_method# n’est disponible que sur des canaux dont la devise est l’EURO only_one_gateway_allowed: | - Attention, le moyen de paiement %gateway_title% existe déjà. Pour le modifier, rendez-vous sur vos moyens de paiement. + Attention, le moyen de paiement %gateway_title% existe déjà. Pour le modifier, rendez-vous sur vos moyens de paiement. one_click_enable: Activer le One click one_click_help: | Permettez à vos clients d'enregistrer leurs coordonnées de carte de paiement pour effectuer ultérieurement diff --git a/translations/messages.it.yml b/translations/messages.it.yml index f8c23bcb..7e4b3ee6 100644 --- a/translations/messages.it.yml +++ b/translations/messages.it.yml @@ -123,7 +123,7 @@ payplug_sylius_payplug_plugin: base_currency_not_euro: | Il canale #channel_code# : #payment_method# è disponibile solo per i canali la cui valuta è in EURO only_one_gateway_allowed: | - Attenzione: il metodo di pagamento %gateway_title% è già definito. Per modificarlo, vai ai tuoi metodi di pagamento. + Attenzione: il metodo di pagamento %gateway_title% è già definito. Per modificarlo, vai ai tuoi metodi di pagamento. one_click_enable: Attiva un clic one_click_help: | Consenti ai tuoi clienti di salvare i dettagli della loro carta di credito per dopo