Ejemplo n.º 1
0
def payday():

    # Wire things up.
    # ===============

    env = wireup.env()
    db = wireup.db(env)

    wireup.billing(env)

    # Lazily import the billing module.
    # =================================
    # This dodges a problem where db in billing is None if we import it from
    # gratipay before calling wireup.billing.

    from gratipay.billing.exchanges import sync_with_balanced
    from gratipay.billing.payday import Payday

    try:
        sync_with_balanced(db)
        Payday.start().run()
    except KeyboardInterrupt:
        pass
    except:
        import aspen
        import traceback
        aspen.log(traceback.format_exc())
Ejemplo n.º 2
0
def payday():

    # Wire things up.
    # ===============

    env = wireup.env()
    db = wireup.db(env)

    wireup.billing(env)
    wireup.nanswers(env)

    # Lazily import the billing module.
    # =================================
    # This dodges a problem where db in billing is None if we import it from
    # gratipay before calling wireup.billing.

    from gratipay.billing.exchanges import sync_with_balanced
    from gratipay.billing.payday import Payday

    try:
        sync_with_balanced(db)
        Payday.start().run()
    except KeyboardInterrupt:
        pass
    except:
        import aspen
        import traceback

        aspen.log(traceback.format_exc())
Ejemplo n.º 3
0
 def test_sync_with_balanced(self):
     with mock.patch("gratipay.billing.exchanges.record_exchange_result") as rer:
         rer.side_effect = Foobar()
         hold, error = create_card_hold(self.db, self.janet, D("20.00"))
         assert error == ""  # sanity check
         with self.assertRaises(Foobar):
             capture_card_hold(self.db, self.janet, D("10.00"), hold)
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.status == "pre"
     sync_with_balanced(self.db)
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.status == "succeeded"
     assert Participant.from_username("janet").balance == 10
 def test_sync_with_balanced_reverts_credits_that_didnt_happen(self):
     self.make_exchange('balanced-cc', 41, 0, self.homer)
     with mock.patch('gratipay.billing.exchanges.record_exchange_result') as rer \
        , mock.patch('gratipay.billing.exchanges.thing_from_href') as tfh:
         rer.side_effect = tfh.side_effect = Foobar
         with self.assertRaises(Foobar):
             ach_credit(self.db, self.homer, 0, 0)
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == 'pre'
     sync_with_balanced(self.db)
     exchanges = self.db.all("SELECT * FROM exchanges WHERE amount < 0")
     assert not exchanges
     assert Participant.from_username('homer').balance == 41
 def test_sync_with_balanced_reverts_credits_that_didnt_happen(self):
     self.make_exchange('bill', 41, 0, self.homer)
     with mock.patch('gratipay.billing.exchanges.record_exchange_result') as rer \
        , mock.patch('balanced.Customer') as Customer:
         rer.side_effect = Customer.side_effect = Foobar
         with self.assertRaises(Foobar):
             ach_credit(self.db, self.homer, 0, 0)
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == 'pre'
     sync_with_balanced(self.db)
     exchanges = self.db.all("SELECT * FROM exchanges WHERE amount < 0")
     assert not exchanges
     assert Participant.from_username('homer').balance == 41
 def test_sync_with_balanced(self):
     with mock.patch('gratipay.billing.exchanges.record_exchange_result') as rer:
         rer.side_effect = Foobar()
         hold, error = create_card_hold(self.db, self.janet, D('20.00'))
         assert error == ''  # sanity check
         with self.assertRaises(Foobar):
             capture_card_hold(self.db, self.janet, D('10.00'), hold)
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.status == 'pre'
     sync_with_balanced(self.db)
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.status == 'succeeded'
     assert Participant.from_username('janet').balance == 10
Ejemplo n.º 7
0
 def test_sync_with_balanced_reverts_credits_that_didnt_happen(self):
     self.make_exchange("bill", 41, 0, self.homer)
     with mock.patch("gratipay.billing.exchanges.record_exchange_result") as rer, mock.patch(
         "balanced.Customer"
     ) as Customer:
         rer.side_effect = Customer.side_effect = Foobar
         with self.assertRaises(Foobar):
             ach_credit(self.db, self.homer, 0, 0)
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == "pre"
     sync_with_balanced(self.db)
     exchanges = self.db.all("SELECT * FROM exchanges WHERE amount < 0")
     assert not exchanges
     assert Participant.from_username("homer").balance == 41
 def test_sync_with_balanced_deletes_charges_that_didnt_happen(self):
     with mock.patch('gratipay.billing.exchanges.record_exchange_result') as rer \
        , mock.patch('balanced.CardHold.capture') as capture:
         rer.side_effect = capture.side_effect = Foobar
         hold, error = create_card_hold(self.db, self.janet, D('33.67'))
         assert error == ''  # sanity check
         with self.assertRaises(Foobar):
             capture_card_hold(self.db, self.janet, D('7.52'), hold)
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.status == 'pre'
     sync_with_balanced(self.db)
     exchanges = self.db.all("SELECT * FROM exchanges")
     assert not exchanges
     assert Participant.from_username('janet').balance == 0
 def test_sync_with_balanced_deletes_charges_that_didnt_happen(self):
     with mock.patch('gratipay.billing.exchanges.record_exchange_result') as rer \
        , mock.patch('balanced.CardHold.capture') as capture:
         rer.side_effect = capture.side_effect = Foobar
         hold, error = create_card_hold(self.db, self.janet, D('33.67'))
         assert error == ''  # sanity check
         with self.assertRaises(Foobar):
             capture_card_hold(self.db, self.janet, D('7.52'), hold)
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.status == 'pre'
     sync_with_balanced(self.db)
     exchanges = self.db.all("SELECT * FROM exchanges")
     assert not exchanges
     assert Participant.from_username('janet').balance == 0