1 | import grok |
---|
2 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
3 | from waeup.ikoba.browser.layout import IkobaPage |
---|
4 | from waeup.ikoba.payments.interfaces import IPaymentGatewayService, IPayment |
---|
5 | from waeup.ikoba.payments.payment import Payment, get_payment |
---|
6 | |
---|
7 | |
---|
8 | grok.templatedir('templates') |
---|
9 | |
---|
10 | |
---|
11 | class DemoCreditcardPaymentService(grok.GlobalUtility): |
---|
12 | """A demo payment gateway service. |
---|
13 | |
---|
14 | This one supports credit card payments. |
---|
15 | """ |
---|
16 | grok.implements(IPaymentGatewayService) |
---|
17 | grok.name('demo_creditcard') |
---|
18 | |
---|
19 | title = _(u'Credit Card (Demo Payments)') |
---|
20 | |
---|
21 | def create_payment(self, payer, payment_item_list=[], payee=None): |
---|
22 | """Create a payment. |
---|
23 | """ |
---|
24 | payment = Payment() |
---|
25 | payment.gateway_service = 'demo_creditcard' # must be grok.name above |
---|
26 | payment.payer_id = payer.payer_id |
---|
27 | # XXX: we should not have to store a payment before adding items |
---|
28 | site = grok.getSite() |
---|
29 | site['payments'][payment.payment_id] = payment |
---|
30 | for item in payment_item_list: |
---|
31 | payment.add_payment_item(item) |
---|
32 | return payment |
---|
33 | |
---|
34 | def next_step(self, payment_id): |
---|
35 | """Tell where to go next. |
---|
36 | |
---|
37 | Returns (context, view_name). Both may be none. |
---|
38 | """ |
---|
39 | payment = get_payment(payment_id) |
---|
40 | if payment is None: |
---|
41 | return None, None |
---|
42 | return payment, 'demo_cc1' |
---|
43 | |
---|
44 | |
---|
45 | class CreditCardStep1(IkobaPage): |
---|
46 | grok.context(IPayment) |
---|
47 | grok.name('demo_cc1') |
---|
48 | # XXX: Use own permissions for payments |
---|
49 | grok.require('waeup.Authenticated') |
---|
50 | label = "Enter Credit Card Details" |
---|
51 | grok.template('demo_cc_step1') |
---|
52 | pnav = 4 |
---|
53 | |
---|
54 | def update(self): |
---|
55 | pass |
---|