Skip to content

Commit

Permalink
Merge pull request #144 from synolia/fix/order-payment-integrated
Browse files Browse the repository at this point in the history
fix(form): payplug integrated payment rendering once became an order
  • Loading branch information
maxperei authored Dec 2, 2024
2 parents 452b3f6 + afd896f commit 0b4657c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/Resources/dev/shop/payment/integrated.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ const IntegratedPayment = {
})
return;
}
if (document.querySelector('[id*=sylius_checkout_select_payment_payments][value=payplug]:checked')) {
if (document.querySelector(`[id*=sylius_checkout_select_payment_payments][value=${payplug_integrated_payment_params.payment_method_code}]:checked`)) {
IntegratedPayment.openFields();
}
document.querySelectorAll('[id*=sylius_checkout_select_payment_payments]').forEach((element) => {
element.addEventListener('change', (e) => {
if ('payplug' === e.currentTarget.value && e.currentTarget.checked) {
if (payplug_integrated_payment_params.payment_method_code === e.currentTarget.value && e.currentTarget.checked) {
IntegratedPayment.openFields();
return;
}
Expand All @@ -67,14 +67,14 @@ const IntegratedPayment = {
},
openFields() {
document.querySelector('.payplugIntegratedPayment').classList.add('payplugIntegratedPayment--loaded');
document.querySelector('#next-step').classList.add('disabled');
document.querySelector('button[type=submit]').classList.add('disabled');
if (null === IntegratedPayment.options.api) {
IntegratedPayment.load();
}
},
closeFields() {
document.querySelector('.payplugIntegratedPayment').classList.remove('payplugIntegratedPayment--loaded');
document.querySelector('#next-step').classList.remove('disabled');
document.querySelector('button[type=submit]').classList.remove('disabled');
},
load() {
IntegratedPayment.options.api = integratedPaymentApi = new Payplug.IntegratedPayment(payplug_integrated_payment_params.is_test_mode);
Expand Down Expand Up @@ -127,12 +127,10 @@ const IntegratedPayment = {
if (null !== chosenScheme) {
IntegratedPayment.options.scheme = chosenScheme.value;
}

if (payplug_integrated_payment_params.payment_id !== undefined) {
integratedPaymentApi.pay(payplug_integrated_payment_params.payment_id, IntegratedPayment.options.scheme, {save_card: IntegratedPayment.options.save_card});
return;
}

const response = await fetch(payplug_integrated_payment_params.routes.init_payment, {method: 'POST'});
const data = await response.json();
integratedPaymentApi.pay(data.payment_id, IntegratedPayment.options.scheme, {save_card: IntegratedPayment.options.save_card});
Expand All @@ -153,7 +151,6 @@ const IntegratedPayment = {
if (err.error) {
document.querySelector(`.payplugIntegratedPayment__error--${key}`).classList.remove('payplugIntegratedPayment__error--hide');
document.querySelector(`.${key}-input-container`).classList.add('payplugIntegratedPayment__container--invalid');

if (err.error.name === "FIELD_EMPTY") {
document.querySelector(`.payplugIntegratedPayment__error--${key}`).querySelector(".emptyField").classList.remove('payplugIntegratedPayment__error--hide');
document.querySelector(`.payplugIntegratedPayment__error--${key}`).querySelector(".invalidField").classList.add('payplugIntegratedPayment__error--hide');
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/assets/shop/payment/integrated.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
{% include '@PayPlugSyliusPayPlugPlugin/form/integrated.html.twig' with {
'paymentMethod': method,
'payment': order.getLastPayment('cart'),
'hasSavedCards': hasSavedCards
'hasSavedCards': hasSavedCards,
} %}
{% endif %}
{% if method.gatewayConfig.factoryName == applePayFactoryName %}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/views/form/integrated.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var payplug_integrated_payment_params = {
is_test_mode: '{{ is_payplug_test_mode_enabled(paymentMethod) }}',
has_saved_cards: '{{ hasSavedCards }}',
payment_method_code: '{{ paymentMethod.code }}',
{% if payment.details.payment_id is defined %}
payment_id: '{{ payment.details.payment_id }}',
{% endif %}
Expand Down

0 comments on commit 0b4657c

Please sign in to comment.