Skip to content
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

Bugfix on Zero total Invoice #429

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/vendor/api/v1/stripe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def post(self, request, *args, **kwargs):
logger.error(f"StripeSubscriptionPaymentFailed error: email: {stripe_invoice.customer_email} does not exist")
return HttpResponse(status=200, content=f"StripeSubscriptionPaymentFailed error: email: {stripe_invoice.customer_email} does not exist")


try:
subscription = Subscription.objects.get(gateway_id=stripe_invoice.subscription, profile=customer_profile)
except ObjectDoesNotExist:
Expand Down Expand Up @@ -195,7 +194,6 @@ class StripeInvoicePaid(StripeBaseAPI):
def post(self, request, *args, **kwargs):
site = get_site_from_request(self.request)
processor = StripeProcessor(site)


if not self.is_valid_post(site):
logger.error("StripeInvoicePaid error: invalid post")
Expand Down Expand Up @@ -312,7 +310,12 @@ def process_stripe_invoice_subscription_payment_succeded(stripe_invoice, site):
processor = StripeProcessor(site)

paid_date = timezone.datetime.fromtimestamp(stripe_invoice.status_transitions.paid_at, tz=timezone.utc)
stripe_charge = processor.stripe_get_object(processor.stripe.Charge, stripe_invoice.charge)
payment_status = PurchaseStatus.SETTLED

if stripe_invoice.charge:
stripe_charge = processor.stripe_get_object(processor.stripe.Charge, stripe_invoice.charge)
payment_status = processor.get_payment_status(stripe_charge.status, stripe_charge.refunded)

stripe_subscription = processor.stripe_get_object(processor.stripe.Subscription, stripe_invoice.subscription)
subscription = processor.get_subscription(stripe_subscription)

Expand All @@ -331,7 +334,6 @@ def process_stripe_invoice_subscription_payment_succeded(stripe_invoice, site):
logger.error(msg)
return HttpResponse(status=200, content=msg)

payment_status = processor.get_payment_status(stripe_charge.status, stripe_charge.refunded)
processor.invoice, created = processor.get_or_create_invoice_from_stripe_invoice(stripe_invoice, offer, customer_profile)
processor.renew_subscription(subscription, stripe_invoice.charge, payment_status, payment_success=True, submitted_date=paid_date)

Expand Down