找不到指定的结帐会话

问题描述

目标:使用 Stripe 的结账 API 创建一个成功的(测试)结账会话。

[他们的 Checkout 教程链接在这里https://github.com/stripe-samples/checkout-one-time-payments]

我正在使用我的 UI 创建一个结帐会话,并使用以下代码使用提供给后端 Web 服务的数据构建结帐会话:

            var options = new Stripe.Checkout.SessionCreateOptions
            {
                PaymentMethodTypes = new List<string>
                {
                    "card",},LineItems = stripeCartLineItems,Mode = "payment",SuccessUrl = "https://" + HostName + "/Stripe/OrderPlaced",CancelUrl = "https://example.com/cancel",};

            var requestOptions = new RequestOptions
            {
                StripeAccount = stripeConnectedAccountId,ApiKey = StripeConfiguration.ApiKey
            };

            var service = new Stripe.Checkout.SessionService();
            Stripe.Checkout.Session session = service.Create(options,requestOptions);

            return Json(new { sessionId = session.Id });

如您所见,我收到了来自 Stripe 的 API 的确认,其中包含一个有效的结帐会话 ID:

enter image description here

登录 Stripe 的仪表板确认结帐会话成功:

enter image description here

但是,我不断收到此错误消息:

enter image description here

API 密钥已经刷新并正确放置。那不是问题...加载测试结帐页面失败。我在 Stripe 仪表板中的日志是这样说的:

enter image description here

启动重定向到 Stripe 结帐体验的 Javascript 调用是直接从他们的教程(粘贴在上面)中复制的。该代码如下所示:

           checkoutButton.addEventListener('click',function () {
                $.ajax({
                    url: "/Stripe/CreateCheckoutSession",method: "POST",data: { stripeConnectedAccountId: stripeConnectedAccountId,cartLineItems: scope.cartLineItems },}).done(function (resp) {

                    stripe.redirecttocheckout({
                        sessionId: resp.sessionId
                    }).then(function (result) {
                        // If `redirecttocheckout` fails due to a browser or network
                        // error,display the localized error message to your customer
                        // using `result.error.message`.
                        alert(result.error.message);
                    });
                })

前往后:https://stripe.com/docs/error-codes/resource-missing。文档针对该特定错误代码说明了这一点:“提供的 ID 无效。资源不存在,或者提供了其他资源的 ID。”

好的条纹。一定一定。你制作了这个 API - 我会听的。但是,根据您的文档、Intellisense 和您的示例代码...我的代码是正确的,我使用了您在启动结帐会话后发送给我的响应对象提供的 session.Id:

enter image description here

我不知道如何继续。 任何想法表示赞赏。

解决方法

如果您已经验证了来自服务器和条带的会话和密钥, 请检查您的客户端使用的条带密钥。用于在客户端和服务器中初始化条带的公钥应该相同。

检查客户端的日志以确保密钥相同。