Skip to content

Commit

Permalink
refacto(payment): slightly js restructure, reindent twig
Browse files Browse the repository at this point in the history
  • Loading branch information
maxperei committed Nov 27, 2024
1 parent d45ef9b commit 34a0052
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
17 changes: 7 additions & 10 deletions src/Resources/dev/shop/payment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const Payment = {
});
Payment.tabsHandler();
Payment.applePayHandler();
$('form[name="sylius_checkout_select_payment"]').on("submit", () => {
Payment.handleForm();
});
},
toggleGateway() {
const paymentMethodInputId = $(this.options.trigger).data("payment-input-id");
Expand Down Expand Up @@ -118,8 +121,7 @@ const Payment = {
Payment.enableNextStepButton();
}
},
onApplePayButtonClick(event)
{
onApplePayButtonClick(event) {
const applePayButton = $(event.currentTarget);

if (applePaySessionRequestSettings === undefined) {
Expand Down Expand Up @@ -270,12 +272,7 @@ const Payment = {
this.modalSubmit(e);
});
},
};

const onDocumentLoad = function (event) {
Payment.init();

$('form[name="sylius_checkout_select_payment"] button[type="submit"]').on("click", (event) => {
handleForm() {
if ($(".checkbox-oney :radio:checked").length) {
$(".checkbox-payplug").closest(".payment-item").find(".payment-choice__input:checked").prop("checked", false);
} else if ($(".checkbox-payplug :radio:checked").length) {
Expand All @@ -284,7 +281,7 @@ const onDocumentLoad = function (event) {

$("input#payplug_choice_card_other").attr("disabled", true);
$('form[name="sylius_checkout_select_payment"]').submit();
});
}
};

document.addEventListener("DOMContentLoaded", onDocumentLoad, false);
document.addEventListener("DOMContentLoaded", Payment.init, false);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endif %}

{% set showOney = false %}
{% set showPayplug = false %}
{% set hasSavedCards = false %}

{% if method.gatewayConfig.factoryName == oneyFactoryName and form.parent.parent.oney_payment_choice is defined %}
{% set showOney = true %}
Expand All @@ -28,7 +28,7 @@
and is_save_card_enabled(method)
and sylius.customer.cards is not empty
%}
{% set showPayplug = true %}
{% set hasSavedCards = true %}
{% endif %}

<div class="item payment-item" {{ sylius_test_html_attribute('payment-item') }}>
Expand Down Expand Up @@ -80,14 +80,14 @@
<div class="oney-payment-choice payment-method-choice" data-payment-input-id="{{ form.vars.id }}">
{{ form_row(form.parent.parent.oney_payment_choice) }}
</div>
{% if app.session is not null and app.session.get('oney_has_error') == true %}
<script type="text/javascript">
/* <![CDATA[ */
var completeInfoRoute = '{{ path("payplug_sylius_oney_complete_info") }}?tokenValue={{ order.tokenValue }}';
/* ]] */
</script>
{% endif %}
{% elseif showPayplug %}
{% if app.session is not null and app.session.get('oney_has_error') == true %}
<script type="text/javascript">
/* <![CDATA[ */
var completeInfoRoute = '{{ path("payplug_sylius_oney_complete_info") }}?tokenValue={{ order.tokenValue }}';
/* ]] */
</script>
{% endif %}
{% elseif hasSavedCards %}
<div class="payplug-payment-choice payment-method-choice" data-payment-input-id="{{ form.vars.id }}">
{{ form_row(form.parent.parent.payplug_card_choice) }}
</div>
Expand Down

0 comments on commit 34a0052

Please sign in to comment.