Dj-stripe: Coupon object missing is_valid property

Created on 29 Jul 2018  路  6Comments  路  Source: dj-stripe/dj-stripe

There's no way to tell if a coupon is still valid from the models alone unless checking with data from stripe. Can we add this property to the model so it gets sync'ed as well?

Response from stripe:

<Coupon coupon id=$1OFF at 0x00000a> JSON: {
  "id": "$1OFF",
  "object": "coupon",
  "amount_off": 100,
  "created": 1433453599,
  "currency": "usd",
  "duration": "forever",
  "duration_in_months": null,
  "livemode": false,
  "max_redemptions": null,
  "metadata": {
  },
  "name": null,
  "percent_off": null,
  "redeem_by": null,
  "times_redeemed": 0,
  "valid": true
}
enhancement good first issue

All 6 comments

The reason that property isn't synced is because it updates out of band without broadcasting through a webhook (due to the redeem_by property).

My plan was to add it as an actual python property instead of feeding it through the model, so it's always correct. eg:

    @property
    def valid(self):
        if self.redeem_by and self.redeem_by > timezone.now():
            return False

        if self.max_redemptions and self.times_redeemed >= self.max_redemptions:
            return False

        return True

I think this should be correct but it's untested.

Weird though with v1.2.0 that I'm using and stripe v2018-05-21 I do see it get updated via webhooks. I'm using a OneToOne model to attach this property only and I update it with those webhooks.

I've invalidated the coupon via stripe console and also via using all of its available uses. Perhaps stripe fixed this in latest versions?

If you set a coupon to expire at a certain date, you won't receive a webhook at that date to update the valid property on the coupon itself. That's the main issue. (Unless they fixed it and didn't tell anyone)

Gotcha, I'll try to see if that's still true and get back to you, otherwise I'll use your snippet instead, thanks

When are you planning on adding this feature?

@jleclanche I have checked it and they (still) do not send an event when a coupon expires

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Copser picture Copser  路  6Comments

MarcMacia picture MarcMacia  路  3Comments

banool picture banool  路  6Comments

jcobacho picture jcobacho  路  4Comments

therefromhere picture therefromhere  路  4Comments