Merge billing and generic-payment forms and post values as get

parameters
This commit is contained in:
PCoder 2018-09-23 13:13:29 +02:00
parent bc3eaaa7eb
commit 9ec05e7df4

View file

@ -124,17 +124,25 @@ $(document).ready(function () {
$('#billing-form').submit(); $('#billing-form').submit();
} }
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length === 2) return parts.pop().split(";").shift();
}
var $form_new = $('#payment-form-new'); var $form_new = $('#payment-form-new');
$form_new.submit(payWithStripe_new); $form_new.submit(payWithStripe_new);
function payWithStripe_new(e) { function payWithStripe_new(e) {
e.preventDefault(); e.preventDefault();
function stripeTokenHandler(token) { function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server // Insert the token ID into the form so it gets submitted to the server
$('#id_token').val(token.id); $('#id_token').val(token.id);
$('#billing-form').submit(); var get_parameters = $("#billing-form").serialize();
get_parameters += "&" + $("#generic-payment-form").serialize();
$('<form action="?' + get_parameters + '" method="post">' +
'<input name="csrfmiddlewaretoken" value="' +
getCookie('csrftoken')+ '" type="hidden" />'+
'</form>').appendTo('body').submit();
} }
@ -199,7 +207,15 @@ $(document).ready(function () {
$('.credit-card-info .btn.choice-btn').click(function(){ $('.credit-card-info .btn.choice-btn').click(function(){
var id = this.dataset['id_card']; var id = this.dataset['id_card'];
$('#id_card').val(id); $('#id_card').val(id);
$('#billing-form').submit(); var get_parameters = $("#billing-form").serialize();
var generic_payment_form = $("#generic-payment-form");
if (generic_payment_form !== null) {
get_parameters += "&" + generic_payment_form.serialize();
}
$('<form action="?' + get_parameters + '" method="post">' +
'<input name="csrfmiddlewaretoken" value="' +
getCookie('csrftoken')+ '" type="hidden" />'+
'</form>').appendTo('body').submit();
}); });
}); });