예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
 def test_skim_credit_outside_sepa(self):
     actual = skim_credit(EUR('10.00'), self.bank_account_outside_sepa)
     assert actual == (EUR('10.00'), EUR('0.00'), EUR('0.00'))
예제 #4
0
 def test_skim_credit(self):
     actual = skim_credit(EUR('10.00'), self.bank_account)
     assert actual == (EUR('10.00'), EUR('0.00'), EUR('0.00'))
예제 #5
0
 def test_skim_credit_outside_sepa(self):
     actual = skim_credit(D('10.00'), self.bank_account_outside_sepa)
     assert actual == (D('7.07'), D('2.93'), D('0.43'))
예제 #6
0
 def test_skim_credit_outside_sepa(self):
     actual = skim_credit(EUR('10.00'), self.bank_account_outside_sepa)
     assert actual == (EUR('7.07'), EUR('2.93'), EUR('0.43'))
예제 #7
0
 def test_skim_credit(self):
     actual = skim_credit(EUR('10.00'), self.bank_account)
     assert actual == (EUR('10.00'), EUR('0.00'), EUR('0.00'))