Unable to create stripe token

梦想的初衷 提交于 2021-01-29 16:32:21

问题


I am trying to create token of Card but I don't know how to do it. let say I have Data like this in my state

this.state = {
paymentInfo : {
cardNumber : '4242424242424242',
expiry_month : 12,
expiry_year : 22,
cardCvc : 123
} 
}

createToken = () => {
  const {stripe} = this.props;
  const element = stripe.elements();

//From here I don't know how to use data in my State to generate a token 
}

Your help would be appreciated.


回答1:


The recommended approach is to not maintain credit card information in your React state. If you handle credit card information in this way, it opens up your business to complex regulatory requirements [1]. Avoiding this is one of the main benefits of using Stripe, and specifically, Stripe Elements [2].

For React, the following docs here will guide you through the process of accepting a payment using our latest APIs:

https://stripe.com/docs/payments/accept-a-payment#web

Each client-side code example in the above guide has a "React" tab that you can switch over to if necessary.

I would also recommend watching Stripe's Developer Office Hours video for getting started with React:

  • Video: https://youtu.be/w1oLdAPyuok
  • Demo: https://github.com/tmarek-stripe/demo-react-stripe-js

If you absolutely must handle credit card information in this way, then of course, Stripe can accommodate that. The approach would be to securely send the credit card information to your server, and tokenize the details using the following API here:

https://stripe.com/docs/api/payment_methods/create

Note that the PaymentMethods API is Stripe's new API for tokenizing card details (replacing the Tokens API).

[1] https://stripe.com/en-dk/guides/pci-compliance [2] https://stripe.com/docs/stripe-js



来源:https://stackoverflow.com/questions/61755834/unable-to-create-stripe-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!