| jQuery(document).ready(function($) { | |
| $('#has_coupon').change(function(){ | |
| $(this).prop("checked"); | |
| $('.coupons').toggle('slow'); | |
| }); | |
| $('#submitBtn').click(function(){ | |
| var amount = $('#amount').val(); | |
| var couponCode = $('#coupon_code').val(); | |
| alert('Looking for coupon...'); | |
| $.ajax({ | |
| type: "post", | |
| url: ajax_coupons.ajaxurl, | |
| data: { | |
| coupon_code: couponCode, | |
| action: "get_coupon_discount" | |
| }, | |
| success:function (discount) { | |
| $.trim(discount); | |
| if(discount != "not_found") { | |
| var discount = discount/10; | |
| var currency = $('.stripe-button').attr("data-currency"); | |
| alert("Coupon applied succesfully. \nDiscount: " + currency + ' ' + discount.toFixed(2)); | |
| $('.stripe_checkout_app').hide(); | |
| $('#discount').text(discount); | |
| var finalAmount = amount - discount*100; | |
| $('#finalAmount').val(finalAmount); | |
| $('.stripe-button-el > span').html("Pay " + currency + ' ' + (finalAmount/100).toFixed(2)); | |
| $('.stripe-button').attr("data-amount", finalAmount); | |
| $('.stripe-button').attr("data-label", "Pay " + currency + ' ' + (finalAmount/100).toFixed(2)); | |
| $('.stripe-button').attr("data-panel-label", "Pay " + currency + ' ' + (finalAmount/100).toFixed(2)); | |
| $('#amount').val(finalAmount); | |
| $('#submitBtn').attr("disabled", "disabled"); | |
| $('#submitBtn').fadeOut('slow'); | |
| } | |
| else{ | |
| $('#errorMsg').show(); | |
| alert('no funca'); | |
| } | |
| }, | |
| error:function (e) { | |
| console.log(e); | |
| } | |
| }); | |
| }); | |
| })(jQuery); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment