nadermx
nadermx

Reputation: 2776

Cancel stripe subscription via information in metadata

I'm currently trying to cancel a subscription via parsing the stripe customer list and searching in each of them if the meta data matches.

Currently this is not working.

customers = stripe.Customer.list(limit=100)
for c in customers.auto_paging_iter():
    if bool(c.metadata):
        try:
            if user.username == c.metadata.username:
                for s in c.subscriptions.data:
                    subscription = stripe.Subscription.retrieve(s['id'])
                    subscription.delete(at_period_end=True)
                commit()
                return jsonify(status=True)
        except:
            continue

Am I missing something?

Upvotes: 2

Views: 474

Answers (1)

nadermx
nadermx

Reputation: 2776

so I just figured it out, apparently

subscription = stripe.Subscription.retrieve(s['id']) 

does not work

it has to be

subscription = c.subscriptions.retrieve(s['id'])

Upvotes: 1

Related Questions