コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
 def get_pay_in(self):
     author = self.mangopay_user.get_user()
     credited_wallet = self.mangopay_wallet.get_wallet()
     return BankWirePayIn(
         author=author,
         declared_debited_funds=python_money_to_mangopay_money(
             self.debited_funds),
         declared_fees=python_money_to_mangopay_money(self.fees),
         credited_wallet=credited_wallet,
         payment_type=PAYIN_PAYMENT_TYPE.bank_wire)
コード例 #5
0
 def test_payin_bank_wire_callback(self, Get):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x')
     cases = (
         ('failed', '000001', 'FOO'),
         ('failed', '101109', 'The payment period has expired'),
         ('succeeded', '000000', None),
     )
     for status, result_code, error in cases:
         status_up = status.upper()
         e_id = record_exchange(self.db, route, EUR(11), EUR(0), EUR(0), homer, 'pre').id
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         qs = "EventType=PAYIN_NORMAL_"+status_up+"&RessourceId=123456790"
         payin = BankWirePayIn(Id=-1)
         payin.Status = status_up
         payin.ResultCode = result_code
         payin.ResultMessage = error
         payin.AuthorId = homer.mangopay_user_id
         payin.PaymentType = 'BANK_WIRE'
         payin.DeclaredDebitedFunds = Money(1100, 'EUR')
         payin.DeclaredFees = Money(0, 'EUR')
         payin.CreditedFunds = Money(0, 'XXX') if error else Money(1100, 'EUR')
         payin.Tag = str(e_id)
         Get.return_value = payin
         r = self.callback(qs)
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == 11
             assert homer.status == 'active'
         else:
             assert homer.balance == 0
             assert homer.status == 'closed'
         emails = self.get_emails()
         assert len(emails) == 1
         assert emails[0]['to'][0] == 'homer <%s>' % homer.email
         expected = 'expired' if result_code == '101109' else status[:4]
         assert expected in emails[0]['subject']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run
コード例 #6
0
ファイル: models.py プロジェクト: ojr9/g39
    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()
コード例 #7
0
ファイル: models.py プロジェクト: ojr9/confessapp
 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()
コード例 #8
0
 def _test_payin_bank_wire_callback_amount_mismatch(self, Get, fee):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x', 'chargeable')
     e_id = record_exchange(self.db, route, EUR(11), EUR(0), EUR(0), homer,
                            'pre').id
     assert homer.balance == 0
     homer.close(None)
     assert homer.status == 'closed'
     qs = "EventType=PAYIN_NORMAL_SUCCEEDED&RessourceId=123456790"
     payin = BankWirePayIn(Id=-1)
     payin.Status = 'SUCCEEDED'
     payin.ResultCode = '000000'
     payin.ResultMessage = None
     payin.AuthorId = homer.mangopay_user_id
     payin.PaymentType = 'BANK_WIRE'
     payin.DeclaredDebitedFunds = Money(4500, 'EUR')
     payin.DeclaredFees = Money(100, 'EUR')
     payin.DebitedFunds = Money(302, 'EUR')
     payin.Fees = Money(fee, 'EUR')
     payin.CreditedFunds = Money(302 - fee, 'EUR')
     payin.Tag = str(e_id)
     Get.return_value = payin
     r = self.callback(qs)
     assert r.code == 200, r.text
     e = self.db.one("SELECT * FROM exchanges WHERE id = %s", (e_id, ))
     assert e.amount == payin.CreditedFunds / 100
     assert e.fee == EUR(fee) / 100
     assert e.vat == EUR('0.01')
     assert e.status == 'succeeded'
     homer = homer.refetch()
     assert homer.balance == e.amount
     assert homer.status == 'active'
     emails = self.get_emails()
     assert len(emails) == 1
     assert emails[0]['to'][0] == 'homer <%s>' % homer.email
     assert 'succ' in emails[0]['subject']
     self.db.self_check()
コード例 #9
0
 def test_payin_bank_wire_callback_unexpected(self, Get):
     homer = self.homer
     cases = (
         ('failed', '000001', 'FOO', 0),
         ('succeeded', '000000', None, 5),
         ('succeeded', '000000', None, 2),
     )
     for status, result_code, error, fee in cases:
         status_up = status.upper()
         homer.set_tip_to(self.janet, EUR('1.00'))
         homer.close('downstream')
         assert homer.balance == 0
         assert homer.status == 'closed'
         qs = "EventType=PAYIN_NORMAL_" + status_up + "&RessourceId=123456790"
         payin = BankWirePayIn(Id=-1)
         payin.Status = status_up
         payin.ResultCode = result_code
         payin.ResultMessage = error
         payin.AuthorId = homer.mangopay_user_id
         payin.PaymentType = 'BANK_WIRE'
         payin.DebitedFunds = Money(242, 'EUR')
         payin.DeclaredDebitedFunds = payin.DebitedFunds
         payin.DeclaredFees = Money(fee, 'EUR')
         payin.Fees = Money(fee, 'EUR')
         payin.CreditedFunds = Money(0, 'XXX') if error else Money(
             242 - fee, 'EUR')
         payin.CreditedWalletId = self.homer_wallet_id
         Get.return_value = payin
         r = self.callback(qs)
         assert r.code == 200, r.text
         amount = EUR(242 - fee) / 100
         e = self.db.one(
             "SELECT * FROM exchanges ORDER BY timestamp DESC lIMIT 1")
         assert e.status == status
         assert e.amount == amount
         assert e.fee == EUR(fee) / 100
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == amount
             assert homer.status == 'active'
         else:
             assert homer.balance == 0
             assert homer.status == 'closed'
         emails = self.get_emails()
         assert len(emails) == 1
         assert emails[0]['to'][0] == 'homer <%s>' % homer.email
         assert status[:4] in emails[0]['subject']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run
コード例 #10
0
 def test_payin_bank_wire_callback(self, Get):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x', 'chargeable')
     cases = (
         ('failed', '000001', 'FOO'),
         ('failed', '101109', 'The payment period has expired'),
         ('succeeded', '000000', None),
     )
     for status, result_code, error in cases:
         status_up = status.upper()
         e_id = record_exchange(self.db, route, EUR(11), EUR(0), EUR(0),
                                homer, 'pre').id
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         qs = "EventType=PAYIN_NORMAL_" + status_up + "&RessourceId=123456790"
         payin = BankWirePayIn(Id=-1)
         payin.Status = status_up
         payin.ResultCode = result_code
         payin.ResultMessage = error
         payin.AuthorId = homer.mangopay_user_id
         payin.PaymentType = 'BANK_WIRE'
         payin.DeclaredDebitedFunds = Money(1100, 'EUR')
         payin.DeclaredFees = Money(0, 'EUR')
         payin.CreditedFunds = Money(0, 'XXX') if error else Money(
             1100, 'EUR')
         payin.Tag = str(e_id)
         Get.return_value = payin
         r = self.callback(qs)
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == 11
             assert homer.status == 'active'
         else:
             assert homer.balance == 0
             assert homer.status == 'closed'
         emails = self.get_emails()
         assert len(emails) == 1
         assert emails[0]['to'][0] == 'homer <%s>' % homer.email
         expected = 'expired' if result_code == '101109' else status[:4]
         assert expected in emails[0]['subject']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run
コード例 #11
0
 def test_payin_bank_wire_callback(self, Get):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x')
     for status in ('failed', 'succeeded'):
         status_up = status.upper()
         error = 'FOO' if status == 'failed' else None
         e_id = record_exchange(self.db, route, 11, 0, 0, homer, 'pre')
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         qs = "EventType=PAYIN_NORMAL_"+status_up+"&RessourceId=123456790"
         payin = BankWirePayIn()
         payin.Status = status_up
         payin.ResultCode = '000001' if error else '000000'
         payin.ResultMessage = error
         payin.AuthorId = homer.mangopay_user_id
         payin.PaymentType = 'BANK_WIRE'
         payin.DeclaredDebitedFunds = Money(1100, 'EUR')
         payin.DeclaredFees = Money(0, 'EUR')
         payin.CreditedFunds = Money(0, 'XXX') if error else Money(1100, 'EUR')
         payin.Tag = str(e_id)
         Get.return_value = payin
         r = self.callback(qs)
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == 11
             assert homer.status == 'active'
         else:
             assert homer.balance == 0
             assert homer.status == 'closed'
         emails = self.get_emails()
         assert len(emails) == 1
         assert emails[0]['to'][0] == 'homer <%s>' % homer.email
         assert status[:4] in emails[0]['subject']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run
コード例 #12
0
ファイル: models.py プロジェクト: ojr9/g39
 def _check_status(self):
     bw = BankWirePayIn.get(Id=self.piid)
     if bw.status != self.status:
         self.status = bw.status
     return self.status
コード例 #13
0
 def _test_payin_bank_wire_callback_amount_mismatch(self, Get, fee):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x')
     e_id = record_exchange(self.db, route, EUR(11), EUR(0), EUR(0), homer, 'pre').id
     assert homer.balance == 0
     homer.close(None)
     assert homer.status == 'closed'
     qs = "EventType=PAYIN_NORMAL_SUCCEEDED&RessourceId=123456790"
     payin = BankWirePayIn(Id=-1)
     payin.Status = 'SUCCEEDED'
     payin.ResultCode = '000000'
     payin.ResultMessage = None
     payin.AuthorId = homer.mangopay_user_id
     payin.PaymentType = 'BANK_WIRE'
     payin.DeclaredDebitedFunds = Money(4500, 'EUR')
     payin.DeclaredFees = Money(100, 'EUR')
     payin.DebitedFunds = Money(302, 'EUR')
     payin.Fees = Money(fee, 'EUR')
     payin.CreditedFunds = Money(302 - fee, 'EUR')
     payin.Tag = str(e_id)
     Get.return_value = payin
     r = self.callback(qs)
     assert r.code == 200, r.text
     e = self.db.one("SELECT * FROM exchanges WHERE id = %s", (e_id,))
     assert e.amount == D(payin.CreditedFunds.Amount) / D(100)
     assert e.fee == D(fee) / D(100)
     assert e.vat == D('0.01')
     assert e.status == 'succeeded'
     homer = homer.refetch()
     assert homer.balance == e.amount
     assert homer.status == 'active'
     emails = self.get_emails()
     assert len(emails) == 1
     assert emails[0]['to'][0] == 'homer <%s>' % homer.email
     assert 'succ' in emails[0]['subject']
     self.db.self_check()
コード例 #14
0
 def test_payin_bank_wire_callback_unexpected(self, Get):
     homer = self.homer
     cases = (
         ('failed', '000001', 'FOO', 0),
         ('succeeded', '000000', None, 5),
         ('succeeded', '000000', None, 2),
     )
     for status, result_code, error, fee in cases:
         status_up = status.upper()
         homer.set_tip_to(self.janet, EUR('1.00'))
         homer.close('downstream')
         assert homer.balance == 0
         assert homer.status == 'closed'
         qs = "EventType=PAYIN_NORMAL_"+status_up+"&RessourceId=123456790"
         payin = BankWirePayIn(Id=-1)
         payin.Status = status_up
         payin.ResultCode = result_code
         payin.ResultMessage = error
         payin.AuthorId = homer.mangopay_user_id
         payin.PaymentType = 'BANK_WIRE'
         payin.DebitedFunds = Money(242, 'EUR')
         payin.DeclaredDebitedFunds = payin.DebitedFunds
         payin.DeclaredFees = Money(fee, 'EUR')
         payin.Fees = Money(fee, 'EUR')
         payin.CreditedFunds = Money(0, 'XXX') if error else Money(242 - fee, 'EUR')
         payin.CreditedWalletId = self.homer_wallet_id
         Get.return_value = payin
         r = self.callback(qs)
         assert r.code == 200, r.text
         amount = D(242 - fee) / D(100)
         e = self.db.one("SELECT * FROM exchanges ORDER BY timestamp DESC lIMIT 1")
         assert e.status == status
         assert e.amount == amount
         assert e.fee == D(fee) / D(100)
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == amount
             assert homer.status == 'active'
         else:
             assert homer.balance == 0
             assert homer.status == 'closed'
         emails = self.get_emails()
         assert len(emails) == 1
         assert emails[0]['to'][0] == 'homer <%s>' % homer.email
         assert status[:4] in emails[0]['subject']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run