From 2c2f94892b3c9069b2f2ac239b25174b192962fe Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Tue, 27 Nov 2018 14:35:31 +0100 Subject: [PATCH] Remove hardcoded PGEU prefix from Adyen and Paypal refunds We already had the payment references in a parameter, but for some reason not the refunds. In passing, add ORG_SHORT_NAME to the settings and org_short_name to the context on all pages, to make it easier to do this in the future. --- postgresqleu/adyen/util.py | 4 ++-- postgresqleu/paypal/management/commands/paypal_match.py | 2 +- .../paypal/management/commands/refund_paypal_transaction.py | 2 +- postgresqleu/settings.py | 2 ++ postgresqleu/util/context_processors.py | 1 + postgresqleu/util/payment/paypal.py | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/postgresqleu/adyen/util.py b/postgresqleu/adyen/util.py index c41d083..43acb4b 100644 --- a/postgresqleu/adyen/util.py +++ b/postgresqleu/adyen/util.py @@ -194,7 +194,7 @@ def process_refund(notification): ] # API generated refund? - if notification.merchantReference.startswith('PGEUREFUND'): + if notification.merchantReference.startswith(settings.ADYEN_MERCHANTREF_REFUND_PREFIX): # API generated invoicerefundid = int(notification.merchantReference[10:]) @@ -398,7 +398,7 @@ class AdyenAPI(object): 'currency': settings.CURRENCY_ISO, }, 'originalReference': transreference, - 'reference': 'PGEUREFUND{0}'.format(refundid), + 'reference': '{0}{1}'.format(settings.ADYEN_MERCHANTREF_REFUND_PREFIX, refundid), } try: diff --git a/postgresqleu/paypal/management/commands/paypal_match.py b/postgresqleu/paypal/management/commands/paypal_match.py index eac7194..aceddb5 100755 --- a/postgresqleu/paypal/management/commands/paypal_match.py +++ b/postgresqleu/paypal/management/commands/paypal_match.py @@ -77,7 +77,7 @@ class Command(BaseCommand): ] create_accounting_entry(trans.timestamp.date(), accrows, True, urls) continue - if trans.amount < 0 and trans.transtext.startswith('Refund of Paypal payment: PGEU refund '): + if trans.amount < 0 and trans.transtext.startswith('Refund of Paypal payment: {0} refund '.format(settings.ORG_SHORTNAME)): trans.setmatched('Matched API initiated refund') # API initiated refund, so we should be able to match it invoicemanager.complete_refund( diff --git a/postgresqleu/paypal/management/commands/refund_paypal_transaction.py b/postgresqleu/paypal/management/commands/refund_paypal_transaction.py index 230ae77..bdb832a 100644 --- a/postgresqleu/paypal/management/commands/refund_paypal_transaction.py +++ b/postgresqleu/paypal/management/commands/refund_paypal_transaction.py @@ -16,7 +16,7 @@ class Command(BaseCommand): help = 'Refund paypal transactions' def add_arguments(self, parser): - parser.add_argument('-i', '--ids', help='PGEU transaction id from database', nargs='+', required=True) + parser.add_argument('-i', '--ids', help='Transaction id from database', nargs='+', required=True) parser.add_argument('-m', '--message', help='Message', required=True) def handle(self, *args, **options): diff --git a/postgresqleu/settings.py b/postgresqleu/settings.py index 9115a12..f8528e7 100644 --- a/postgresqleu/settings.py +++ b/postgresqleu/settings.py @@ -172,6 +172,7 @@ ADYEN_REPORT_PASSWORD='topsecret' ADYEN_WS_USER='someone' ADYEN_WS_PASSWORD='topsecret' ADYEN_MERCHANTREF_PREFIX='PGEU' +ADYEN_MERCHANTREF_REFUND_PREFIX='PGEUREFUND' # Account numbers used for auto-accounting ENABLE_AUTO_ACCOUNTING=True @@ -214,6 +215,7 @@ ENABLE_TRUSTLY=False # Organization name ORG_NAME="PostgreSQL Europe" +ORG_SHORTNAME="PGEU" # Treasurer email address TREASURER_EMAIL="treasurer@postgresql.eu" diff --git a/postgresqleu/util/context_processors.py b/postgresqleu/util/context_processors.py index ca41e6d..82ed040 100644 --- a/postgresqleu/util/context_processors.py +++ b/postgresqleu/util/context_processors.py @@ -11,6 +11,7 @@ from postgresqleu.membership.models import Member def settings_context(request=None): return { 'org_name': settings.ORG_NAME, + 'org_short_name': settings.ORG_SHORTNAME, 'treasurer_email': settings.TREASURER_EMAIL, 'sitebase': settings.SITEBASE, 'currency_abbrev': settings.CURRENCY_ABBREV, diff --git a/postgresqleu/util/payment/paypal.py b/postgresqleu/util/payment/paypal.py index 56ca6c9..9d2ee91 100644 --- a/postgresqleu/util/payment/paypal.py +++ b/postgresqleu/util/payment/paypal.py @@ -73,7 +73,7 @@ lower fees. trans.paypaltransid, invoice.refund.fullamount, invoice.refund.fullamount == invoice.total_amount, - 'PGEU refund {0}'.format(invoice.refund.id), + '{0} refund {1}'.format(settings.ORG_SHORTNAME, invoice.refund.id), ) # At this point, we succeeded. Anything that failed will bubble # up as an exception. -- 2.39.5