我试图为一个项目实施条带支付,但卡片元素的输入显示不正确:
你可以在这里看到它的显示
这是我的代码:
结帐组件
import React, { useState, useEffect } from "react";
import { CardElement, useStripe, useElements } from "@stripe/react-stripe-js";
import { useSelector, useDispatch } from "react-redux";
import { createPaymentIntent } from "../functions/stripe";
const StripeCheckout = ({ history }) => {
const [succeeded, setSucceeded] = useState(false);
const [error, setError] = useState(null);
const [processing, setProcessing] = useState("");
const [disabled, setDisabled] = useState(true);
const [clientSecret, setClientSecret] = useState("");
const stripe = useStripe();
const elements = useElements();
const cardStyle = {
style: {
base: {
color: "#32325d",
fontFamily: "Arial, sans-serif",
fontSmoothing: "antialiased",
fontSize: "16px",
"::placeholder": {
color: "#32325d",
},
},
invalid: {
color: "#fa755a",
iconColor: "#fa755a",
},
},
};
return (
<>
<form id="payment-form" className="stripe-form" onSubmit={handleSubmit}>
<CardElement
id="card-element"
options={cardStyle}
onChange={handleChange}
/>
<button
className="stripe-button"
disabled={processing || disabled || succeeded}
>
<span id="button-text">
{processing ? <div className="spinner" id="spinner"></div> : "Pay"}
</span>
</button>
</form>
</>
);
};
export default StripeCheckout;
和支付页面
import React from "react";
import { loadStripe } from "@stripe/stripe-js";
import { Elements } from "@stripe/react-stripe-js";
import StripeCheckout from "../components/StripeCheckout";
import "../stripe.css";
const promise = loadStripe(process.env.STRIPE_PUBLIC);
const Payment = () => {
return (
<div className="container p-5 text-center">
<h4>Complete your purchase</h4>
<Elements stripe={promise}>
<div className="col-md-8 offset-md-2">
<StripeCheckout />
</div>
</Elements>
</div>
);
};
export default Payment;
如果有人添加建议或可以提供工作示例,我没有看到我的输入代码显示不正确的任何问题。