[英]Stripe - Accept a payment throws integration error
I am working on my app made in reactjs
and nodejs
.我正在开发
reactjs
和nodejs
制作的应用程序。 I am following this guide for react web. I am using react-stripe-elements
.我正在按照本指南进行反应 web。我正在使用
react-stripe-elements
。 My version for react-stripe-elements
is ^3.0.1
.我的
react-stripe-elements
版本是^3.0.1
。 Here is what my front end code looks like.这是我的前端代码的样子。
checkout.js结帐.js
import React, { Component } from "react";
import {
CardNumberElement,
CardExpiryElement,
CardCVCElement,
injectStripe,
} from "react-stripe-elements";
import axios from 'axios';
const createOptions = () => {
return {
style: {
base: {
fontSize: "16px",
color: "#0382FF",
fontFamily: "Quicksand",
letterSpacing: "2px",
fontSmoothing: "antialiased",
"::placeholder": {
color: "#40e8cb87"
},
padding: "10px"
},
invalid: {
color: "#9e2146"
}
}
};
};
class CheckoutFormIntent extends Component {
constructor(props) {
super(props);
this.cardNumberRef = React.createRef();
}
GetClientSecret = async () => {
await axios.get('/api/stripe-client-secret');
return {
clientSecret: res.data.client_secret,
};
}
handleSubmit = async ev => {
ev.preventDefault();
const { stripe } = this.props;
if (stripe) {
setloader(true);
this.GetClientSecret().then(responseJson => {
const { clientSecret } = responseJson;
stripe
.confirmCardPayment(clientSecret, {
payment_method: { cardNumber: this.cardNumberRef.current }
})
.then(result => {
// Display error.message in your UI.
if (result.error) {
console.log("error");
} else {
console.log("success");
}
})
.catch(error => {
console.log(error);
});
});
}
};
render() {
return (
<>
<form onSubmit={this.handleSubmit}>
<div>
<div>
<span>Card Number</span>
<CardNumberElement
{...createOptions()}
ref={this.cardNumberRef}
placeholder="1234 1234 1234 1234"
/>
</div>
<div className="expCvc">
<div>
<span>Expiry Date</span>
<CardExpiryElement {...createOptions()} />
</div>
<div>
<span>Security Code</span>
<CardCVCElement {...createOptions()} placeholder="CVV" />
</div>
</div>
</div>
<button type="submit" disabled={isSubmitting} className="btnSubmit">
PAY 25
</button>
</form>
</>
);
}
}
export default injectStripe(CheckoutFormIntent);
I successfully got the client secret from the backend but when the code reached at confirmCardPayment
it throws this error integration error Invalid value for confirmCardPayment: payment_method.card should be object or element. You specified: undefined
我成功地从后端获取了客户端密码,但是当代码到达
confirmCardPayment
时,它抛出此错误integration error Invalid value for confirmCardPayment: payment_method.card should be object or element. You specified: undefined
integration error Invalid value for confirmCardPayment: payment_method.card should be object or element. You specified: undefined
. integration error Invalid value for confirmCardPayment: payment_method.card should be object or element. You specified: undefined
。 I have gone through every document of stripe, they have implemented the cardElement
which gets cardnumber
, cvc
and expiry
instead of react-stripe-elements
.我已经浏览了每个条带文档,他们已经实现了
cardElement
,它获取cardnumber
、 cvc
和expiry
而不是react-stripe-elements
。 I tried to use elements to collect information but no success.我尝试使用元素来收集信息但没有成功。
I finally made it.我终于做到了。 Here it is how it worked.
这就是它的工作原理。
.confirmCardPayment(clientSecret, {
payment_method: { card: this.cardNumberRef.current._element },
})
You're not passing the card
Element in payment_method: { card: cardElement }
as it's expecting you to per the docs .您没有在
payment_method: { card: cardElement }
中传递card
元素,因为它希望您按照文档传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.