1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Extract script into separate file

This commit is contained in:
Benjamin Beganović 2021-10-14 18:45:48 +02:00
parent 9264b6b80e
commit 0db3f3dd57
3 changed files with 56 additions and 40 deletions

View File

@ -0,0 +1,51 @@
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
class CheckoutCreditCardAuthorization {
constructor() {
this.button = document.querySelector('#pay-button');
}
init() {
this.frames = Frames.init(
document.querySelector('meta[name=public-key]').content
);
}
handle() {
this.init();
Frames.addEventHandler(
Frames.Events.CARD_VALIDATION_CHANGED,
(event) => {
this.button.disabled = !Frames.isCardValid();
}
);
Frames.addEventHandler(Frames.Events.CARD_TOKENIZED, (event) => {
document.querySelector(
'input[name="gateway_response"]'
).value = JSON.stringify(event);
document.getElementById('server_response').submit();
});
document
.querySelector('#authorization-form')
.addEventListener('submit', (event) => {
this.button.disabled = true;
event.preventDefault();
Frames.submitCard();
});
}
}
new CheckoutCreditCardAuthorization().handle();

View File

@ -40,44 +40,5 @@
@endsection
@section('gateway_footer')
<script>
class CheckoutCreditCardAuthorization {
constructor() {
this.button = document.querySelector('#pay-button');
}
init() {
this.frames = Frames.init(
document.querySelector('meta[name=public-key]').content
);
}
handle() {
this.init();
Frames.addEventHandler(Frames.Events.CARD_VALIDATION_CHANGED, (event) => {
this.button.disabled = !Frames.isCardValid();
});
Frames.addEventHandler(Frames.Events.CARD_TOKENIZED, (event) => {
document.querySelector(
'input[name="gateway_response"]'
).value = JSON.stringify(event);
document.getElementById('server_response').submit();
});
document
.querySelector('#authorization-form')
.addEventListener('submit', (event) => {
this.button.disabled = true;
event.preventDefault();
Frames.submitCard();
});
}
}
new CheckoutCreditCardAuthorization().handle();
</script>
<script src="{{ asset('js/clients/payment_methods/authorize-checkout-card.js') }}"></script>
@endsection

4
webpack.mix.js vendored
View File

@ -114,6 +114,10 @@ mix.js("resources/js/app.js", "public/js")
"resources/js/clients/payments/stripe-sepa.js",
"public/js/clients/payments/stripe-sepa.js"
)
.js(
"resources/js/clients/payment_methods/authorize-checkout-card.js",
"public/js/clients/payment_methods/authorize-checkout-card.js"
)
mix.copyDirectory('node_modules/card-js/card-js.min.css', 'public/css/card-js.min.css');