【发布时间】:2018-11-07 21:09:13
【问题描述】:
我使用 AWS Amplify 进行身份验证,使用 Stripe 进行支付以创建注册页面。
问题:我找不到将电子邮件和密码部分(来自 AWS Amplify)的验证与付款信息部分(来自 Stripe)结合起来的方法。
我当前的代码创建了一个 Stripe 令牌并调用 API(带有有效的支付信息),然后处理来自 userSignupRequest 的错误消息,该消息负责处理电子邮件和密码字段。
如何使用付款信息验证电子邮件和密码,然后在 AWS 和 Stripe 中创建帐户?
// Stripe payment process
this.props.stripe.createToken(
{
email: this.state.email
}
).then(result => {
// PROBLEM: Form server validation from Stripe
if(result.error){
return this.setState({ errors: { errorMsg: result.error.message }, isLoading: false })
}
// if success, create customer and subscription with result.token.id
const apiName = 'NameOfAPI';
const path = '/stripe/signup';
let myInit = {
body: {
"stripeToken": result.token.id,
"email": this.state.email
}
}
API.post(apiName , path, myInit).then(reponse => {
this.props.userSignupRequest(this.state.email, this.state.password, reponse).then(user => {
this.setState({
confirmAccount: true,
isLoading: false,
userEmail: this.state.email,
errors: {}
})
this.props.history.push('/signup#confirm-account')
}).catch(err => {
// PROBLEM: Form server validation
this.setState({ errors: { errorMsg: err.message }, isLoading: false })
})
}).catch(err => {
console.log(err)
this.setState({ errors: { errorMsg: err }, isLoading: false })
});
})
【问题讨论】:
-
给你一个服务器端的解决方案可以吗?如果是这样,您是否使用节点,如果使用 - 什么版本?我认为您的解决方案是关于客户端的最佳解决方案。
-
我正在使用 AWS 放大 API,它使用 Lambda 和节点 6.10
标签: javascript reactjs stripe-payments aws-amplify