Skip to content

Commit

Permalink
Allow paying with using on-site credit card (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz authored Sep 13, 2024
2 parents 100299b + 8b26e3a commit c40d0c8
Show file tree
Hide file tree
Showing 63 changed files with 3,087 additions and 633 deletions.
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

0 comments on commit c40d0c8

Please sign in to comment.