6

I tried to work out the way to write a simple subscription using the new set of tools provided by Stripe on 1st July 2019 (see here https://stripe.com/docs/payments/checkout/fulfillment) to fulfil SCA regulations but it does not work for me. It would be great if someone can share a full example (checkout, view, etc...) to do this in Flask/Python.

I attached the code I implemented after creating the product and the plan using the Stripe dashboard. My customer will come from my code/database that it is something that I haven't really developed.

views.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')

checkout.html is

<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>

This is what I got when I print "session":

{
  "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"

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.