From 24f21ffe24cabe97fa108f7a7f84857dc08f9eae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Wed, 2 Oct 2013 01:37:39 +0200 Subject: [PATCH 1/1] =?utf8?q?Paiement=20op=C3=A9rationnel=20avec=20PayPal?= =?utf8?q?.=20Il=20reste=20=C3=A0=20loguer=20les=20=C3=A9changes=20PayPal?= =?utf8?q?=20/=20Zope.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- order.py | 27 +++++++++++++++++---------- skins/photoprint_order_confirm.py | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 skins/photoprint_order_confirm.py diff --git a/order.py b/order.py index 7b87275..2948aaf 100755 --- a/order.py +++ b/order.py @@ -340,13 +340,15 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : quantitySum = reduce(lambda a, b : a['quantity'] + b['quantity'], self.items) priceSum = reduce(lambda a, b : a['unit_price'] * a['quantity'] + b['unit_price'] * b['quantity'], self.items) priceValues = priceSum.getValues() - total = round(priceValues['taxed'], 2) - basePrice = round(priceValues['value'], 2) - tax = round(total - basePrice, 2) + total = round(self.amountWithFees.getValues()['taxed'], 2) options['L_PAYMENTREQUEST_0_NAME0'] = 'Commande realis photo ref. %s' % self.getId() - options['L_PAYMENTREQUEST_0_DESC0'] = 'Commande de %d tirages photo' % quantitySum + if quantitySum == 1 : + options['L_PAYMENTREQUEST_0_DESC0'] = "Commande d'un tirage photographique" + else : + options['L_PAYMENTREQUEST_0_DESC0'] = 'Commande de %d tirages photographiques' % quantitySum options['L_PAYMENTREQUEST_0_AMT0'] = total + options['PAYMENTINFO_0_SHIPPINGAMT'] = round(self.shippingFees.getValues()['taxed'], 2) # options['L_PAYMENTREQUEST_0_TAXAMT0'] = tax # options['L_PAYMENTREQUEST_0_QTY%d' % n] = 1 options['PAYMENTREQUEST_0_AMT'] = total @@ -364,8 +366,8 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : def ppGetExpressCheckoutDetails(self, token) : ppi = self._initPayPalInterface() response = ppi.get_express_checkout_details(TOKEN=token) - response = Registration.recordifyPPResp(response) - self._paypalLog.append(response) + response = PrintOrder.recordifyPPResp(response) + # self._paypalLog.append(response) return response security.declarePrivate('ppDoExpressCheckoutPayment') @@ -376,15 +378,20 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : PAYMENTREQUEST_0_CURRENCYCODE='EUR', TOKEN=token, PAYERID=payerid) - response = Registration.recordifyPPResp(response) - self._paypalLog.append(response) + response = PrintOrder.recordifyPPResp(response) + # self._paypalLog.append(response) return response security.declareProtected(ModifyPortalContent, 'ppPay') def ppPay(self, token, payerid): # assure le paiement paypal en une passe : # récupération des détails et validation de la transaction. - if not self.paid : + + wtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IWorkflowTool') + wfstate = wtool.getInfoFor(self, 'review_state', 'order_workflow') + paid = wfstate == 'paid' + + if not paid : details = self.ppGetExpressCheckoutDetails(token) if payerid != details['PAYERID'] : @@ -401,7 +408,7 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : wtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IWorkflowTool') wtool.doActionFor( self , 'paypal_pay' - , wf_id='jma_registration_workflow' + , wf_id='order_workflow' , comments='Paiement par PayPal') return True return False diff --git a/skins/photoprint_order_confirm.py b/skins/photoprint_order_confirm.py new file mode 100644 index 0000000..c7a8d0a --- /dev/null +++ b/skins/photoprint_order_confirm.py @@ -0,0 +1,16 @@ +##parameters=token=None, PayerID=None +# -*- coding: utf-8 -*- + +from Products.photoprint.utils import Message as _ +options = {} +if token and PayerID and context.ppPay(token, PayerID) : + context.setStatus(True, _(u'Your payment has been accepted by PayPal.')) + # options['current_sell_step'] = 'confirmation' + return context.order_view() +else : + context.setStatus(False, _('Your payment has been canceled.
' + 'You can retry with an other account / credit card by cliking on the PayPal button.
' + 'You can also choose an other payment option, like bank transfert or cheque.
' + 'If so, click on the "Modify" button.')) + + return context.order_view() -- 2.20.1