def get_johns_account(recreate=False): if BaseTestLive._johns_account is None or recreate: account = BankAccount() account.owner_name = BaseTestLive._john.first_name + ' ' + BaseTestLive._john.last_name account.user = BaseTestLive._john account.type = 'IBAN' account.owner_address = BaseTestLive._john.address account.iban = 'FR7618829754160173622224154' account.bic = 'CMBRFR2BCME' BaseTestLive._johns_account = BankAccount(**account.save()) return BaseTestLive._johns_account
def get_johns_account(recreate=False): if BaseTestLive._johns_account is None or recreate: account = BankAccount() account.owner_name = BaseTestLive._john.first_name + ' ' + BaseTestLive._john.last_name account.user = BaseTestLive._john account.type = 'IBAN' account.owner_address = BaseTestLive._john.address account.iban = 'FR7630004000031234567890143' account.bic = 'BNPAFRPP' BaseTestLive._johns_account = BankAccount(**account.save()) return BaseTestLive._johns_account
def create(self): # Instead of getting the NaturalUser, I can get Saver! like that I can query both Natural and Legal, when I have # the model utils manager installed !!! Now this makes sense why to have it and how to use it! # Also because the MIDs are unique for all MP Objects. Makes it simpler, but only easier to see in hindsight!! ba = BankAccount(owner_name=(self.saver.user.first_name + '' + self.saver.user.last_name), user_id=self.saver.mid, type=self.bank_account_type, owner_address=self._make_address(), IBAN=self.iban, BIC=self.bic) ba.save() self.bid = ba.Id # get other stuff from the API to add to the model? self.save()
def create(self, user, line1, city, region, pc, country, line2=''): self.mid = MangoUser.objects.get(user=user).mid address = _make_address(line1, line2, city, pc, country, region) self.address = address ba = BankAccount(OwnerAddress=address, OwnerName=(str(user.first_name + user.last_name)), IBAN=self.iban, BIC=self.bic, Type=self.bank_account_type) # check if I don't need a function in the user model for get_full_name ba.save() self.bid = ba.get_pk() self.creation_date = ba.creation_date self.active = True self.save()
def deactivate(self): ba = BankAccount.get(Id=self.bid) ba.deactivate() ba.save() self.active = False self.save() return HttpResponse('Bank Account deactivated.')
def Create(self, pay_in): if isinstance(pay_in, DirectPayIn) and not pay_in.Id: pay_in.Id = self.pay_in_id pay_in.ExecutionDate = 12312312 pay_in.PaymentDetails = PayInPaymentDetailsBankWire() pay_in.PaymentDetails.WireReference = '4a57980154' pay_in.PaymentDetails.BankAccount = BankAccount() pay_in.PaymentDetails.BankAccount.IBAN = "FR7618829754160173622224251" pay_in.PaymentDetails.BankAccount.BIC = "CMBRFR2BCME" pay_in.PaymentDetails.BankAccount.Details = BankAccountDetailsIBAN() pay_in.PaymentDetails.BankAccount.Details.bic = "123" pay_in.PaymentDetails.BankAccount.Details.iban = "abc" return pay_in else: raise TypeError("PayIn must be a PayIn entity")
def payout(db, route, amount, ignore_high_fee=False): """Withdraw money to the specified bank account (`route`). """ assert amount > 0 assert route assert route.network == 'mango-ba' participant = route.participant if participant.is_suspended: raise AccountSuspended() payday = db.one("SELECT * FROM paydays WHERE ts_start > ts_end") if payday: raise PaydayIsRunning ba = BankAccount.get(route.address, user_id=participant.mangopay_user_id) # Do final calculations amount = Money(amount, 'EUR') if isinstance(amount, Decimal) else amount credit_amount, fee, vat = skim_credit(amount, ba) if credit_amount <= 0 and fee > 0: raise FeeExceedsAmount fee_percent = fee / amount if fee_percent > FEE_PAYOUT_WARN and not ignore_high_fee: raise TransactionFeeTooHigh(fee_percent, fee, amount) # Try to dance with MangoPay e_id = record_exchange(db, route, -credit_amount, fee, vat, participant, 'pre').id payout = BankWirePayOut() payout.AuthorId = participant.mangopay_user_id payout.DebitedFunds = amount.int() payout.DebitedWalletId = participant.get_current_wallet( amount.currency).remote_id payout.Fees = fee.int() payout.BankAccountId = route.address payout.BankWireRef = str(e_id) payout.Tag = str(e_id) try: test_hook() payout.save() return record_exchange_result(db, e_id, payout.Id, payout.Status.lower(), repr_error(payout), participant) except Exception as e: error = repr_exception(e) return record_exchange_result(db, e_id, '', 'failed', error, participant)
def payout(db, route, amount, ignore_high_fee=False): """Withdraw money to the specified bank account (`route`). """ assert amount > 0 assert route assert route.network == 'mango-ba' participant = route.participant if participant.is_suspended: raise AccountSuspended() payday = db.one("SELECT * FROM paydays WHERE ts_start > ts_end") if payday: raise PaydayIsRunning ba = BankAccount.get(route.address, user_id=participant.mangopay_user_id) # Do final calculations amount = Money(amount, 'EUR') if isinstance(amount, Decimal) else amount credit_amount, fee, vat = skim_credit(amount, ba) if credit_amount <= 0 and fee > 0: raise FeeExceedsAmount fee_percent = fee / amount if fee_percent > FEE_PAYOUT_WARN and not ignore_high_fee: raise TransactionFeeTooHigh(fee_percent, fee, amount) # Try to dance with MangoPay e_id = record_exchange(db, route, -credit_amount, fee, vat, participant, 'pre').id payout = BankWirePayOut() payout.AuthorId = participant.mangopay_user_id payout.DebitedFunds = Money_to_cents(amount) payout.DebitedWalletId = participant.get_current_wallet(amount.currency).remote_id payout.Fees = Money_to_cents(fee) payout.BankAccountId = route.address payout.BankWireRef = str(e_id) payout.Tag = str(e_id) try: test_hook() payout.save() return record_exchange_result( db, e_id, payout.Id, payout.Status.lower(), repr_error(payout), participant ) except Exception as e: error = repr_exception(e) return record_exchange_result(db, e_id, '', 'failed', error, participant)
def payout(db, participant, amount, ignore_high_fee=False): assert amount > 0 if participant.is_suspended: raise AccountSuspended() payday = db.one("SELECT * FROM paydays WHERE ts_start > ts_end") if payday: raise PaydayIsRunning route = ExchangeRoute.from_network(participant, 'mango-ba') assert route ba = BankAccount.get(route.address, user_id=participant.mangopay_user_id) # Do final calculations credit_amount, fee, vat = skim_credit(amount, ba) if credit_amount <= 0 and fee > 0: raise FeeExceedsAmount fee_percent = fee / amount if fee_percent > FEE_PAYOUT_WARN and not ignore_high_fee: raise TransactionFeeTooHigh(fee_percent, fee, amount) # Try to dance with MangoPay e_id = record_exchange(db, route, -credit_amount, fee, vat, participant, 'pre') payout = BankWirePayOut() payout.AuthorId = participant.mangopay_user_id payout.DebitedFunds = Money(int(amount * 100), 'EUR') payout.DebitedWalletId = participant.mangopay_wallet_id payout.Fees = Money(int(fee * 100), 'EUR') payout.BankAccountId = route.address payout.BankWireRef = str(e_id) payout.Tag = str(e_id) try: test_hook() payout.save() return record_exchange_result(db, e_id, payout.Status.lower(), repr_error(payout), participant) except Exception as e: error = repr_exception(e) return record_exchange_result(db, e_id, 'failed', error, participant)
def get_bank_account(self): bank_account = BankAccount( id=self.mangopay_id, owner_name=self.mangopay_user.user.get_full_name(), owner_address=Address(address_line_1=self.address), user=self.mangopay_user.get_user(), type=self.account_type) if self.account_type == BANK_ACCOUNT_TYPE_CHOICES.iban: bank_account.iban = self.iban elif self.account_type == BANK_ACCOUNT_TYPE_CHOICES.us: bank_account.aba = self.aba bank_account.deposit_account_type = self.deposit_account_type bank_account.account_number = self.account_number elif self.account_type == BANK_ACCOUNT_TYPE_CHOICES.other: bank_account.account_number = self.account_number else: raise NotImplementedError( "Bank Account Type ({0}) not implemented.".format( self.account_type)) return bank_account
with use_cassette('MangopayHarness'): cls = MangopayHarness cls.david_id = make_mangopay_account('David') cls.david_wallet_id = make_wallet(cls.david_id).Id cls.janet_id = make_mangopay_account('Janet') cls.janet_wallet_id = make_wallet(cls.janet_id).Id cr = create_card(cls.janet_id) cls.card_id = cr.CardId del cr cls.homer_id = make_mangopay_account('Homer') cls.homer_wallet_id = make_wallet(cls.homer_id).Id ba = BankAccount(user_id=cls.homer_id, type='IBAN') ba.OwnerName = 'Homer Jay' ba.OwnerAddress = { 'AddressLine1': 'Somewhere', 'City': 'The City of Light', 'PostalCode': '75001', 'Country': 'FR', } ba.IBAN = 'FR1420041010050500013M02606' ba.save() cls.bank_account = ba ba = BankAccount() ba.Type = 'IBAN' ba.IBAN = 'IR861234568790123456789012' cls.bank_account_outside_sepa = ba
def get_client_bank_account(recreate=False): if BaseTestLive._client_account is None or recreate: account = BankAccount() account.owner_name = 'Joe Blogs' account.type = 'IBAN' account.owner_address = Address() account.owner_address.address_line_1 = "Main Street" account.owner_address.address_line_2 = "no. 5 ap. 6" account.owner_address.country = "FR" account.owner_address.city = "Lyon" account.owner_address.postal_code = "65400" account.iban = 'FR7630004000031234567890143' account.bic = 'BNPAFRPP' account.tag = 'custom meta' account.create_client_bank_account() BaseTestLive._client_account = BankAccount( **account.create_client_bank_account()) return BaseTestLive._client_account
def stop(self): if not self.bid == 0: ba = BankAccount.get(id=self.bid) # something is fishy here: needs a reference??? ba.deactivate()