使用 Stripe 和 Python-Flask 订阅的示例?

Mor*_*ndy 5 python flask flask-sqlalchemy stripe-payments

我试图找出使用 Stripe 于 2019 年 7 月 1 日提供的新工具集编写简单订阅的方法(请参阅此处https://stripe.com/docs/payments/checkout/fulfillment)以满足 SCA 规定,但它对我不起作用。如果有人可以在 Flask/Python 中分享一个完整的示例(结帐、查看等),那就太好了。

我附上了我在使用 Stripe 仪表板创建产品和计划后实现的代码。我的客户将来自我的代码/数据库,这是我尚未真正开发的东西。

视图.py

@app.route('/checkout', methods=['GET', 'POST'])
def checkout():
    session = stripe.checkout.Session.create(
      payment_method_types=['card'],
      subscription_data={
        'items': [{
          'plan': 'my_plan_id',
        }],
      },
      success_url='https://mywebsite.com',
      cancel_url='https://mywebsite.com',
    )

    print(session)

    return render_template('/web/premium/checkout.html')
Run Code Online (Sandbox Code Playgroud)

checkout.html 是

<script src="https://js.stripe.com/v3/"></script>

<script>
var stripe = Stripe('pk_test_jOuM3bOylIuDHhxMk19ut3CH');

stripe.redirectToCheckout({
  items: [
    {sku: 'my_product_id', quantity: 1}
  ],
  successUrl: 'https://mywebsite.com',
  cancelUrl: 'https://mywebsite.com',
  submitType: 'donate',
}).then(function (result) {
});


</script>
Run Code Online (Sandbox Code Playgroud)

这是我打印“会话”时得到的:

{
  "billing_address_collection": null,
  "cancel_url": "https://mywebsite.com",
  "client_reference_id": null,
  "customer": null,
  "customer_email": null,
  "display_items": [
    {
      "amount": 299,
      "currency": "eur",
      "plan": {
        "active": true,
        "aggregate_usage": null,
        "amount": 299,
        "billing_scheme": "per_unit",
        "created": 1562261496,
        "currency": "eur",
        "id": "my_plan_id",
        "interval": "month",
        "interval_count": 1,
        "livemode": false,
        "metadata": {},
        "nickname": "Monthly",
        "object": "plan",
        "product": "my_product_id",
        "tiers": null,
        "tiers_mode": null,
        "transform_usage": null,
        "trial_period_days": null,
        "usage_type": "licensed"
      },
      "quantity": 1,
      "type": "plan"
    }
  ],
  "id": "cs_test_id",
  "livemode": false,
  "locale": null,
  "object": "checkout.session",
  "payment_intent": null,
  "payment_method_types": [
    "card"
  ],
  "submit_type": null,
  "subscription": null,
  "success_url": "https://mywebsite.com"
Run Code Online (Sandbox Code Playgroud)