diff --git a/apps/payments/wise.py b/apps/payments/wise.py index 166e5b534..84c11ba97 100644 --- a/apps/payments/wise.py +++ b/apps/payments/wise.py @@ -1,4 +1,5 @@ import logging +from dataclasses import dataclass from datetime import timedelta from flask import abort, request @@ -203,52 +204,102 @@ def wise_business_profile(): return id -def wise_retrieve_accounts(profile_id): - # Wise creates the concept of a multi-currency account by calling normal - # bank accounts "balances". As far as we're concerned, "balances" are bank - # accounts, as that's what people will be sending money to. - for account in wise.balances.list(profile_id=profile_id): - try: - if not account.bankDetails: - continue - if not account.bankDetails.bankAddress: - continue - except AttributeError: - continue +@dataclass +class WiseRecipient: + account_holder: str + name_and_address: str + sort_code: str | None = None + account_number: str | None = None + swift: str | None = None + iban: str | None = None + + @property + def bank_info(self): + assert self.name_and_address, "Bank name/address information not found" + return self.name_and_address + + @property + def name(self): + bank_name, _, _ = self.bank_info.partition("\n") + assert bank_name, "Bank name is empty" + return bank_name + + @property + def address(self): + _, _, bank_address = self.bank_info.partition("\n") + assert bank_address, "Bank address is empty" + return bank_address + + @property + def parsed_account_number(self): + return self.account_number.replace(" ", "")[-8:] + + @property + def parsed_sort_code(self): + return self.sort_code.replace("-", "") + + +def _recipient_details_adapter(receive_options): + """Helper method to adapt Wise receive options response data into a WiseRecipient instance""" + field_mappings = { + "ACCOUNT_HOLDER": "account_holder", + "BANK_NAME_AND_ADDRESS": "name_and_address", + "BANK_CODE": "sort_code", + "ACCOUNT_NUMBER": "account_number", + "SWIFT_CODE": "swift", + "IBAN": "iban", + } + return WiseRecipient( + **{ + field_mappings.get(detail.type): detail.body + for detail in receive_options.details + if detail.type in field_mappings + } + ) - address = ", ".join( - [ - account.bankDetails.bankAddress.addressFirstLine, - account.bankDetails.bankAddress.city + " " + (account.bankDetails.bankAddress.postCode or ""), - account.bankDetails.bankAddress.country, - ] - ) - sort_code = account_number = None +def _merge_recipient_details(account): + existing_details = None + for receive_options in account.receiveOptions: + recipient_details = _recipient_details_adapter(receive_options) + + if existing_details: + # coalesce translated account info into the existing bank details + for field in ("sort_code", "account_number", "swift", "iban"): + existing_value = getattr(existing_details, field) + updated_value = getattr(recipient_details, field) + combined_value = existing_value if existing_value is not None else updated_value + setattr(existing_details, field, combined_value) + else: + existing_details = recipient_details + + return existing_details + + +def wise_retrieve_accounts(profile_id): + from main import wise + + for account in wise.account_details.list(profile_id=profile_id): + if account.currency.code != "GBP": + # TODO: support other host currencies + continue - if account.bankDetails.currency == "GBP": - # bankCode is the SWIFT code for non-GBP accounts. - sort_code = account.bankDetails.bankCode.replace("-", "") + bank_details = _merge_recipient_details(account) - if len(account.bankDetails.accountNumber) == 8: - account_number = account.bankDetails.accountNumber - else: - # Wise bug: - # accountNumber is sometimes erroneously the IBAN for GBP accounts. - # Extract the account number from the IBAN. - account_number = account.bankDetails.accountNumber.replace(" ", "")[-8:] + # Workaround: the Wise Sandbox API returns a null/empty account ID; populate a value + if account.id is None and app.config.get("TRANSFERWISE_ENVIRONMENT") == "sandbox": + account.id = 0 yield BankAccount( - sort_code=sort_code, - acct_id=account_number, - currency=account.bankDetails.currency, + sort_code=bank_details.parsed_sort_code, + acct_id=bank_details.parsed_account_number, + currency=account.currency.code, active=False, - payee_name=account.bankDetails.get("accountHolderName"), - institution=account.bankDetails.bankName, - address=address, - swift=account.bankDetails.get("swift"), - iban=account.bankDetails.get("iban"), - # Webhooks only include the borderlessAccountId + payee_name=bank_details.account_holder, + institution=bank_details.name, + address=bank_details.address, + swift=bank_details.swift, + iban=bank_details.iban, wise_balance_id=account.id, ) diff --git a/tests/cassettes/test_wise_account_retrieval.yaml b/tests/cassettes/test_wise_account_retrieval.yaml new file mode 100644 index 000000000..a0038a3a5 --- /dev/null +++ b/tests/cassettes/test_wise_account_retrieval.yaml @@ -0,0 +1,428 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate, br + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.5 + method: GET + uri: https://api.sandbox.transferwise.tech/v1/profiles/123456789/account-details + response: + body: + string: "[{\"id\":null,\"currency\":{\"code\":\"EUR\",\"name\":\"Euro\"},\"balanceId\":-1,\"title\":\"Your + EUR account details\",\"subtitle\":\"IBAN and Swift/BIC\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + EUR account details\",\"body\":\"Receive from a bank in the EurozoneSee how to use EUR account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 2 working days to arrive\",\"description\":null},{\"type\":\"INFO\",\"title\":\"SEPA + includes countries in the EU and EEA\",\"description\":{\"title\":\"What\u2019s + SEPA?\",\"body\":\"
SEPA stands for the Single Euro Payments Area. Within + this area, cross-border euro payments must cost the same as a regular, local + one. It\u2019s EU law.
SEPA covers all the countries within the EU. + It also includes other European countries like Monaco, Norway, and Switzerland.
So + if your sender is sending from a euro bank account in one of these countries, + they shouldn\u2019t have to pay much \u2014 if anything \u2014 to send money + to your EUR account details.
See the full list of SEPA countries
\",\"cta\":null}},{\"type\":\"SAFETY\",\"title\":\"Learn + how Wise keeps your money safe\",\"description\":{\"title\":\"How Wise keeps + your money safe\",\"body\":\"Your Wise account, and the money + in it, are managed and protected by Wise in your region.
\",\"cta\":null}}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"SWIFT_CODE\",\"title\":\"BIC\",\"body\":\"TRWIBxxxxxx\",\"description\":{\"title\":\"What\u2019s + BIC?\",\"body\":\"A BIC code identifies banks and financial institutions + globally. It says who and where they are \u2014 a sort of international bank + code or ID.
\",\"cta\":null},\"hidden\":false},{\"type\":\"IBAN\",\"title\":\"IBAN\",\"body\":\"BE29 + 9670 xxxx xxxx\",\"description\":{\"title\":\"What is an IBAN?\",\"body\":\"IBAN + stands for International Bank Account Number. Your EUR account details include + a Belgian IBAN, which begins with BE.
You only have one Wise account, + no matter how many account details you have. Your Wise account is managed + and protected by Wise in your region. Learn more.
Do you + need an account number?
If your sender specifically asks for an + account number, use: 0000001
\",\"cta\":{\"label\":\"IBAN\",\"content\":\"BE29 + 9670 xxxx xxxx\"}},\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise Europe SA\\nSquare de Mee\xFBs + 38 bte 40\\nBrussels\\n1000\\nBelgium\",\"description\":{\"title\":\"Did they + ask for a bank address?\",\"body\":\"Although Wise isn\u2019t a bank, you + can use these details if your sender needs a bank name and address and we\u2019ll + process the transfer.
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your EUR account details\",\"body\":\"Receive + from a bank outside the EurozoneSee how to use EUR account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 5 working days to arrive\",\"description\":null},{\"type\":\"SAFETY\",\"title\":\"Learn + how Wise keeps your money safe\",\"description\":{\"title\":\"How Wise keeps + your money safe\",\"body\":\"Your Wise account, and the money + in it, are managed and protected by Wise in your region.
\",\"cta\":null}}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"SWIFT_CODE\",\"title\":\"Swift/BIC\",\"body\":\"TRWIBxxxxxx\",\"description\":{\"title\":\"What\u2019s + Swift/BIC?\",\"body\":\"A Swift/BIC code identifies banks and financial + institutions globally. It says who and where they are \u2014 a sort of international + bank code or ID.
\",\"cta\":null},\"hidden\":false},{\"type\":\"IBAN\",\"title\":\"IBAN\",\"body\":\"BE29 + 9670 xxxx xxxx\",\"description\":{\"title\":\"What is an IBAN?\",\"body\":\"IBAN + stands for International Bank Account Number. Your EUR account details include + a Belgian IBAN, which begins with BE.
You only have one Wise account, + no matter how many account details you have. Your Wise account is managed + and protected by Wise in your region. Learn more.
Do you + need an account number?
If your sender specifically asks for an + account number, use: 0000001
\",\"cta\":{\"label\":\"IBAN\",\"content\":\"BE29 + 9670 xxxx xxxx\"}},\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise Europe SA\\nSquare de Mee\xFBs + 38 bte 40\\nBrussels\\n1000\\nBelgium\",\"description\":{\"title\":\"Did they + ask for a bank address?\",\"body\":\"Although Wise isn\u2019t a bank, you + can use these details if your sender needs a bank name and address and we\u2019ll + process the transfer.
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":true},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set up + Direct Debits\",\"supported\":true},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":true}]},{\"id\":null,\"currency\":{\"code\":\"GBP\",\"name\":\"British + pound (accepts US dollar)\"},\"balanceId\":-1,\"title\":\"Your GBP account + details\",\"subtitle\":\"UK sort code, account number and IBAN to receive + US dollars + 22 other currencies\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + GBP account details\",\"body\":\"Receive from a bank in the UKSee how to use GBP account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 1 working day to arrive\",\"description\":{\"title\":\"How long + does it take to receive GBP?\",\"body\":\"Most GBP payments arrive in a + few minutes. But sometimes, it can take longer \u2014 it depends on the kind + of payment.
Ask your sender what kind + of payment they sent you. The payment confirmation from their bank should + show this.
Then, check the table below.
Here\u2019s how long different + payments take in the UK:
If you\u2019re waiting for longer than this, + we can help. Just get in touch with a copy of the payment confirmation.
\",\"cta\":null}}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_CODE\",\"title\":\"Sort + code\",\"body\":\"23-1x-xx\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"1000xxxx\",\"description\":null,\"hidden\":false},{\"type\":\"IBAN\",\"title\":\"IBAN\",\"body\":\"GB77 + TRWI 2314 7010 0000 00\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise\\n56 Shoreditch High Street\\nLondon\\nE1 + 6JJ\\nUnited Kingdom\",\"description\":{\"title\":\"Did they ask for a bank + address?\",\"body\":\"Although Wise isn\u2019t a bank, you can use these + details if your sender needs a bank name and address and we\u2019ll process + the transfer.
Our address changed in March 2025. Payments made using + the previous address will still arrive.
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your GBP account details\",\"body\":\"Receive + from a bank outside the UKSee how to use GBP account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 5 working days to arrive\",\"description\":null},{\"type\":\"INFO\",\"title\":\"Receive + payments in 22 other currencies with these details. Fees apply\",\"description\":{\"title\":\"Receive + payments in 22 other currencies\",\"body\":\"Share these account details + to receive payments in:
You + can view the latest fees for receiving Swift payments on our pricing page.
Your sender\u2019s bank may need to + use correspondent banks within + the Swift network to complete the payment.
Correspondent banks can charge + fees that are outside of our control and are deducted before the money reaches + us. These fees are usually between 15 and 50 USD but can be higher. This means + the amount that you receive can be less than was sent.
It\u2019s best + to ask your sender to check with their bank if there are any fees before they + make the payment.
\",\"cta\":null}}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"SWIFT_CODE\",\"title\":\"Swift/BIC\",\"body\":\"TRWIGB2L\",\"description\":{\"title\":\"What\u2019s + Swift/BIC?\",\"body\":\"A Swift/BIC code identifies banks and financial + institutions globally. It says who and where they are \u2014 a sort of international + bank code or ID.
\",\"cta\":null},\"hidden\":false},{\"type\":\"IBAN\",\"title\":\"IBAN\",\"body\":\"GB77 + TRWI 2314 7010 0000 00\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise\\n56 Shoreditch High Street\\nLondon\\nE1 + 6JJ\\nUnited Kingdom\",\"description\":{\"title\":\"Did they ask for a bank + address?\",\"body\":\"Although Wise isn\u2019t a bank, you can use these + details if your sender needs a bank name and address and we\u2019ll process + the transfer.
Our address changed in March 2025. Payments made using + the previous address will still arrive.
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":true},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set up + Direct Debits\",\"supported\":true},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":true}]},{\"id\":null,\"currency\":{\"code\":\"USD\",\"name\":\"US + dollar\"},\"balanceId\":-1,\"title\":\"Your USD account details\",\"subtitle\":\"Routing + number (ACH or ABA), account number and Swift/BIC\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + USD account details\",\"body\":\"Receive from a bank in the USreceive-option.usd.description.body.links\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 3 working days to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"ROUTING_NUMBER\",\"title\":\"Wire + routing number\",\"body\":\"026073008\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"8xx00xxxxx\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_TYPE\",\"title\":\"Account + type\",\"body\":\"Checking\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise\\n19 W 24th Street\\nNew York NY + 10010\\nUnited States\",\"description\":{\"title\":\"Did they ask for a bank + address?\",\"body\":\"Community Federal Savings Bank is our partner bank + in the US. If your sender asks for a bank name and address, give them these + details and we\u2019ll process the transfer.
Keep in mind that if you + have questions or need help, you\u2019ll need to contact us and not our partner + bank. Get help
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your USD account details\",\"body\":\"Receive + from a bank outside the USreceive-option.usd.description.body.links\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 5 working days to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"ROUTING_NUMBER\",\"title\":\"Routing + number\",\"body\":\"026073008\",\"description\":{\"title\":\"Did they ask + for a routing number?\",\"body\":\"A routing number is not required to + add or receive USD from bank accounts outside the US. But if they specifically + ask for a routing number, you can give them this:
026073008
\",\"cta\":{\"label\":\"Routing + number\",\"content\":\"026073008\"}},\"hidden\":false},{\"type\":\"SWIFT_CODE\",\"title\":\"Swift/BIC\",\"body\":\"CMFGxxxx\",\"description\":{\"title\":\"Swift/BIC\",\"body\":\"We\u2019ll + return payments from countries on this list to the sender. This can take 3\u201310 + working days.
Burundi, Central African Republic, Chad, + Democratic Republic of the Congo, Eritrea, Guinea-Bissau, Libya, Somalia, + South Sudan, Sudan.
Cuba, Venezuela.
Democratic + People\u2019s Republic of Korea (North Korea).
Belarus, + Crimea, Russian Federation, Serbia.
Afghanistan, + Iran, Iraq, Syria, Yemen.
\",\"cta\":{\"label\":\"Swift/BIC\",\"content\":\"CMFGxxxx\"}},\"hidden\":true},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"8xx00xxxxx\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise\\n19 W 24th Street\\nNew York NY + 10010\\nUnited States\",\"description\":{\"title\":\"Did they ask for a bank + address?\",\"body\":\"Community Federal Savings Bank is our partner bank + in the US. If your sender asks for a bank name and address, give them these + details and we\u2019ll process the transfer.
Keep in mind that if you + have questions or need help, you\u2019ll need to contact us and not our partner + bank. Get help
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":true},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set up + Direct Debits\",\"supported\":true},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":true}]},{\"id\":null,\"currency\":{\"code\":\"AUD\",\"name\":\"Australian + dollar\"},\"balanceId\":-1,\"title\":\"Your AUD account details\",\"subtitle\":\"BSB + code, account number and Swift/BIC\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + AUD account details\",\"body\":\"Receive from a bank in AustraliaSee how to use AUD account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 1 working day to arrive\",\"description\":{\"title\":\"How long + does it take to receive AUD?\",\"body\":\"Most AUD payments arrive in a + few minutes. But sometimes, it can take longer \u2014 it depends on the kind + of payment.
Ask your sender what kind + of payment they sent you. The payment confirmation from their bank should + show this.
Then, check the table below.
Here\u2019s how long different + payments take in Australia:
If you\u2019re + waiting for longer than this, we can help. Just get in touch with a copy of + the payment confirmation.\",\"cta\":null}}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_CODE\",\"title\":\"BSB + code\",\"body\":\"774xxx\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"6129xxxxx\",\"description\":null,\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your AUD account details\",\"body\":\"Sorry, + you can\u2019t get account details to receive international AUD payments yet.\",\"cta\":null},\"summaries\":[],\"details\":[],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":false},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":true},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set up + Direct Debits\",\"supported\":false},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]},{\"id\":null,\"currency\":{\"code\":\"NZD\",\"name\":\"New + Zealand dollar\"},\"balanceId\":-1,\"title\":\"Your NZD account details\",\"subtitle\":\"Account + number and Swift/BIC\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + NZD account details\",\"body\":\"Receive from a bank in New ZealandSee how to use NZD account details\",\"cta\":null},\"summaries\":[{\"type\":\"INFO\",\"title\":\"Direct + Debits aren\u2019t supported\",\"description\":{\"title\":\"We don\u2019t + support NZD Direct Debits yet\",\"body\":\"
We hope to change this soon + \u2014 and we\u2019ll let you know when we do.
Until then, please don\u2019t + try to set up any Direct Debits with your NZD account details. The payment + will be rejected and the merchant may charge you a fee.
\",\"cta\":null}},{\"type\":\"TIME\",\"title\":\"Payments + take up to 2 working days to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"02-1290-0xxxxxx-xxx\",\"description\":null,\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your NZD account details\",\"body\":\"Sorry, + you can\u2019t get account details to receive international NZD payments yet.\",\"cta\":null},\"summaries\":[],\"details\":[],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":false},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set + up Direct Debits\",\"supported\":false},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]},{\"id\":null,\"currency\":{\"code\":\"CAD\",\"name\":\"Canadian + dollar\"},\"balanceId\":-1,\"title\":\"Your CAD account details\",\"subtitle\":\"Institution + number, transit number, account number and Swift/BIC\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + CAD account details\",\"body\":\"Receive from a bank in CanadaSee how to use CAD account details\",\"cta\":null},\"summaries\":[{\"type\":\"INFO\",\"title\":\"Domestic + wire transfers and Online Bill Transfers (OBTs) are not yet supported\",\"description\":{\"title\":\"We + support EFTs, Direct Deposits, Interac and Swift\",\"body\":\"You can always + receive CAD into your local details via EFTs (electronic fund transfers) + and Direct Deposits, or to your global details via Swift. + Learn more here.
You + can also receive CAD to your email via Interac. Learn more here.
We don\u2019t + yet support the following payment methods:
If a domestic wire is sent to this currency, + it will be returned to the originating bank with $25 CAD deducted to cover + return processing fees.
\",\"cta\":null}},{\"type\":\"TIME\",\"title\":\"Payments + take up to 2 working days to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"ROUTING_NUMBER\",\"title\":\"Institution + number\",\"body\":\"6xx\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"200110xxxxxx\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"Peoples Trust\\n595 Burrard Street\\nVancouver + BC V7X 1L7\\nCanada\",\"description\":{\"title\":\"Did they ask for a bank + address?\",\"body\":\"Peoples Trust is our partner bank in Canada. If your + sender asks for a bank name and address, give them these details and we\u2019ll + process the transfer.
Keep in mind that if you have questions or need + help, you\u2019ll need to contact us and not our partner bank. Get help
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your CAD account details\",\"body\":\"Sorry, + your Wise CAD account details do not yet support receiving CAD from banks + via Swift transfers. If a Swift transfer is sent to this account, it will + be returned to the originating bank with $50 CAD deducted to cover return + processing fees.\",\"cta\":null},\"summaries\":[],\"details\":[],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":false},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set + up Direct Debits\",\"supported\":true},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]},{\"id\":null,\"currency\":{\"code\":\"HUF\",\"name\":\"Hungarian + forint\"},\"balanceId\":-1,\"title\":\"Your HUF account details\",\"subtitle\":\"Bank + code, account number, IBAN and Swift/BIC\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + HUF account details\",\"body\":\"Receive from a bank in HungarySee how to use HUF account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 1 working day to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"12600016-0000xxxx-xxxxxxxx\",\"description\":{\"title\":\"Did + they ask for an IBAN?\",\"body\":\"For most payments in Hungary, you can + use your account number. But if your sender specifically asked for an IBAN, + you can give them this:
HU68 1260 0016 0000 0000 0000 0000
Just + remember that this IBAN only works for HUF payments. So we recommend asking + the sender which currency they\u2019re sending you first.
\",\"cta\":{\"label\":\"IBAN\",\"content\":\"HU68 + 1260 0016 0000 0000 0000 0000\"}},\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise Europe SA\\nSquare de Mee\xFBs + 38 bte 40\\nBrussels\\n1000\\nBelgium\",\"description\":{\"title\":\"Did they + ask for a bank address?\",\"body\":\"Although Wise isn\u2019t a bank, you + can use these details if your sender needs a bank name and address and we\u2019ll + process the transfer.
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your HUF account details\",\"body\":\"Receive + from a bank outside HungarySee how to use HUF account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 5 working days to arrive\",\"description\":null},{\"type\":\"FEE\",\"title\":\"Fees + can apply to receive Swift payments\",\"description\":{\"title\":\"What are + the fees to receive HUF?\",\"body\":\"Your sender\u2019s bank may need + to use correspondent banks within + the Swift network to complete the payment.
Correspondent banks can charge + fees that are outside of our control and are deducted before the money reaches + us. These fees are usually between 15 and 50 USD but can be higher. This means + the amount that you receive can be less than was sent.
It\u2019s best + to ask your sender to check with their bank if there are any fees before they + make the payment.
\",\"cta\":null}}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"SWIFT_CODE\",\"title\":\"Swift/BIC\",\"body\":\"TRWIBxxxxxx\",\"description\":{\"title\":\"What\u2019s + Swift/BIC?\",\"body\":\"A Swift/BIC code identifies banks and financial + institutions globally. It says who and where they are \u2014 a sort of international + bank code or ID.
\",\"cta\":{\"label\":\"Swift/BIC\",\"content\":\"TRWIBxxxxxx\"}},\"hidden\":false},{\"type\":\"IBAN\",\"title\":\"IBAN\",\"body\":\"HU68 + 1260 0016 0000 0000 0000 0000\",\"description\":{\"title\":\"How to use your + IBAN\",\"body\":\"Your IBAN is a code that helps banks identify your account + for international payments. You can use your Hungarian IBAN to receive HUF + payments.
Some banks may + not be able to process payments using your Hungarian IBAN. If your sender + has problems sending to this IBAN, you can receive HUF using GBP account details + instead, and the payment will arrive as HUF into your account.
Learn more about using GBP account + details
\",\"cta\":null},\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"TransferWise Europe SA\\nSquare de Mee\xFBs + 38 bte 40\\nBrussels\\n1000\\nBelgium\",\"description\":{\"title\":\"Did they + ask for a bank address?\",\"body\":\"Although Wise isn\u2019t a bank, you + can use these details if your sender needs a bank name and address and we\u2019ll + process the transfer.
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":false},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set + up Direct Debits\",\"supported\":false},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]},{\"id\":null,\"currency\":{\"code\":\"MYR\",\"name\":\"Malaysian + ringgit\"},\"balanceId\":-1,\"title\":\"Your MYR account details\",\"subtitle\":\"Account + number\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + MYR account details\",\"body\":\"Receive from a bank in MalaysiaSee how to use MYR account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 1 working day to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"PARTNER_BANK_NAME\",\"title\":\"Partner + bank name\",\"body\":\"JPMorgan Chase Bank Berhad\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"3120000xxxxxxxx\",\"description\":null,\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your MYR account details\",\"body\":\"Sorry, + you can\u2019t get account details to receive international MYR payments yet.\",\"cta\":null},\"summaries\":[],\"details\":[],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":false},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":false},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set + up Direct Debits\",\"supported\":false},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]},{\"id\":null,\"currency\":{\"code\":\"RON\",\"name\":\"Romanian + leu\"},\"balanceId\":-1,\"title\":\"Your RON account details\",\"subtitle\":\"Bank + code, account number and IBAN\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + RON account details\",\"body\":\"Receive from a bank in RomaniaSee how to use RON account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 1 working day to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"SWIFT_CODE\",\"title\":\"Bank + code\",\"body\":\"BRELRxxxxxx\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"RO83 BREL 0005 xxxx xxxx xxxx\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_NAME_AND_ADDRESS\",\"title\":\"Bank + name and address\",\"body\":\"Libra Internet Bank\\nCalea Vitan Nr. 6-6A\\nBucuresti\\n031296\\nRomania\",\"description\":{\"title\":\"Did + they ask for a bank address?\",\"body\":\"Libra Internet Bank is our partner + bank in Romania. If your sender asks for a bank name and address, give them + these details and we\u2019ll process the transfer.
Keep in mind that + if you have questions or need help, you\u2019ll need to contact us and not + our partner bank. Get help
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your Currency(code=RON, name=Romanian + leu) account details\",\"body\":\"Use your Global Swift GBP details to receive + RON from outside Romania.\",\"cta\":null},\"summaries\":[],\"details\":[],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":false},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set + up Direct Debits\",\"supported\":false},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]},{\"id\":null,\"currency\":{\"code\":\"SGD\",\"name\":\"Singapore + dollar\"},\"balanceId\":-1,\"title\":\"Your SGD account details\",\"subtitle\":\"Bank + code, account number and Swift/BIC\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + SGD account details\",\"body\":\"Receive SGD payments instantly through the + FAST networkSee how to use SGD account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 1 working day to arrive\",\"description\":null},{\"type\":\"LIMIT\",\"title\":\"200,000 + SGD limit per payment\",\"description\":null}],\"details\":[{\"type\":\"SUPPORTED_PAYMENT_NETWORK\",\"title\":\"Payment + network\",\"body\":\"FAST\",\"description\":{\"title\":\"What is FAST?\",\"body\":\"FAST + (Fast and Secure Transfer) is the most popular payment network in Singapore + that allows payments to arrive instantly, 24/7.
If you want to receive payments from platforms like Google + or Stripe, use your GIRO/MEPS account details instead.
You + can only receive SGD from people or business that have a SGD bank account + in Singapore.
\",\"cta\":null},\"hidden\":false},{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_NAME\",\"title\":\"Bank + name\",\"body\":\"DBS Bank Ltd\",\"description\":null,\"hidden\":false},{\"type\":\"BANK_CODE\",\"title\":\"Bank + code\",\"body\":\"71xx\",\"description\":null,\"hidden\":false},{\"type\":\"ACCOUNT_NUMBER\",\"title\":\"Account + number\",\"body\":\"885-074-xxx-xxx\",\"description\":null,\"hidden\":false},{\"type\":\"ADDRESS\",\"title\":\"Wise\u2019s + address\",\"body\":\"56 Shoreditch High Street\\nLondon E1 6JJ\",\"description\":{\"title\":\"Did + they ask for a bank address?\",\"body\":\"Although Wise isn\u2019t a bank, + you can use these details if your sender needs a bank name and address and + we\u2019ll process the transfer.
\",\"cta\":null},\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your SGD account details\",\"body\":\"Sorry, + you can\u2019t get account details to receive international SGD payments yet.\",\"cta\":null},\"summaries\":[],\"details\":[],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":false},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set + up Direct Debits\",\"supported\":false},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]},{\"id\":null,\"currency\":{\"code\":\"TRY\",\"name\":\"Turkish + lira\"},\"balanceId\":-1,\"title\":\"Your TRY account details\",\"subtitle\":\"IBAN\",\"status\":\"AVAILABLE\",\"deprecated\":false,\"migrated\":false,\"receiveOptions\":[{\"type\":\"LOCAL\",\"title\":\"Local\",\"description\":{\"title\":\"Your + TRY account details\",\"body\":\"Receive from a bank in TurkeySee how to use TRY account details\",\"cta\":null},\"summaries\":[{\"type\":\"TIME\",\"title\":\"Payments + take up to 1 working day to arrive\",\"description\":null}],\"details\":[{\"type\":\"ACCOUNT_HOLDER\",\"title\":\"Account + holder\",\"body\":\"Willis and Daughters 4056\",\"description\":null,\"hidden\":false},{\"type\":\"IBAN\",\"title\":\"IBAN\",\"body\":\"TR29 + 0010 3000 0xxx xxxx xxxx xx\",\"description\":null,\"hidden\":false}],\"alert\":null,\"shareText\":null},{\"type\":\"INTERNATIONAL\",\"title\":\"Global + \xB7 Swift\",\"description\":{\"title\":\"Your TRY account details\",\"body\":\"Sorry, + you can\u2019t get account details to receive international TRY payments yet.\",\"cta\":null},\"summaries\":[],\"details\":[],\"alert\":null,\"shareText\":null}],\"bankFeatures\":[{\"key\":\"LOCAL_RECEIVE\",\"title\":\"Receive + locally\",\"supported\":true},{\"key\":\"SWIFT\",\"title\":\"Receive internationally + (Swift)\",\"supported\":false},{\"key\":\"DIRECT_DEBITS\",\"title\":\"Set + up Direct Debits\",\"supported\":false},{\"key\":\"PLATFORM_RECEIVE\",\"title\":\"Receive + from PayPal and Stripe\",\"supported\":false}]}]" + headers: + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Mon, 08 Sep 2025 22:19:49 GMT + Transfer-Encoding: + - chunked + cache-control: + - no-cache, no-store, max-age=0, must-revalidate + content-encoding: + - gzip + expires: + - '0' + pragma: + - no-cache + vary: + - origin,access-control-request-method,access-control-request-headers,accept-encoding + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_payment.py b/tests/test_payment.py index c8f35591e..6bb23d52c 100644 --- a/tests/test_payment.py +++ b/tests/test_payment.py @@ -1,8 +1,31 @@ import pytest +from apps.payments.wise import wise_retrieve_accounts from models.payment import BankTransaction +@pytest.fixture(scope="module") +def vcr_config(): + return { + # Replace the Authorization request header with "DUMMY" in cassettes + "filter_headers": [("authorization", "DUMMY")], + } + + +@pytest.mark.vcr() +def test_wise_account_retrieval(app): + accounts = list(wise_retrieve_accounts(profile_id=123456789)) + + # we merge Wise's local and international details for our GBP account into a single record + assert len(accounts) == 1 + + primary_account = accounts[0] + assert primary_account.currency == "GBP" + assert primary_account.institution == "TransferWise" + assert primary_account.sort_code.startswith("231") + assert primary_account.acct_id.startswith("1000") + + @pytest.mark.parametrize( "payee, bankref", [