Working on js for plans
This commit is contained in:
parent
85c1928c31
commit
fde0fdb7fa
@ -91,6 +91,12 @@ Bronze Plan
|
||||
{{ end }}
|
||||
{{ define "js" }}
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<script src="/static/js/stripe.js"></script>
|
||||
<script>stripeInit('{{.StripePubKey}}');</script>
|
||||
<script type="module">
|
||||
import {stripeInit} from "/static/js/common.js";
|
||||
import {val} from "/static/js/stripe-plan.js"
|
||||
stripeInit('{{.StripePubKey}}');
|
||||
document.getElementById("pay-button").addEventListener("click", () => {
|
||||
val({{.API}});
|
||||
})
|
||||
</script>
|
||||
{{ end }}
|
||||
|
@ -92,7 +92,6 @@ Buy one widget
|
||||
{{ end }}
|
||||
{{ define "js" }}
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<script type="module" src="/static/js/stripe.js"></script>
|
||||
<script type="module">
|
||||
import {stripeInit} from "/static/js/common.js";
|
||||
import {val} from "/static/js/stripe.js"
|
||||
|
@ -75,7 +75,6 @@ Virtual Terminal
|
||||
{{ end }}
|
||||
{{ define "js" }}
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<script type="module" src="/static/js/stripe.js"></script>
|
||||
<script type="module">
|
||||
import {stripeInit} from "/static/js/common.js";
|
||||
import {val} from "/static/js/stripe.js"
|
||||
|
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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user