Exemplo n.º 1
0
    def testSimple(self):
        """
        create a single transaction with PAYMENT_TYPE_AUTHORIZATION / ACTIVE with a $12.34 pledge and see whether the payment
        manager can query and get the right amount.
        """
        user = User.objects.create_user('payment_test', '*****@*****.**',
                                        'payment_test')

        w = Work()
        w.save()
        c = Campaign(target=D('1000.00'),
                     deadline=now() + timedelta(days=180),
                     work=w)
        c.save()

        t = Transaction()
        t.amount = D('12.34')
        t.type = PAYMENT_TYPE_AUTHORIZATION
        t.status = 'ACTIVE'
        t.approved = True
        t.campaign = c
        t.user = user
        t.save()

        #test pledge adders
        user.profile.reset_pledge_badge()
        self.assertEqual(user.profile.badges.all()[0].name, 'pledger')

        p = PaymentManager()
        results = p.query_campaign(c, campaign_total=True, summary=False)
        self.assertEqual(results[0].amount, D('12.34'))
        self.assertEqual(c.left, c.target - D('12.34'))
        self.assertEqual(c.supporters_count, 1)
Exemplo n.º 2
0
    def test_paymentmanager_charge(self):
        """
        test regluit.payment.manager.PaymentManager.charge
        
        trying to simulate the conditions of having a bare transaction setup before we try to do
        an instant charge.
        
        """
        user = User.objects.create_user('pm_charge', '*****@*****.**',
                                        'payment_test')
        # need to create an Account to associate with user
        from regluit.payment.stripelib import StripeClient, card, Processor

        sc = StripeClient()

        # valid card and Account
        card0 = card()
        stripe_processor = Processor()
        account = stripe_processor.make_account(user=user, token=card0)

        w = Work()
        w.save()

        c = Campaign(target=D('1000.00'),
                     deadline=now() + timedelta(days=180),
                     work=w)
        c.save()

        t = Transaction(host='stripelib')

        t.max_amount = D('12.34')
        t.type = PAYMENT_TYPE_NONE
        t.status = TRANSACTION_STATUS_NONE
        t.campaign = c
        t.approved = False
        t.user = user

        t.save()

        pm = PaymentManager()
        response = pm.charge(t)

        self.assertEqual(t.status, TRANSACTION_STATUS_COMPLETE)
        self.assertEqual(t.type, EXECUTE_TYPE_CHAINED_INSTANT)
        self.assertEqual(t.amount, D('12.34'))