New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync cards via webhook #41
Conversation
aa_stripe/models.py
Outdated
else: | ||
raise StripeWebhookParseError(_("Card with this id does not exists at Stripe API")) | ||
else: | ||
raise StripeWebhookParseError(_("Card with this id and customer already exists")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll have this error each time a new card gets created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i'll ignore this case
aa_stripe/models.py
Outdated
@@ -583,6 +594,35 @@ def _parse_coupon_notification(self, action): | |||
elif action == "deleted": | |||
StripeCoupon.objects.filter(coupon_id=coupon_id, created=created).delete() | |||
|
|||
def _parse_customer_source_notification(self, action): | |||
stripe_card_id = self.raw_data["data"]["object"]["id"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if type != card:
return
aa_stripe/models.py
Outdated
elif action == "updated": | ||
try: | ||
card = StripeCard.objects.get(stripe_card_id=stripe_card_id, customer=customer) | ||
for updated_field in StripeCard.STRIPE_UPDATABLE_FIELDS & set( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment above deleted - it was invalid. Anyway, it would be best to just call here "retrieve from stripe" & update the card based on the newest data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
aa_stripe/models.py
Outdated
@@ -125,6 +126,16 @@ def create_at_stripe(self): | |||
self.save() | |||
return self | |||
|
|||
def sync_with_stripe(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to refresh_from_stripe
in other places.
aa_stripe/models.py
Outdated
except StripeCustomer.DoesNotExist: | ||
raise StripeWebhookParseError( | ||
_("There is no customer with id that is assigned to this card in our database")) | ||
if action == "created": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line break before it for better readable.
e751c25
to
f59c7a2
Compare
No description provided.