1 | import grok |
---|
2 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
3 | from waeup.ikoba.browser.layout import IkobaEditFormPage, action |
---|
4 | from waeup.ikoba.payments.interfaces import IPaymentGatewayService, IPayment |
---|
5 | from waeup.ikoba.payments.payment import ( |
---|
6 | Payment, get_payment, find_payable_from_payable_id) |
---|
7 | |
---|
8 | |
---|
9 | grok.templatedir('templates') |
---|
10 | |
---|
11 | |
---|
12 | class DemoCreditcardPaymentService(grok.GlobalUtility): |
---|
13 | """A demo payment gateway service. |
---|
14 | |
---|
15 | This one supports credit card payments. |
---|
16 | """ |
---|
17 | grok.implements(IPaymentGatewayService) |
---|
18 | grok.name('demo_creditcard') |
---|
19 | |
---|
20 | title = _(u'Credit Card (Demo Payments)') |
---|
21 | |
---|
22 | def create_payment(self, payer, payment_item_list=[], payee=None): |
---|
23 | """Create a payment. |
---|
24 | """ |
---|
25 | payment = Payment() |
---|
26 | payment.gateway_service = 'demo_creditcard' # must be grok.name above |
---|
27 | payment.payer_id = payer.payer_id |
---|
28 | # XXX: we should not have to store a payment before adding items |
---|
29 | site = grok.getSite() |
---|
30 | site['payments'][payment.payment_id] = payment |
---|
31 | for item in payment_item_list: |
---|
32 | payment.add_payment_item(item) |
---|
33 | return payment |
---|
34 | |
---|
35 | def next_step(self, payment_id): |
---|
36 | """Tell where to go next. |
---|
37 | |
---|
38 | Returns (context, view_name). Both may be none. |
---|
39 | """ |
---|
40 | payment = get_payment(payment_id) |
---|
41 | if payment is None: |
---|
42 | return None, None |
---|
43 | return payment, 'demo_cc1' |
---|
44 | |
---|
45 | |
---|
46 | class CreditCardStep1(IkobaEditFormPage): |
---|
47 | grok.context(IPayment) |
---|
48 | grok.name('demo_cc1') |
---|
49 | # XXX: Use own permissions for payments |
---|
50 | grok.require('waeup.Authenticated') |
---|
51 | label = "Enter Credit Card Details" |
---|
52 | grok.template('demo_cc_step1') |
---|
53 | pnav = 4 |
---|
54 | |
---|
55 | def update(self): |
---|
56 | pass |
---|
57 | |
---|
58 | @action(_('Authorize Payment'), style="primary") |
---|
59 | def authorize(self, **data): |
---|
60 | print "AUTH!" |
---|
61 | |
---|
62 | @action(_('Cancel')) |
---|
63 | def cancel(self, **data): |
---|
64 | """Go back to the payable (if possible) or site home. |
---|
65 | """ |
---|
66 | payable_id = getattr(self.context, 'payable_id', '') |
---|
67 | payed_item = find_payable_from_payable_id(payable_id) |
---|
68 | self.flash(_("Payment cancelled.")) |
---|
69 | if payed_item is not None: |
---|
70 | # remove context/payment? |
---|
71 | target = self.url(payed_item) |
---|
72 | else: |
---|
73 | target = grok.getSite() |
---|
74 | self.redirect(self.url(target)) |
---|