Add ajax call to fetch price/recurring
Based on selected production
This commit is contained in:
parent
b63a572231
commit
69a1d2df71
1 changed files with 49 additions and 16 deletions
|
@ -22,6 +22,37 @@ function setBrandIcon(brand) {
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
$(function () {
|
||||||
|
$("select#id_generic_payment_form-product_name").change(function () {
|
||||||
|
var gp_form = $('#generic-payment-form');
|
||||||
|
$.ajax({
|
||||||
|
url: gp_form.attr('action'),
|
||||||
|
type: 'POST',
|
||||||
|
data: gp_form.serialize(),
|
||||||
|
init: function () {
|
||||||
|
console.log("init")
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if (data.amount !== undefined) {
|
||||||
|
$("#id_generic_payment_form-amount").val(data.amount);
|
||||||
|
if (data.isSubscription) {
|
||||||
|
$('#id_generic_payment_form-recurring').prop('checked', true);
|
||||||
|
} else {
|
||||||
|
$('#id_generic_payment_form-recurring').prop('checked', false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$("#id_generic_payment_form-amount").val('');
|
||||||
|
$('#id_generic_payment_form-recurring').prop('checked', false);
|
||||||
|
console.log("No product found")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (xmlhttprequest, textstatus, message) {
|
||||||
|
console.log("Error fetching product")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
beforeSend: function (xhr, settings) {
|
beforeSend: function (xhr, settings) {
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
|
@ -124,19 +155,21 @@ $(document).ready(function () {
|
||||||
$('#billing-form').submit();
|
$('#billing-form').submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
var value = "; " + document.cookie;
|
var value = "; " + document.cookie;
|
||||||
var parts = value.split("; " + name + "=");
|
var parts = value.split("; " + name + "=");
|
||||||
if (parts.length === 2) return parts.pop().split(";").shift();
|
if (parts.length === 2) return parts.pop().split(";").shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitBillingForm(){
|
function submitBillingForm() {
|
||||||
var billing_form =$('#billing-form');
|
var billing_form = $('#billing-form');
|
||||||
|
billing_form.append('<input type="hidden" name="generic_payment_form-product_name" value="' + $('#id_generic_payment_form-product_name').val() + '" />');
|
||||||
billing_form.append('<input type="hidden" name="generic_payment_form-amount" value="' + $('#id_generic_payment_form-amount').val() + '" />');
|
billing_form.append('<input type="hidden" name="generic_payment_form-amount" value="' + $('#id_generic_payment_form-amount').val() + '" />');
|
||||||
billing_form.append('<input type="hidden" name="generic_payment_form-recurring" value="' + ($('#id_generic_payment_form-recurring').prop('checked') ? 'on':'') + '" />');
|
billing_form.append('<input type="hidden" name="generic_payment_form-recurring" value="' + ($('#id_generic_payment_form-recurring').prop('checked') ? 'on' : '') + '" />');
|
||||||
billing_form.append('<input type="hidden" name="generic_payment_form-description" value="' + $('#id_generic_payment_form-description').val() + '" />');
|
billing_form.append('<input type="hidden" name="generic_payment_form-description" value="' + $('#id_generic_payment_form-description').val() + '" />');
|
||||||
billing_form.submit();
|
billing_form.submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -207,7 +240,7 @@ function submitBillingForm(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.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);
|
||||||
submitBillingForm();
|
submitBillingForm();
|
||||||
|
|
Loading…
Reference in a new issue