def payin_bank_wire(db, participant, debit_amount): """Prepare to receive a bank wire payin. The amount should be how much the user intends to send, not how much will arrive in the wallet. """ route = ExchangeRoute.upsert_bankwire_route(participant) if not isinstance(debit_amount, Money): debit_amount = Money(debit_amount, 'EUR') amount, fee, vat = skim_bank_wire(debit_amount) wallet = participant.get_current_wallet(amount.currency, create=True) e_id = record_exchange(db, route, amount, fee, vat, participant, 'pre').id payin = BankWirePayIn() payin.AuthorId = participant.mangopay_user_id payin.CreditedWalletId = wallet.remote_id payin.DeclaredDebitedFunds = debit_amount.int() payin.DeclaredFees = fee.int() payin.Tag = str(e_id) try: test_hook() payin.save() except Exception as e: error = repr_exception(e) return None, record_exchange_result(db, e_id, '', 'failed', error, participant) e = record_exchange_result( db, e_id, payin.Id, payin.Status.lower(), repr_error(payin), participant ) return payin, e
def payin_bank_wire(db, participant, debit_amount): """Prepare to receive a bank wire payin. The amount should be how much the user intends to send, not how much will arrive in the wallet. """ route = ExchangeRoute.upsert_generic_route(participant, 'mango-bw') if not isinstance(debit_amount, Money): debit_amount = Money(debit_amount, 'EUR') amount, fee, vat = skim_bank_wire(debit_amount) wallet = participant.get_current_wallet(amount.currency, create=True) e_id = record_exchange(db, route, amount, fee, vat, participant, 'pre').id payin = BankWirePayIn() payin.AuthorId = participant.mangopay_user_id payin.CreditedWalletId = wallet.remote_id payin.DeclaredDebitedFunds = Money_to_cents(debit_amount) payin.DeclaredFees = Money_to_cents(fee) payin.Tag = str(e_id) try: test_hook() payin.save() except Exception as e: error = repr_exception(e) return None, record_exchange_result(db, e_id, '', 'failed', error, participant) e = record_exchange_result( db, e_id, payin.Id, payin.Status.lower(), repr_error(payin), participant ) return payin, e
def payin_bank_wire(db, participant, debit_amount): """Prepare to receive a bank wire payin. The amount should be how much the user intends to send, not how much will arrive in the wallet. """ route = ExchangeRoute.from_network(participant, 'mango-bw') if not route: route = ExchangeRoute.insert(participant, 'mango-bw', 'x') amount, fee, vat = skim_bank_wire(debit_amount) e_id = record_exchange(db, route, amount, fee, vat, participant, 'pre') payin = BankWirePayIn() payin.AuthorId = participant.mangopay_user_id if not participant.mangopay_wallet_id: create_wallet(db, participant) payin.CreditedWalletId = participant.mangopay_wallet_id payin.DeclaredDebitedFunds = Money(int(debit_amount * 100), 'EUR') payin.DeclaredFees = Money(int(fee * 100), 'EUR') payin.Tag = str(e_id) try: test_hook() payin.save() except Exception as e: error = repr_exception(e) return None, record_exchange_result(db, e_id, 'failed', error, participant) e = record_exchange_result(db, e_id, payin.Status.lower(), repr_error(payin), participant) return payin, e
def create(self, account): self.cwid = account.wid self.fees = round(float(self.amount) * 0.1, 2) am = self.amount * 100 fe = self.fees * 100 bw = BankWirePayIn(AuthorId=self.saver.mid, CreditedWalletId=account.wid, DeclaredDebitedFunds=Money(am, account.currency), DeclaredFees=Money(fe, account.currency)) bw.save() self.piid = bw.Id # self.creation_date = bw.CreationDate # self.creation_date = _from_timestamp(bw.CreationDate) self.creation_date = datetime.datetime.now() self.status = 'CREATED' self.transaction_type = bw.BANK_WIRE self.wire_reference = bw.WireReference self.wire_type = bw.Type self.iban = bw.IBAN self.bic = bw.BIC self.save()
def create(self, user, amount, fees, line1, line2, city, pc, country): address = _make_address(line1, line2, city, pc, country) mid = MangoUser.objects.get(user=user).mid wallet = MangoWallet.objects.get(mid=mid).wid bw = BankWirePayIn(AuthorId=mid, CreditedWalletId=wallet, DeclaredDebitedFunds=Money(amount, wallet.currency), DeclaredFees=Money(fees, wallet.currency)) bw.save() self.piid = bw.get_pk() self.creation_date = bw['CreationDate'] self.status = 'CREATED' self.amount = amount self.fees = fees self.transaction_type = bw['BANK_WIRE'] self.wire_reference = bw['WireReference'] self.address = address self.wire_type = bw['Type'] self.iban = bw['IBAN'] self.bic = bw['BIC'] self.save()