From 62d2f2e9f80a4d79cd662d45ee9a005fb012b155 Mon Sep 17 00:00:00 2001 From: Hunter Freyer Date: Fri, 23 May 2014 18:47:46 -0400 Subject: [PATCH] commit --- backend/handlers.py | 32 ++++++++++++++++++++++++-------- unittests/test_e2e.py | 6 +++--- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/backend/handlers.py b/backend/handlers.py index 3bed89a..3c9805b 100644 --- a/backend/handlers.py +++ b/backend/handlers.py @@ -7,6 +7,8 @@ import validictory +import model + # Immutable environment with both configuration variables, and backends to be # mocked out in tests. Environment = namedtuple( @@ -28,15 +30,21 @@ class PaymentProcessor(object): """Interface which processes payments.""" - def CreateCustomer(self, payment_params, pledge_model): + + STRIPE = 'STRIPE' + + def CreateCustomer(self, plaform, params): """Does whatever the payment processor needs to do in order to be able to charge the customer later. Args: - payment_params: dict with keys like 'paypal' or 'stripe', with values - which are dicts with parameters specific to that payment platform. - pledge_model: A not-yet-committed pledge model for us to modify to include - a record of the customer. + platform: string, one of the ones declared above. + params: dict of parameters specific to that payment platform. + + Returns: + A pair of (str, dict), the str indicating the platform (one of the strings + declared above), and the dict giving the fields that will need to be + included in the Pledge model. """ raise NotImplementedError() @@ -55,8 +63,7 @@ class PledgeHandler(webapp2.RequestHandler): properties=dict( email=_STR, phone=dict(type='string', blank=True), - firstName=_STR, - lastName=_STR, + name=_STR, occupation=_STR, employer=_STR, target=_STR, @@ -82,8 +89,17 @@ def post(self): self.response.write('Invalid request') return + pledge = model.addPledge(email=data['email'], + stripe_customer_id='3', + amount_cents=data['amountCents'], + occupation=data['occupation'], + employer=data['employer'], + phone=data['phone'], + fundraisingRound='1', + target=data['target']) + self.response.headers['Content-Type'] = 'application/json' - json.dump(dict(id='2'), self.response) + json.dump(dict(id=pledge.url_nonce), self.response) HANDLERS = [ diff --git a/unittests/test_e2e.py b/unittests/test_e2e.py index a94ee72..955b5c1 100644 --- a/unittests/test_e2e.py +++ b/unittests/test_e2e.py @@ -23,16 +23,16 @@ def setUp(self): def tearDown(self): self.testbed.deactivate() + class PledgeTest(BaseTest): SAMPLE_USER = dict( email='pika@pokedex.biz', phone='212-234-5432', - firstName='Pika', - lastName='Chu', + name='Pika Chu', occupation=u'Pok\u00E9mon', employer='Nintendo', target='Republicans Only', - subscribe=False, + subscribe=True, amountCents=4200) def testBadJson(self):