diff --git a/payment/stripelib.py b/payment/stripelib.py index df669381..6a67bcf0 100644 --- a/payment/stripelib.py +++ b/payment/stripelib.py @@ -31,6 +31,7 @@ from regluit.payment.parameters import ( TRANSACTION_STATUS_COMPLETE, TRANSACTION_STATUS_ERROR, PAYMENT_TYPE_AUTHORIZATION, + PAYMENT_TYPE_INSTANT, TRANSACTION_STATUS_CANCELED ) from regluit.payment.signals import transaction_charged, transaction_failed @@ -680,13 +681,10 @@ class Processor(baseprocessor.Processor): if p.success() and not p.error(): transaction.pay_key = p.key() transaction.save() - return True - else: transaction.error = p.error_string() transaction.save() logger.info("execute_transaction Error: " + p.error_string()) - return False def amount( self ): return self.transaction.amount diff --git a/payment/tests.py b/payment/tests.py index af79435a..12776f58 100644 --- a/payment/tests.py +++ b/payment/tests.py @@ -297,6 +297,49 @@ class TransactionTest(TestCase): self.assertEqual(results[0].amount, D('12.34')) self.assertEqual(c.left,c.target-D('12.34')) self.assertEqual(c.supporters_count, 1) + + 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', 'support2@example.org', '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,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')) class BasicGuiTest(TestCase): def setUp(self):