summaryrefslogtreecommitdiff
path: root/postgresqleu/transferwise/api.py
diff options
context:
space:
mode:
authorMagnus Hagander2019-05-31 18:45:21 +0000
committerMagnus Hagander2019-05-31 18:45:21 +0000
commitd0a199aadf294e1a5f92dc4592a397a5d5d9e452 (patch)
tree741ea95627f4c4a8daeffbc86d59acb1c9a2c673 /postgresqleu/transferwise/api.py
parentaa2c12427159faee074c2e9066ca1dc7ebb58a78 (diff)
Refactor transferwise refund API
This separates out the "send money" functionality into a separate function and makes refund_transaction() call this one with refund specific details.
Diffstat (limited to 'postgresqleu/transferwise/api.py')
-rw-r--r--postgresqleu/transferwise/api.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/postgresqleu/transferwise/api.py b/postgresqleu/transferwise/api.py
index e7da7070..5689f9fe 100644
--- a/postgresqleu/transferwise/api.py
+++ b/postgresqleu/transferwise/api.py
@@ -95,20 +95,33 @@ class TransferwiseApi(object):
# This is a many-step process, unfortunately complicated.
twr = TransferwiseRefund(origtransaction=origtrans, uuid=uuid.uuid4(), refundid=refundid)
+ (accid, quoteid, transferid) = self.make_transfer(origtrans.counterpart_name,
+ origtrans.counterpart_account,
+ refundamount,
+ refundstr,
+ twr.uuid,
+ )
+ twr.accid = accid
+ twr.quoteid = quoteid
+ twr.transferid = transferid
+ twr.save()
+ return twr.id
+
+ def make_transfer(self, counterpart_name, counterpart_account, amount, reference, xuuid):
# Create a recipient account
acc = self.post(
'accounts',
{
'profile': self.get_profile(),
'currency': settings.CURRENCY_ABBREV,
- 'accountHolderName': origtrans.counterpart_name,
+ 'accountHolderName': counterpart_name,
'type': 'iban',
'details': {
- 'IBAN': origtrans.counterpart_account,
+ 'IBAN': counterpart_account,
},
}
)
- twr.accid = acc['id']
+ accid = acc['id']
# Create a quote (even though we're not doing currency exchange)
quote = self.post(
@@ -118,33 +131,32 @@ class TransferwiseApi(object):
'source': settings.CURRENCY_ABBREV,
'target': settings.CURRENCY_ABBREV,
'rateType': 'FIXED',
- 'targetAmount': refundamount,
+ 'targetAmount': amount,
'type': 'BALANCE_PAYOUT',
},
)
- twr.quoteid = quote['id']
+ quoteid = quote['id']
# Create the actual transfer
transfer = self.post(
'transfers',
{
- 'targetAccount': twr.accid,
- 'quote': twr.quoteid,
- 'customerTransactionId': str(twr.uuid),
+ 'targetAccount': accid,
+ 'quote': quoteid,
+ 'customerTransactionId': str(xuuid),
'details': {
- 'reference': refundstr,
+ 'reference': reference,
},
},
)
- twr.transferid = transfer['id']
- twr.save()
+ transferid = transfer['id']
# Fund the transfer from our account
fund = self.post(
- 'transfers/{0}/payments'.format(twr.transferid),
+ 'transfers/{0}/payments'.format(transferid),
{
'type': 'BALANCE',
},
)
- return twr.id
+ return (accid, quoteid, transferid)