Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow paying with using on-site credit card #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed assets/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions assets/shop/entrypoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './js/card_encoder';
25 changes: 25 additions & 0 deletions assets/shop/js/card_encoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as JSEncrypt from './jsencrypt.min';

document.addEventListener('DOMContentLoaded', () => {
const form = document.querySelector('[name="sylius_checkout_complete"]');
const submit_button = form.querySelector('[type="submit"]');
const cards_api = document.getElementById('sylius_checkout_complete_tpay_cards_api').value.replace(/\s/g, '');
const encrypted_card_field = document.getElementById('sylius_checkout_complete_tpay_card_card');

const encrypt = new JSEncrypt();
encrypt.setPublicKey(atob(cards_api));

submit_button.addEventListener('click', (e) => {
e.preventDefault();

const card_number = document.getElementById('sylius_checkout_complete_tpay_card_number').value.replace(/\s/g, '');
const cvc = document.getElementById('sylius_checkout_complete_tpay_card_cvv').value.replace(/\s/g, '');
const expiration_date_month = document.getElementById('sylius_checkout_complete_tpay_card_expiration_date_month').value.replace(/\s/g, '');
const expiration_date_year = document.getElementById('sylius_checkout_complete_tpay_card_expiration_date_year').value.replace(/\s/g, '');
const expiration_date = [expiration_date_month, expiration_date_year].join('/');

encrypted_card_field.value = encrypt.encrypt([card_number, expiration_date, cvc, document.location.origin].join('|'));

form.submit();
})
});
Loading
Loading