Reputation: 67
I'm trying to make payment through stripe in hubspot using jquery or javascript My Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script src="https://js.stripe.com/v3/"></script>
<form id="myForm" action="" method="POST">
<input type="text" id="amountInDollars" />
<input type="hidden" id="stripeToken" name="stripeToken" />
<input type="hidden" id="stripeEmail" name="stripeEmail" />
<input type="hidden" id="amountInCents" name="amountInCents" />
</form>
<input type="button" id="customButton" value="Pay">
<script>
var handler = StripeCheckout.configure({
key: 'pk_test_******************',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
token: function(token) {
$("#stripeToken").val(token.id);
$("#stripeEmail").val(token.email);
$("#amountInCents").val(Math.floor($("#amountInDollars").val() * 100));
$("#myForm").submit();
}
});
$('#customButton').on('click', function(e) {
var amountInCents = Math.floor($("#amountInDollars").val() * 100);
var displayAmount = parseFloat(Math.floor($("#amountInDollars").val() * 100) / 100).toFixed(2);
// Open Checkout with further options
handler.open({
name: 'p1',
description: 'Custom amount ($' + displayAmount + ')',
amount: amountInCents,
});
e.preventDefault();
});
// Close Checkout on page navigation
$(window).on('popstate', function() {
handler.close();
});
</script>
So my question here, Is it possible to implement payment module of stripe using javascript or jquery ?? if yes then what am i doing wrong, i cant figure it out. my code is working with no error but the test data not showing on stripe account.
Upvotes: 0
Views: 717
Reputation: 178
Yes it is possible to stripe provide JavaScript examples as well you can follow the following link https://stripe.com/docs/stripe-js
Upvotes: 1
Reputation: 953
Of course is possible to do that, you can use the client-only checkout, the guide is pretty straightforward :) you can add it to your page by creating the form in the Stripe dashboard
Upvotes: 1