forked from CGM_Public/pretix_original
Expose some payment details in exports
This commit is contained in:
committed by
Raphael Michel
parent
fd78e31861
commit
e358bacfa3
@@ -122,6 +122,8 @@ The provider class
|
|||||||
|
|
||||||
.. automethod:: refund_control_render
|
.. automethod:: refund_control_render
|
||||||
|
|
||||||
|
.. automethod:: refund_control_render_short
|
||||||
|
|
||||||
.. automethod:: new_refund_control_form_render
|
.. automethod:: new_refund_control_form_render
|
||||||
|
|
||||||
.. automethod:: new_refund_control_form_process
|
.. automethod:: new_refund_control_form_process
|
||||||
|
|||||||
@@ -796,17 +796,17 @@ class PaymentListExporter(ListExporter):
|
|||||||
payments = OrderPayment.objects.filter(
|
payments = OrderPayment.objects.filter(
|
||||||
order__event__in=self.events,
|
order__event__in=self.events,
|
||||||
state__in=form_data.get('payment_states', [])
|
state__in=form_data.get('payment_states', [])
|
||||||
).order_by('created')
|
).select_related('order').prefetch_related('order__event').order_by('created')
|
||||||
refunds = OrderRefund.objects.filter(
|
refunds = OrderRefund.objects.filter(
|
||||||
order__event__in=self.events,
|
order__event__in=self.events,
|
||||||
state__in=form_data.get('refund_states', [])
|
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)
|
objs = sorted(list(payments) + list(refunds), key=lambda o: o.created)
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
_('Event slug'), _('Order'), _('Payment ID'), _('Creation date'), _('Completion date'), _('Status'),
|
_('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
|
yield headers
|
||||||
|
|
||||||
@@ -819,6 +819,18 @@ class PaymentListExporter(ListExporter):
|
|||||||
d2 = obj.execution_date.astimezone(tz).date().strftime('%Y-%m-%d')
|
d2 = obj.execution_date.astimezone(tz).date().strftime('%Y-%m-%d')
|
||||||
else:
|
else:
|
||||||
d2 = ''
|
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 = [
|
row = [
|
||||||
obj.order.event.slug,
|
obj.order.event.slug,
|
||||||
obj.order.code,
|
obj.order.code,
|
||||||
@@ -830,6 +842,8 @@ class PaymentListExporter(ListExporter):
|
|||||||
obj.amount * (-1 if isinstance(obj, OrderRefund) else 1),
|
obj.amount * (-1 if isinstance(obj, OrderRefund) else 1),
|
||||||
provider_names.get(obj.provider, obj.provider),
|
provider_names.get(obj.provider, obj.provider),
|
||||||
obj.comment if isinstance(obj, OrderRefund) else "",
|
obj.comment if isinstance(obj, OrderRefund) else "",
|
||||||
|
matching_id,
|
||||||
|
payment_details,
|
||||||
]
|
]
|
||||||
yield row
|
yield row
|
||||||
|
|
||||||
|
|||||||
@@ -821,11 +821,11 @@ class BasePaymentProvider:
|
|||||||
"""
|
"""
|
||||||
Will be called if the *event administrator* performs an action on the payment. Should
|
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.
|
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``.
|
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)
|
return self.payment_presale_render(payment)
|
||||||
|
|
||||||
@@ -842,6 +842,18 @@ class BasePaymentProvider:
|
|||||||
"""
|
"""
|
||||||
return ''
|
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:
|
def payment_presale_render(self, payment: OrderPayment) -> str:
|
||||||
"""
|
"""
|
||||||
Will be called if the *ticket customer* views the details of a payment. This is
|
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)
|
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):
|
def api_payment_details(self, payment: OrderPayment):
|
||||||
from .models import GiftCard
|
from .models import GiftCard
|
||||||
try:
|
try:
|
||||||
@@ -1464,7 +1484,7 @@ class GiftCardPayment(BasePaymentProvider):
|
|||||||
)
|
)
|
||||||
refund.info_data = {
|
refund.info_data = {
|
||||||
'gift_card': gc.pk,
|
'gift_card': gc.pk,
|
||||||
'gift_card_code': gc.secret,
|
'gift_card_secret': gc.secret,
|
||||||
'transaction_id': trans.pk,
|
'transaction_id': trans.pk,
|
||||||
}
|
}
|
||||||
refund.done()
|
refund.done()
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ from django.urls import reverse
|
|||||||
from django.utils import formats
|
from django.utils import formats
|
||||||
from django.utils.formats import date_format, get_format
|
from django.utils.formats import date_format, get_format
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
from django.utils.html import conditional_escape
|
||||||
from django.utils.http import url_has_allowed_host_and_scheme
|
from django.utils.http import url_has_allowed_host_and_scheme
|
||||||
from django.utils.timezone import make_aware, now
|
from django.utils.timezone import make_aware, now
|
||||||
from django.utils.translation import gettext, gettext_lazy as _, ngettext
|
from django.utils.translation import gettext, gettext_lazy as _, ngettext
|
||||||
@@ -1126,7 +1127,7 @@ class OrderRefundView(OrderView):
|
|||||||
|
|
||||||
for p in payments:
|
for p in payments:
|
||||||
if p.payment_provider:
|
if p.payment_provider:
|
||||||
p.html_info = (p.payment_provider.payment_control_render_short(p) or "").strip()
|
p.html_info = conditional_escape(p.payment_provider.payment_control_render_short(p) or "").strip()
|
||||||
|
|
||||||
return render(self.request, 'pretixcontrol/order/refund_choose.html', {
|
return render(self.request, 'pretixcontrol/order/refund_choose.html', {
|
||||||
'payments': payments,
|
'payments': payments,
|
||||||
|
|||||||
Reference in New Issue
Block a user