Working on js for plans
This commit is contained in:
40
static/js/stripe-plan.js
Normal file
40
static/js/stripe-plan.js
Normal file
@ -0,0 +1,40 @@
|
||||
import {
|
||||
hidePayButton,
|
||||
showPayButton,
|
||||
showCardError,
|
||||
showCardSuccess,
|
||||
stripe,
|
||||
card,
|
||||
processing,
|
||||
} from './common.js';
|
||||
|
||||
export function val() {
|
||||
let form = document.getElementById("charge_form");
|
||||
|
||||
if (form.checkValidity() === false) {
|
||||
this.event.preventDefault();
|
||||
this.event.stopPropagation();
|
||||
form.classList.add("was-validated");
|
||||
return;
|
||||
}
|
||||
form.classList.add("was-validated");
|
||||
hidePayButton();
|
||||
|
||||
let amountToCharge = document.getElementById("amount").value;
|
||||
|
||||
stripe.createPaymentMethod({
|
||||
type: 'card',
|
||||
card: card,
|
||||
billing_details: {
|
||||
email: document.getElementById("cardholder-email").value,
|
||||
},
|
||||
}).then(stripePaymentMethodHandler);
|
||||
}
|
||||
|
||||
function stripePaymentMethodHandler(result) {
|
||||
if (result.error) {
|
||||
showCardError(result.error.message);
|
||||
} else {
|
||||
// create a customer and subscribe to plan
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user