0

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.

Dev65
  • 67
  • 9
  • Possible duplicate of [Make a Stripe payment with Jquery AJAX? (Javascript ONLY)](https://stackoverflow.com/questions/38819502/make-a-stripe-payment-with-jquery-ajax-javascript-only) – taintedzodiac Jan 24 '19 at 16:25
  • @taintedzodiac I viewed the question you mentioned in the comment, the problem here is my code is working with no error but the test data not showing on stripe account. – Dev65 Jan 25 '19 at 06:11

2 Answers2

1

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

Silvio Biasiol
  • 856
  • 8
  • 14
1

Yes it is possible to stripe provide JavaScript examples as well you can follow the following link https://stripe.com/docs/stripe-js

Usama Kiyani
  • 195
  • 10