forked from CGM_Public/pretix_original
Stripe: Store refund details
This commit is contained in:
@@ -14,6 +14,7 @@ from django.template.loader import get_template
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.crypto import get_random_string
|
from django.utils.crypto import get_random_string
|
||||||
from django.utils.http import urlquote
|
from django.utils.http import urlquote
|
||||||
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import pgettext, ugettext, ugettext_lazy as _
|
from django.utils.translation import pgettext, ugettext, ugettext_lazy as _
|
||||||
from django_countries import countries
|
from django_countries import countries
|
||||||
|
|
||||||
@@ -417,7 +418,7 @@ class StripeMethod(BasePaymentProvider):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ch = stripe.Charge.retrieve(payment_info['id'], **self.api_kwargs)
|
ch = stripe.Charge.retrieve(payment_info['id'], **self.api_kwargs)
|
||||||
ch.refunds.create(
|
r = ch.refunds.create(
|
||||||
amount=self._get_amount(refund),
|
amount=self._get_amount(refund),
|
||||||
)
|
)
|
||||||
ch.refresh()
|
ch.refresh()
|
||||||
@@ -435,7 +436,13 @@ class StripeMethod(BasePaymentProvider):
|
|||||||
logger.error('Stripe error: %s' % str(err))
|
logger.error('Stripe error: %s' % str(err))
|
||||||
raise PaymentException(_('Stripe returned an error'))
|
raise PaymentException(_('Stripe returned an error'))
|
||||||
else:
|
else:
|
||||||
refund.done()
|
refund.info = str(r)
|
||||||
|
if r.status in ('succeeded', 'pending'):
|
||||||
|
refund.done()
|
||||||
|
elif r.status in ('failed', 'canceled'):
|
||||||
|
refund.state = OrderRefund.REFUND_STATE_FAILED
|
||||||
|
refund.execution_date = now()
|
||||||
|
refund.save()
|
||||||
|
|
||||||
def execute_payment(self, request: HttpRequest, payment: OrderPayment):
|
def execute_payment(self, request: HttpRequest, payment: OrderPayment):
|
||||||
self._init_api()
|
self._init_api()
|
||||||
|
|||||||
Reference in New Issue
Block a user