首页 > 解决方案 > 无法获取 Stripe Checkout 会话对象

问题描述

Stripe.Net v34.16.0 在创建结帐会话对象时反弹我的代码,响应如下:

StripeException:没有这样的计划:plan_myPlanId;实时模式中存在类似的对象,但使用了测试模式密钥来发出此请求。

我没有在 Stripe Dashboard 中看到将给定计划指定为测试计划的方法。我也看不到任何类似于模式属性的东西.. 我的代码

public async Task<IActionResult> Index()
            {

                //var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                //user = await _userManager.FindByIdAsync(userId);

                StripeConfiguration.ApiKey = "sk_test_mytestkey"; 


                var options = new Stripe.Checkout.SessionCreateOptions
                {               
                    PaymentMethodTypes = new List<string> {
                        "card",
                    },
                    SubscriptionData = new Stripe.Checkout.SessionSubscriptionDataOptions
                    {
                        Items = new List<SessionSubscriptionDataItemOptions> {
                            new SessionSubscriptionDataItemOptions {
                                Plan = "plan_myplanid",
                            },
                        },
                    },
    //to do
                    SuccessUrl = "localhost://home",
                    CancelUrl = "localhost://home",
                    //CancelUrl = "https://example.com/cancel",
                };

                var service = new Stripe.Checkout.SessionService();

                Stripe.Checkout.Session session = service.Create(options); //error out here           

                StripeCheckoutSessionId stripeCheckoutSessionId = new StripeCheckoutSessionId();
                stripeCheckoutSessionId.StripeSessionID = session.Id;

                return View(stripeCheckoutSessionId);

            }

我指的是 .Net 选项卡中的 Stripe 示例代码:https ://stripe.com/docs/payments/checkout/subscriptions/starting

感谢您在纠正我的错误方面的指导。

标签: stripe-payments

解决方案


推荐阅读