Add BasePaymentProvider.matching_id()

This commit is contained in:
Raphael Michel
2020-01-27 21:46:36 +01:00
parent 8c7d7a3055
commit 889dd651ef
5 changed files with 36 additions and 1 deletions

View File

@@ -531,10 +531,11 @@ class InvoiceDataExporter(MultiSheetListExporter):
_('Foreign currency rate'),
_('Total value (with taxes)'),
_('Total value (without taxes)'),
_('Payment matching IDs'),
]
qs = self.event.invoices.order_by('full_invoice_no').select_related(
'order', 'refers'
).annotate(
).prefetch_related('order__payments').annotate(
total_gross=Subquery(
InvoiceLine.objects.filter(
invoice=OuterRef('pk')
@@ -551,6 +552,16 @@ class InvoiceDataExporter(MultiSheetListExporter):
)
)
for i in qs:
pmis = []
for p in i.order.payments.all():
if p.state in (OrderPayment.PAYMENT_STATE_CONFIRMED, OrderPayment.PAYMENT_STATE_CREATED,
OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_REFUNDED):
pprov = p.payment_provider
if pprov:
mid = pprov.matching_id(p)
if mid:
pmis.append(mid)
pmi = '\n'.join(pmis)
yield [
i.full_invoice_no,
date_format(i.date, "SHORT_DATE_FORMAT"),
@@ -581,6 +592,7 @@ class InvoiceDataExporter(MultiSheetListExporter):
i.foreign_currency_rate,
i.total_gross if i.total_gross else Decimal('0.00'),
Decimal(i.total_net if i.total_net else '0.00').quantize(Decimal('0.01')),
pmi
]
elif sheet == 'lines':
yield [

View File

@@ -721,6 +721,16 @@ class BasePaymentProvider:
"""
return {}
def matching_id(self, payment: OrderPayment):
"""
Will be called to get an ID for a matching this payment when comparing pretix records with records of an external
source. This should return the main transaction ID for your API.
:param payment: The payment in question.
:return: A string or None
"""
return None
class PaymentException(Exception):
pass

View File

@@ -396,6 +396,14 @@ class Paypal(BasePaymentProvider):
'retry': retry, 'order': payment.order}
return template.render(ctx)
def matching_id(self, payment: OrderPayment):
sale_id = None
for trans in payment.info_data.get('transactions', []):
for res in trans.get('related_resources', []):
if 'sale' in res and 'id' in res['sale']:
sale_id = res['sale']['id']
return sale_id or payment.info_data.get('id', None)
def api_payment_details(self, payment: OrderPayment):
sale_id = None
for trans in payment.info_data.get('transactions', []):

View File

@@ -432,6 +432,9 @@ class StripeMethod(BasePaymentProvider):
}
return template.render(ctx)
def matching_id(self, payment: OrderPayment):
return payment.info_data.get("id", None)
def api_payment_details(self, payment: OrderPayment):
return {
"id": payment.info_data.get("id", None),