gpt4 book ai didi

node.js - 为什么 Stripe 付款不完整?

转载 作者:太空宇宙 更新时间:2023-11-03 23:52:42 25 4
gpt4 key购买 nike

我的 Stripe 付款显示在我的仪表板上,但其状态为“未完成”,并且将鼠标悬停在上面会显示提示“客户尚未输入付款方式”。我认为我在 session.create() 方法中考虑了付款方式。

我的 Angular 组件创建一个 StripeCheckout 并将 session 数据发送到我的 API。然后API将其包含在对浏览器的响应中(我的第一次尝试是使用这个sessionId来重定向到结账,但我选择了这个,因为它更流畅)。

Angular/TS StripeCheckout 和处理程序:

let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append(
"authentication",
`Bearer ${this.authServ.getAuthenticatedUserToken()}`
);

this.handler = StripeCheckout.configure({
key: environment.stripe_public_key,
locale: "auto",
source: async source => {
this.isLoading = true;
this.amount = this.amount * 100;
this.sessionURL = `${this.stringValServ.getCheckoutSessionStripeURL}/${this.activeUser.id}/${this.amount}`;
const session = this.http
.get(this.sessionURL, {
headers: new HttpHeaders({
"Content-Type": "application/json",
authentication: `Bearer ${this.authServ.getAuthenticatedUserToken()}`
})
})
.subscribe(res => {
console.log(res);
});
}
});
//so that the charge is depicted correctly on the front end
this.amount = this.amount / 100;
}

async checkout(e) {
this.stripeAmountEvent.emit(this.amount);
this.handler.open({
name: "[REDACTED]",
amount: this.amount * 100,
description: this.description,
email: this.activeUser.email
});
e.preventDefault();
}

NodeJS API 接受它

exports.getCheckoutSession = catchAsync(async (req, res, next) => {
const currentUserId = req.params.userId;
const paymentAmount = req.params.amount;
const user = await User.findById(currentUserId);

const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
success_url: `${process.env.CLIENT_URL}`,
cancel_url: `${process.env.CLIENT_URL}`,
customer_email: user.email,
client_reference_id: user.userId,
line_items: [
{
name: `Donation from ${user.userName}`,
description: '[REDACTED]',
amount: paymentAmount,
currency: 'usd',
quantity: 1,
customer: user.userId
}
]
});

const newPayment = await Payment.create({
amount: paymentAmount,
createdAt: Date.now(),
createdById: user._id
});

res.status(200).send({
status: 'success',
session
});
});

付款在我的数据库中创建,付款显示在我的 Stripe 仪表板上。当我期望它从卡中扣款时,付款显示为“未完成”。

提前致谢。

最佳答案

最新版本Checkout让您可以直接在 Stripe 托管的支付页面上接受付款。这包括收集银行卡详细信息、显示您购物车中的商品以及确保客户在重定向到您的网站之前付款。

但目前,您的代码错误地将多种产品混合在一处。您的客户端代码使用 Legacy Checkout 。这是 Stripe 产品的旧版本,您可以使用它来安全地收集卡详细信息。这不是你应该再使用的东西。

然后在服务器端,您正在使用较新版本的 Checkout通过创建一个 session 。这部分是正确的,但您似乎从未使用过它。

相反,您需要在服务器端创建 session ,然后在客户端,您只需使用 redirectToCheckout 重定向到 Stripe,如文档 here 所示。 .

关于node.js - 为什么 Stripe 付款不完整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58757239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com