代码之家  ›  专栏  ›  技术社区  ›  ThomasArdal

使用带条目的API进行计费(定期订阅)

  •  0
  • ThomasArdal  · 技术社区  · 6 年前

    我使用Stripe.js和令牌向我的客户端添加了一点JavaScript:

    function pay() {
        stripe.createToken(card).then(function (result) {
            if (result.error) {
                // Do something
            } else {
                var token = result.token.id;
                $.post("/api/subscriptions/create?token=" + token, ...);
            }
        });
    }
    

    在服务器上,我将令牌放在客户身上(C中的示例,但可以是任何内容):

    customerService.Update(customerId, new CustomerUpdateOptions
    {
        SourceToken = token,
    });
    

    并创建订阅:

    var items = new List<SubscriptionItemOption> {
        new SubscriptionItemOption {
            PlanId = newPlanId,
        },
    };
    var subscriptionCreateOptions = new SubscriptionCreateOptions
    {
        CustomerId = customerId,
        Items = items,
    };
    Subscription subscription = stripe.Subscriptions.Create(subscriptionCreateOptions);
    

    我现在应该高兴,但我不高兴。当测试上述代码时,它不适用于需要3D安全和类似扩展身份验证检查的卡。在这种情况下,我在创建订阅时从Stripe中得到一个错误,说该卡无效(我想是因为我们从未完成过3D安全身份验证)。

    从条纹文档中可以了解到,显示3D安全身份验证对话框需要使用Checkout或Intents API。我不想使用Checkout,但Intents API看起来是正确的选择。

    使用意图,我需要先请求意图:

    var createOptions = new PaymentIntentCreateOptions {
      Amount = 4900,
      Currency = "usd",
      PaymentMethodTypes = new List<string> { "card" }
    };
    paymentIntents.Create(createOptions);
    

    createToken . 对于客户,我打电话给 handleCardPayment 功能,在需要时显示3D安全模式:

    stripe.handleCardPayment(
        clientSecret, cardElement
      ).then(function(result) {
        if (result.error) {
          // Display error.message in your UI.
        } else {
          $.post("/api/subscriptions/create?...");
        }
      });
    

    问题是 向客户收取费用。我不想那样,因为我想每月自动给客户开发票。

    是否有人知道不使用意图或至少不创建费用就可以显示3D安全(和类似内容)?我读过类似的问题,人们建议创建收费,然后创建一个试用期为1个月的订阅。这没有我想要的效果,因为这会在第一个月产生费用,并在接下来的几个月产生费用发票。

    0 回复  |  直到 6 年前
        1
  •  7
  •   fearis    5 年前

    Stripe目前正致力于将PaymentIntents与订阅整合,并计划在2019年4月支持这一流程。一旦有了它,你肯定会想用PaymentIntents。因为它是在不久的将来,你可能只想等到它可用。

    如果你想让这个同时生效, this guide 引导您通过初始3DS检查设置订阅。这是你所说的试用期的推荐方法。

    更新

    使用支付意图API的非会话支付

    第三点说:

    为了申请豁免,您将需要进行增量更改 客户这将在2019年7月1日前准备好。

    https://stripe.com/docs/strong-customer-authentication/migration#step-2