added a first pass for payment.tests.TransactionTest.test_paymentmanager_charge to illustrate use of PaymentManager.charge() -> hardwired for stripelib right now....
parent
172ed2f557
commit
ccbc78a10c
|
@ -31,6 +31,7 @@ from regluit.payment.parameters import (
|
||||||
TRANSACTION_STATUS_COMPLETE,
|
TRANSACTION_STATUS_COMPLETE,
|
||||||
TRANSACTION_STATUS_ERROR,
|
TRANSACTION_STATUS_ERROR,
|
||||||
PAYMENT_TYPE_AUTHORIZATION,
|
PAYMENT_TYPE_AUTHORIZATION,
|
||||||
|
PAYMENT_TYPE_INSTANT,
|
||||||
TRANSACTION_STATUS_CANCELED
|
TRANSACTION_STATUS_CANCELED
|
||||||
)
|
)
|
||||||
from regluit.payment.signals import transaction_charged, transaction_failed
|
from regluit.payment.signals import transaction_charged, transaction_failed
|
||||||
|
@ -680,13 +681,10 @@ class Processor(baseprocessor.Processor):
|
||||||
if p.success() and not p.error():
|
if p.success() and not p.error():
|
||||||
transaction.pay_key = p.key()
|
transaction.pay_key = p.key()
|
||||||
transaction.save()
|
transaction.save()
|
||||||
return True
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
transaction.error = p.error_string()
|
transaction.error = p.error_string()
|
||||||
transaction.save()
|
transaction.save()
|
||||||
logger.info("execute_transaction Error: " + p.error_string())
|
logger.info("execute_transaction Error: " + p.error_string())
|
||||||
return False
|
|
||||||
|
|
||||||
def amount( self ):
|
def amount( self ):
|
||||||
return self.transaction.amount
|
return self.transaction.amount
|
||||||
|
|
|
@ -297,6 +297,49 @@ class TransactionTest(TestCase):
|
||||||
self.assertEqual(results[0].amount, D('12.34'))
|
self.assertEqual(results[0].amount, D('12.34'))
|
||||||
self.assertEqual(c.left,c.target-D('12.34'))
|
self.assertEqual(c.left,c.target-D('12.34'))
|
||||||
self.assertEqual(c.supporters_count, 1)
|
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):
|
class BasicGuiTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue