Esempio n. 1
0
    def test_direct_debit_creation(self, url):
        path = b'/homer/wallet/payin/direct-debit'
        data = {'amount': '100.00'}

        url.return_value = b'https://liberapay.com' + path

        r = self.client.PxST(path, data, auth_as=self.homer)
        assert r.code == 403  # rejected because homer has no donations set up

        self.homer.set_tip_to(self.david, EUR('10.00'))
        r = self.client.GET(path, auth_as=self.homer)
        assert b'FRxxxxxxxxxxxxxxxxxxxxx2606' in r.body, r.text

        r = self.client.POST(path,
                             data,
                             auth_as=self.homer,
                             raise_immediately=False)
        assert r.code == 200, r.text
        assert ';url=https://api.sandbox.mangopay.com/' in r.text

        exchange = self.db.one("SELECT * FROM exchanges")
        assert exchange.status == 'pre-mandate'
        route = ExchangeRoute.from_id(self.homer, exchange.route)

        path += ('/%s?MandateId=%s' %
                 (exchange.id, route.mandate)).encode('ascii')
        r = self.client.GET(path, auth_as=self.homer)
        assert r.code == 200

        exchange = self.db.one("SELECT * FROM exchanges")
        assert exchange.status == 'failed'
        assert exchange.note == '001833: The Status of this Mandate does not allow for payments'
Esempio n. 2
0
    def test_direct_debit_creation(self, url):
        path = b'/homer/wallet/payin/direct-debit'
        data = {'amount': '100.00'}

        url.return_value = b'https://liberapay.com' + path

        r = self.client.PxST(path, data, auth_as=self.homer)
        assert r.code == 403  # rejected because homer has no donations set up

        self.homer.set_tip_to(self.david, EUR('10.00'))
        r = self.client.GET(path, auth_as=self.homer)
        assert b'FRxxxxxxxxxxxxxxxxxxxxx2606' in r.body, r.text

        r = self.client.POST(path, data, auth_as=self.homer, raise_immediately=False)
        assert r.code == 200, r.text
        assert ';url=https://api.sandbox.mangopay.com/' in r.text

        exchange = self.db.one("SELECT * FROM exchanges")
        assert exchange.status == 'pre-mandate'
        route = ExchangeRoute.from_id(exchange.route)

        path += ('/%s?MandateId=%s' % (exchange.id, route.mandate)).encode('ascii')
        r = self.client.GET(path, auth_as=self.homer)
        assert r.code == 200

        exchange = self.db.one("SELECT * FROM exchanges")
        assert exchange.status == 'failed'
        assert exchange.note == '001833: The Status of this Mandate does not allow for payments'
Esempio n. 3
0
def record_payout_refund(db, payout_refund):
    orig_payout = BankWirePayOut.get(payout_refund.InitialTransactionId)
    e_origin = db.one("SELECT * FROM exchanges WHERE id = %s" % (orig_payout.Tag,))
    e_refund_id = db.one("SELECT id FROM exchanges WHERE refund_ref = %s", (e_origin.id,))
    if e_refund_id:
        # Already recorded
        return e_refund_id
    amount, fee, vat = -e_origin.amount, -e_origin.fee, -e_origin.vat
    assert payout_refund.DebitedFunds == Money(int(amount * 100), 'EUR')
    assert payout_refund.Fees == Money(int(fee * 100), 'EUR')
    route = ExchangeRoute.from_id(e_origin.route)
    participant = Participant.from_id(e_origin.participant)
    return db.one("""
        INSERT INTO exchanges
               (amount, fee, vat, participant, status, route, note, refund_ref)
        VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
     RETURNING id
    """, (amount, fee, vat, participant.id, 'created', route.id, None, e_origin.id))
Esempio n. 4
0
def record_payout_refund(db, payout_refund):
    orig_payout = BankWirePayOut.get(payout_refund.InitialTransactionId)
    e_origin = db.one("SELECT * FROM exchanges WHERE id = %s", (orig_payout.Tag,))
    e_refund_id = db.one("SELECT id FROM exchanges WHERE refund_ref = %s", (e_origin.id,))
    if e_refund_id:
        # Already recorded
        return e_refund_id
    amount, fee, vat = -e_origin.amount, -e_origin.fee, -e_origin.vat
    assert payout_refund.DebitedFunds / 100 == amount
    assert payout_refund.Fees / 100 == fee
    route = ExchangeRoute.from_id(e_origin.route)
    participant = Participant.from_id(e_origin.participant)
    remote_id = payout_refund.Id
    wallet_id = e_origin.wallet_id
    return db.one("""
        INSERT INTO exchanges
               (amount, fee, vat, participant, status, route, note, refund_ref, remote_id, wallet_id)
        VALUES (%s, %s, %s, %s, 'created', %s, NULL, %s, %s, %s)
     RETURNING id
    """, (amount, fee, vat, participant.id, route.id, e_origin.id, remote_id, wallet_id))
Esempio n. 5
0
def record_payout_refund(db, payout_refund):
    orig_payout = BankWirePayOut.get(payout_refund.InitialTransactionId)
    e_origin = db.one("SELECT * FROM exchanges WHERE id = %s", (orig_payout.Tag,))
    e_refund_id = db.one("SELECT id FROM exchanges WHERE refund_ref = %s", (e_origin.id,))
    if e_refund_id:
        # Already recorded
        return e_refund_id
    amount, fee, vat = -e_origin.amount, -e_origin.fee, -e_origin.vat
    assert payout_refund.DebitedFunds / 100 == amount
    assert payout_refund.Fees / 100 == fee
    participant = Participant.from_id(e_origin.participant)
    route = ExchangeRoute.from_id(participant, e_origin.route)
    remote_id = payout_refund.Id
    wallet_id = e_origin.wallet_id
    return db.one("""
        INSERT INTO exchanges
               (amount, fee, vat, participant, status, route, note, refund_ref, remote_id, wallet_id)
        VALUES (%s, %s, %s, %s, 'created', %s, NULL, %s, %s, %s)
     RETURNING id
    """, (amount, fee, vat, participant.id, route.id, e_origin.id, remote_id, wallet_id))