Expose some payment details in exports

This commit is contained in:
Raphael Michel
2023-02-15 13:04:50 +01:00
committed by Raphael Michel
parent fd78e31861
commit e358bacfa3
4 changed files with 44 additions and 7 deletions

View File

@@ -796,17 +796,17 @@ class PaymentListExporter(ListExporter):
payments = OrderPayment.objects.filter(
order__event__in=self.events,
state__in=form_data.get('payment_states', [])
).order_by('created')
).select_related('order').prefetch_related('order__event').order_by('created')
refunds = OrderRefund.objects.filter(
order__event__in=self.events,
state__in=form_data.get('refund_states', [])
).order_by('created')
).select_related('order').prefetch_related('order__event').order_by('created')
objs = sorted(list(payments) + list(refunds), key=lambda o: o.created)
headers = [
_('Event slug'), _('Order'), _('Payment ID'), _('Creation date'), _('Completion date'), _('Status'),
_('Status code'), _('Amount'), _('Payment method'), _('Comment'),
_('Status code'), _('Amount'), _('Payment method'), _('Comment'), _('Matching ID'), _('Payment details'),
]
yield headers
@@ -819,6 +819,18 @@ class PaymentListExporter(ListExporter):
d2 = obj.execution_date.astimezone(tz).date().strftime('%Y-%m-%d')
else:
d2 = ''
matching_id = ''
payment_details = ''
try:
if isinstance(obj, OrderPayment):
matching_id = obj.payment_provider.matching_id(obj) or ''
payment_details = obj.payment_provider.payment_control_render_short(obj)
elif isinstance(obj, OrderRefund):
matching_id = obj.payment_provider.refund_matching_id(obj) or ''
payment_details = obj.payment_provider.refund_control_render_short(obj)
except Exception:
pass
row = [
obj.order.event.slug,
obj.order.code,
@@ -830,6 +842,8 @@ class PaymentListExporter(ListExporter):
obj.amount * (-1 if isinstance(obj, OrderRefund) else 1),
provider_names.get(obj.provider, obj.provider),
obj.comment if isinstance(obj, OrderRefund) else "",
matching_id,
payment_details,
]
yield row

View File

@@ -821,11 +821,11 @@ class BasePaymentProvider:
"""
Will be called if the *event administrator* performs an action on the payment. Should
return a very short version of the payment method. Usually, this should return e.g.
a transaction ID or account identifier, but no information on status, dates, etc.
an account identifier of the payee, but no information on status, dates, etc.
The default implementation falls back to ``payment_presale_render``.
:param order: The order object
:param payment: The payment object
"""
return self.payment_presale_render(payment)
@@ -842,6 +842,18 @@ class BasePaymentProvider:
"""
return ''
def refund_control_render_short(self, refund: OrderRefund) -> str:
"""
Will be called if the *event administrator* performs an action on the refund. Should
return a very short description of the refund method. Usually, this should return e.g.
an account identifier of the refund recipient, but no information on status, dates, etc.
The default implementation returns an empty string.
:param refund: The refund object
"""
return ''
def payment_presale_render(self, payment: OrderPayment) -> str:
"""
Will be called if the *ticket customer* views the details of a payment. This is
@@ -1290,6 +1302,14 @@ class GiftCardPayment(BasePaymentProvider):
}
return template.render(ctx)
def payment_control_render_short(self, payment: OrderPayment) -> str:
d = payment.info_data
return d.get('gift_card_secret', self.public_name)
def refund_control_render_short(self, refund: OrderRefund) -> str:
d = refund.info_data
return d.get('gift_card_secret', d.get('gift_card_code', self.public_name))
def api_payment_details(self, payment: OrderPayment):
from .models import GiftCard
try:
@@ -1464,7 +1484,7 @@ class GiftCardPayment(BasePaymentProvider):
)
refund.info_data = {
'gift_card': gc.pk,
'gift_card_code': gc.secret,
'gift_card_secret': gc.secret,
'transaction_id': trans.pk,
}
refund.done()