Stipe Checkout Form Does Not Send Token To Server
I am trying to integrate a stripe checkout form onto my website which is run from a node.js server on heroku.
The form to collect payment information is provided by stripe:
<form action="/updatepayment" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_DNdN11LpouG0f1x4_____"
data-amount="999"
data-name="[Name]"
data-description="Widget"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto">
</script>
</form>
This are the instructions stripe gives:
The simple integration uses a <script>
tag inside your payment form to render the blue Checkout button. Upon completion of the Checkout process, Checkout submits your form to your server, passing along a stripeToken and any elements your form contains. When adding the following code to your page, make sure that the form submits to your own server-side code within the action attribute
I have also tried different data-keys with no success. When the form is submitted, the page is redirected to the current page and the url then contains the token but nothing is sent to the server.
Answer
You can try below method just add
<script src="https://checkout.stripe.com/checkout.js"></script>
in index.html File
and add <button (click)="openCheckout()">Purchase</button>
in your component html File
and in ts file add below code
openCheckout() {
var tok=this;
var handler = (<any>window).StripeCheckout.configure({
key: '', // Enter your publishable key
locale: 'auto',
token: function (token: any) {
tok.token1(token);
}
});
handler.open({
name: 'Food Style',
description: 'Payment',
amount: this.price * 100,
});
}
token1(token){
console.log(token);
this.paymentservice.defaultcard(token)
.subscribe((result)=>{
console.log(result);
},
(err)=>{
console.log(err);
})
}
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error