def test_check_eligibility(self): params = { "owner_name": "Victor Hugo", "user": self.legal_user, "type": "IBAN", "owner_address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2', city='City', region='Region', postal_code='11222', country='FR'), "iban": "FR7630004000031234567890143", "bic": "BNPAFRPP", "tag": "custom tag" } bankaccount = BankAccount(**params) bankaccount.save() eligibility = { "author": self.legal_user, "debited_funds": Money(amount=10, currency='EUR'), "debited_wallet": self.legal_user_wallet, "bank_account": bankaccount, "payout_mode_requested": "INSTANT_PAYMENT" } check_eligibility = PayOutEligibility(**eligibility) result = check_eligibility.check_eligibility() self.assertIsNotNone(result) instant_payout = result.get('instant_payout') self.assertIsNotNone(instant_payout)
def test_create_bankaccount_gb(self): self.mock_natural_user() self.register_mock({ 'method': responses.POST, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/bankaccounts/GB', 'body': { "UserId": "1169419", "Type": "GB", "OwnerName": "Victor Hugo", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "AccountNumber": "62136016", "SortCode": "404865", "Id": "38290008", "Tag": "custom tag", "CreationDate": 1383561267 }, 'status': 200 }) params = { "tag": "custom tag", "user": self.natural_user, "type": "GB", "owner_name": "Victor Hugo", "owner_address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2', city='City', region='Region', postal_code='11222', country='FR'), "account_number": "62136016", "sort_code": "404865" } bankaccount = BankAccount(**params) self.assertIsNone(bankaccount.get_pk()) bankaccount.save() self.assertIsInstance(bankaccount, BankAccount) for key, value in params.items(): self.assertEqual(getattr(bankaccount, key), value) self.assertIsNotNone(bankaccount.get_pk())
def test_retrieve_users_all_bankaccounts(self): self.mock_natural_user() self.register_mock([{ 'method': responses.POST, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/bankaccounts/IBAN', 'body': { "UserId": "1167502", "Type": "IBAN", "OwnerName": "Victor Hugo", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "IBAN": "FR3020041010124530725S03383", "BIC": "CRLYFRPP", "Id": "1169675", "Tag": "custom tag", "CreationDate": 1383561267 }, 'status': 200 }, { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/bankaccounts', 'body': [{ "UserId": "1167502", "Type": "IBAN", "OwnerName": "Victor Hugo", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "IBAN": "FR3020041010124530725S03383", "BIC": "CRLYFRPP", "Id": "1169675", "Tag": "custom tag", "CreationDate": 1383561267 }], 'status': 200 }]) params = { "owner_name": "Victor Hugo", "user": self.natural_user, "type": "IBAN", "owner_address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2', city='City', region='Region', postal_code='11222', country='FR'), "iban": "FR3020041010124530725S03383", "bic": "CRLYFRPP", "tag": "custom tag" } bankaccount = BankAccount(**params) bankaccount.save() self.assertIsNotNone(bankaccount.get_pk()) self.assertIsInstance(self.natural_user.bankaccounts.all(), list) for bankaccount in self.natural_user.bankaccounts.all(): self.assertIsInstance(bankaccount, BankAccount)
def test_retrieve_bankaccount_iban(self): self.mock_natural_user() self.register_mock([{ 'method': responses.POST, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/bankaccounts/IBAN', 'body': { "UserId": "1169419", "Type": "IBAN", "OwnerName": "Victor Hugo", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "IBAN": "FR3020041010124530725S03383", "BIC": "CRLYFRPP", "Id": "1169675", "Tag": "custom tag", "CreationDate": 1383561267 }, 'status': 200 }, { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/bankaccounts/1169675', 'body': { "UserId": "1169419", "Type": "IBAN", "OwnerName": "Victor Hugo", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "IBAN": "FR3020041010124530725S03383", "BIC": "CRLYFRPP", "Id": "1169675", "Tag": "custom tag", "CreationDate": 1383561267 }, 'status': 200 }, { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/bankaccounts', 'body': [{ "UserId": "1169419", "Type": "IBAN", "OwnerName": "Victor Hugo", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "IBAN": "FR3020041010124530725S03383", "BIC": "CRLYFRPP", "Id": "1169675", "Tag": "custom tag", "CreationDate": 1383561267 }], 'status': 200 }, { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419', 'body': { "Id": '1169419', "FirstName": "Victor", "LastName": "Hugo", "Address": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "Birthday": int(time.mktime(date.today().timetuple())), "Nationality": "FR", "CountryOfResidence": "FR", "Occupation": "Writer", "IncomeRange": 6, "PersonType": "NATURAL", "Email": "*****@*****.**", "Tag": "custom tag" }, 'status': 200 }]) params = { "owner_name": "Victor Hugo", "user": self.natural_user, "type": "IBAN", "owner_address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2', city='City', region='Region', postal_code='11222', country='FR'), "iban": "FR3020041010124530725S03383", "bic": "CRLYFRPP", "tag": "custom tag" } bankaccount = BankAccount(**params) bankaccount.save() self.assertIsNotNone(bankaccount.get_pk()) pk = bankaccount.get_pk() bankaccount = BankAccount.get( bankaccount.get_pk(), **{'user_id': self.natural_user.get_pk()}) self.assertIsNotNone(bankaccount.get_pk()) self.assertEqual( self.natural_user.bankaccounts.get( pk, **{'user_id': self.natural_user.get_pk()}), bankaccount) self.assertEqual(self.natural_user.bankaccounts.all(), [bankaccount]) for key, value in params.items(): self.assertEqual(getattr(bankaccount, key), value)
def test_create_bankaccount_ca(self): self.mock_natural_user() self.register_mock({ 'method': responses.POST, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/bankaccounts/CA', 'body': { "UserId": "1169419", "OwnerName": "Victor Hugo", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "Type": "CA", "Id": "6775449", "Tag": "custom tag", "CreationDate": 1431964854, "AccountNumber": "123", "InstitutionNumber": "1234", "BranchCode": "12345", "BankName": "banque nationale of canada" }, 'status': 200 }) params = { "owner_name": "Victor Hugo", "user": self.natural_user, "type": "CA", "owner_address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2', city='City', region='Region', postal_code='11222', country='FR'), "tag": "custom tag", "bank_name": "banque nationale of canada", "institution_number": "1234", "branch_code": "12345", "account_number": "123" } bankaccount = BankAccount(**params) self.assertIsNone(bankaccount.get_pk()) bankaccount.save() self.assertIsInstance(bankaccount, BankAccount) for key, value in params.items(): self.assertEqual(getattr(bankaccount, key), value) self.assertIsNotNone(bankaccount.get_pk())
def test_create_bank_wire_payout(self): self.mock_legal_user() self.mock_user_wallet() self.register_mock([{ 'method': responses.POST, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169420/bankaccounts/IBAN', 'body': { "UserId": "1169420", "Type": "IBAN", "OwnerName": "MangoPay", "OwnerAddress": { "AddressLine1": "AddressLine1", "AddressLine2": "AddressLine2", "City": "City", "Region": "Region", "PostalCode": "11222", "Country": "FR" }, "IBAN": "FR3020041010124530725S03383", "BIC": "CRLYFRPP", "Id": "1169675", "Tag": "custom tag", "CreationDate": 1383561267 }, 'status': 200 }, { 'method': responses.POST, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/payouts/bankwire', 'body': { "Id": 30047, "CreditedFunds": None, "BankWireRef": "John Doe's trousers", "DebitedFunds": { "Currency": "EUR", "Amount": 1000 }, "BankAccountId": 6784645, "AuthorId": 6784642, "Tag": "Custom data", "Fees": { "Currency": "EUR", "Amount": 100 }, "DebitedWalletId": 6784644 }, 'status': 200 }, { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/payouts/30047', 'body': { "Id": 30047, "Tag": "custom tag", "CreationDate": 1374232891, "AuthorId": "20164", "CreditedUserId": None, "DebitedFunds": { "Currency": "EUR", "Amount": 100 }, "CreditedFunds": { "Currency": "EUR", "Amount": "1000" }, "Fees": { "Currency": "EUR", "Amount": "100" }, "Status": "SUCCEEDED", "ResultCode": "00000", "ExecutionDate": 1374233532, "Type": "PAY_OUT", "Nature": "NORMAL", "DebitedWalletId": "30025", "BankAccountId": "30027", "BankWireRef": "John Doe's trousers" }, 'status': 200 }]) params = { "owner_name": "Victor Hugo", "user": self.legal_user, "type": "IBAN", "owner_address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2', city='City', region='Region', postal_code='11222', country='FR'), "iban": "FR3020041010124530725S03383", "bic": "CRLYFRPP", "tag": "custom tag" } bankaccount = BankAccount(**params) bankaccount.save() bank_wire_payout_params = { "tag": "Custom data", "author": self.legal_user, "debited_funds": Money(amount=1000, currency='EUR'), "fees": Money(amount=100, currency='EUR'), "debited_wallet": self.legal_user_wallet, "bank_account": bankaccount, "bank_wire_ref": "John Doe's trousers" } bank_wire_payout = BankWirePayOut(**bank_wire_payout_params) self.assertIsNone(bank_wire_payout.get_pk()) bank_wire_payout.save() self.assertIsInstance(bank_wire_payout, BankWirePayOut) self.assertEqual(bank_wire_payout.debited_funds.amount, 1000) bank_wire_payout_params.pop('debited_funds') self.assertEqual(bank_wire_payout.fees.amount, 100) bank_wire_payout_params.pop('fees') for key, value in bank_wire_payout_params.items(): self.assertEqual(getattr(bank_wire_payout, key), value) self.assertIsNotNone(bank_wire_payout.get_pk()) # test_retrieve_payouts retrieved_payout = BankWirePayOut.get(bank_wire_payout.get_pk()) self.assertIsNotNone(retrieved_payout.get_pk()) self.assertIsInstance(retrieved_payout, BankWirePayOut) self.assertEqual(getattr(retrieved_payout, 'id'), bank_wire_payout.get_pk())