我有一个对象:
{
user: activated: true;
createdAt: "2020-07-29T22:19:51.053Z";
email: "db2@bahn.com";
updatedAt: "2020-08-02T13:07:48.992Z";
_id: "5f21f6079f28a2095089c96a";
__proto__: Object;
__proto__: Object;
}
我正在寻找将电子邮件属性从用户对象传递到Stripe createPaymentMethod中的billing_address的方法:
import React from "react";
import { CardElement, useStripe, useElements } from "@stripe/react-stripe-js";
const CheckoutForm = (user) => {
const stripe = useStripe();
const elements = useElements();
console.log(user);
const handleSubmit = async (event) => {
event.preventDefault();
if (!stripe || !elements) {
return;
}
const cardElement = elements.getElement(CardElement);
const { error, paymentMethod } = await stripe.createPaymentMethod({
type: "card",
card: cardElement,
billing_details: {
email: user.email,
},
});
if (error) {
console.log("[error]", error);
} else {
console.log("[PaymentMethod]", paymentMethod);
}
};
return (
<form style={{ width: "400px" }} onSubmit={handleSubmit}>
<CardElement />
<button type="submit" disabled={!stripe}>
Pay
</button>
</form>
);
};
到目前为止,我已经尝试了Object.values(user)和映射函数,但是没有运气。
预先感谢