diff options
author | Magnus Hagander | 2016-01-20 11:43:39 +0000 |
---|---|---|
committer | Magnus Hagander | 2016-01-20 18:56:38 +0000 |
commit | ee5cd99ec2b9aed13c30592199d9661e17189dd3 (patch) | |
tree | d3c97f5862f7f277cf7934ad4fda6687a92accaa /postgresqleu/paypal/util.py | |
parent | d062ccfe9841a27ecab4b0e838cdee4acd93785f (diff) |
Implement proper refund management
This means a few things:
1. We track refunds properly. Each invoice can be refunded once, but we now
also support partial refunds (which is important, as almost every refund we
make on a conference registration ends up being a partial one - if nothing
else it is deducted transaction fees).
2. We support API initiated refunds. That means that as long as the payment is
done using a supported provider (today that means Adyen and Paypal), the
complete invoice processing is done in the webapp, which means there is no
risk of getting the wrong numbers into the accounting (which has happened more
than once).
3. We now generate proper refund notices in PDF format for all refunds (both
automated and manual). The user receives this one as well as status updates
throughout the refund process.
Actual API refunds are handled by a new cronjob, to ensure that we don't end up
blocking the user if the API is slow. Initiating the refund puts it on the queue,
the cronjob sends it to the provider, and the notification from the provider
flags it as completed (and generates the refund notice).
Diffstat (limited to 'postgresqleu/paypal/util.py')
-rw-r--r-- | postgresqleu/paypal/util.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/postgresqleu/paypal/util.py b/postgresqleu/paypal/util.py index d9c2e4c3..03934a14 100644 --- a/postgresqleu/paypal/util.py +++ b/postgresqleu/paypal/util.py @@ -49,3 +49,20 @@ class PaypalAPI(object): return self._api_call('GetTransactionDetails', { 'TRANSACTIONID': transactionid, }) + + + def refund_transaction(self, paypaltransid, amount, isfull, refundnote): + r = self._api_call('RefundTransaction', { + 'TRANSACTIONID': paypaltransid, + 'REFUNDTYPE': isfull and 'Full' or 'Partial', + 'AMT': '{0:.2f}'.format(amount), + 'CURRENCYCODE': settings.CURRENCY_ISO, + 'NOTE': refundnote, + }) + + # We ignore the status here as we will parse it from the + # actual statement later. + if r['ACK'][0] == 'Success': + return r['REFUNDTRANSACTIONID'][0] + + raise Exception(r) |