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 ( |
---|
5 | IPaymentGatewayService, IPayment, IPayable, IPayer, IPayee,) |
---|
6 | from waeup.ikoba.payments.payment import ( |
---|
7 | Payment, get_payment, find_payable_from_payable_id, |
---|
8 | PaymentProviderServiceBase) |
---|
9 | |
---|
10 | |
---|
11 | grok.templatedir('templates') |
---|
12 | |
---|
13 | |
---|
14 | WARN_FINAL_SUBMIT = _( |
---|
15 | 'You can not edit your contract after final submission. ' |
---|
16 | 'Do you really want to submit?' |
---|
17 | ) |
---|
18 | |
---|
19 | |
---|
20 | class DemoCreditcardPaymentService(PaymentProviderServiceBase): |
---|
21 | """A demo payment gateway service. |
---|
22 | |
---|
23 | This one supports credit card payments. |
---|
24 | """ |
---|
25 | grok.implements(IPaymentGatewayService) |
---|
26 | grok.name('demo_creditcard') |
---|
27 | |
---|
28 | title = _(u'Credit Card (Demo Payments)') |
---|
29 | |
---|
30 | def create_payment(self, payer, payable, payee=None): |
---|
31 | """Create a payment. |
---|
32 | """ |
---|
33 | if not IPayer.providedBy(payer): |
---|
34 | payer = IPayer(payer) |
---|
35 | if not IPayable.providedBy(payable): |
---|
36 | payable = IPayable(payable) |
---|
37 | if (payee is not None) and (not IPayee.providedBy(payee)): |
---|
38 | payee = IPayee(payee) |
---|
39 | payment = Payment(payer, payable, payee) |
---|
40 | payment.gateway_service = 'demo_creditcard' # must be grok.name above |
---|
41 | return payment |
---|
42 | |
---|
43 | def next_step(self, payment_id): |
---|
44 | """Tell where to go next. |
---|
45 | |
---|
46 | Returns (context, view_name). Both may be none. |
---|
47 | """ |
---|
48 | payment = get_payment(payment_id) |
---|
49 | if payment is None: |
---|
50 | return None, None |
---|
51 | return payment, 'demo_cc1' |
---|
52 | |
---|
53 | |
---|
54 | class CreditCardStep1(IkobaEditFormPage): |
---|
55 | grok.context(IPayment) |
---|
56 | grok.name('demo_cc1') |
---|
57 | # XXX: Use own permissions for payments |
---|
58 | grok.require('waeup.Authenticated') |
---|
59 | label = "Enter Credit Card Details" |
---|
60 | grok.template('demo_cc_step1') |
---|
61 | pnav = 4 |
---|
62 | |
---|
63 | def update(self): |
---|
64 | pass |
---|
65 | |
---|
66 | @action(_('Authorize Payment'), warning=WARN_FINAL_SUBMIT, |
---|
67 | style="primary") |
---|
68 | def authorize(self, **data): |
---|
69 | print "AUTH!" |
---|
70 | |
---|
71 | @action(_('Cancel')) |
---|
72 | def cancel(self, **data): |
---|
73 | """Go back to the payable (if possible) or site home. |
---|
74 | """ |
---|
75 | payable_id = getattr(self.context, 'payable_id', '') |
---|
76 | payed_item = find_payable_from_payable_id(payable_id) |
---|
77 | self.flash(_("Payment cancelled.")) |
---|
78 | if payed_item is not None: |
---|
79 | # remove context/payment? |
---|
80 | target = self.url(payed_item) |
---|
81 | else: |
---|
82 | target = grok.getSite() |
---|
83 | self.redirect(self.url(target)) |
---|