我正在尝试在条纹上使用订阅模式实现贝宝支付方法,它在测试模式下工作正常,但在实时模式下我收到此错误: { “错误”: { "message": "您的帐户未启用 PayPal 定期付款。您可以删除
setup_future_usage
或使用以下说明启用 PayPal 定期付款:https://stripe.com/docs/ payments/paypal/set-未来付款”,
"request_log_url": "https://dashboard.stripe.com/logs/req_MVBaUD0dASTgB7?t=1713974563",
“类型”:“无效请求错误”
}
}
我真的不太明白,因为 PayPal 在 stripe 中很活跃,而且我有一个帐户链接到 stripe。
这是客户端和服务器端代码:
Server Side
exports.createCheckoutSession = async function (req, res) {
const data = req.body;
const accountId = data.accountId;
const plan = data.plan;
const accountData = await account.get(accountId);
utils.assert(accountData, "No account with that ID", null, "NO-ACCOUNT");
// Create new Checkout Session for the order
try {
// Create customer
const customer = await stripe.customers.create({
email: accountData.email,
});
const session = await stripe.checkout.sessions.create({
mode: "subscription",
payment_method_types: ["paypal"],
line_items: [{ price: plan, quantity: 1 }],
customer:id,
success_url: `${domain}/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${domain}/cancel`,
automatic_tax: { enabled: true },
customer_update: {
address: 'auto',
},
});
res.json({url: session.url});
} catch (e) {
res.status(400);
return res.send({
error: {
message: e.message,
},
});
}
};
exports.retreiveCheckoutSession = async (req, res) => {
const { sessionId } = req.query;
const session = await stripe.checkout.sessions.retrieve(sessionId);
res.send(session);
};
exports.saveSessiondata = async function (req, res) {
const data = req.body;
const accountId = data.accountId;
const stripeData = data.stripeData;
let subscription;
let plan
if (stripeData.subscription) {
subscription = await stripe.subscriptions.create(stripeData.subscription);
}}
Client Side
const [, setSessionId] = useState("");
const [, setSessionJSON] = useState("");
const [loading, setLoading] = useState(false)
const user = JSON.parse(localStorage.getItem("user"));
const activeAccountId = user.account_id;
const history = useHistory();
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
const sessionId = urlParams.get("session_id");
const fetchSession = async () => {
if (sessionId) {
setSessionId(sessionId);
const session = await fetch(
`${BFF_SAAS_SERVER_URL}/checkout-session?sessionId=${sessionId}`
).then((r) => r.json());
const sessionJSON = JSON.stringify(session, null, 2);
setSessionJSON(sessionJSON);
saveStripeData(session);
}
};
const saveStripeData = async (session) => {
try {
const stripeData = {
subscription: session.subscription,
customer: session.customer,
};
setLoading(true);
await fetch(`${BFF_SAAS_SERVER_URL}/save-session-data`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ stripeData, activeAccountId }),
});
console.log("Session data saved successfully");
setTimeout(() => {
setLoading(false);
history.push("/offre");
}, 1000);
} catch (error) {
console.error("Error saving session data:", error);
}
};
fetchSession();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
看起来您只需要在您的帐户上启用 PayPal 定期付款即可。默认情况下未启用这些功能,因此只需按照此处的说明进行操作即可。