From 3d0ac6643e8a3a3a257f3ba72f63c3852b9a3a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 7 Nov 2013 18:15:58 +0100 Subject: [PATCH] [IMP] payment_acquirer: continuing base model. Two main models : payment.acquirer and payment.transaction. payment.acquirer models the acquirer: paypal, ogone. Each specific acquirer will inherit from the class and add specific fields. payment.transaction models the transaction itself. It has basic fields for a transaction: date, partner, partner fields (to hold data at transaction time), reference, state and its message, amount, currency. Class methods are not finished and still quite WIP. payment.acqurier has a render method that is used to render its form. The form is the 'pay now' button with the specific sementic of each acquirer. This model is supposed to work on form-based and server-to-server implementation methods. bzr revid: tde@openerp.com-20131107171558-jrwrj3ll9kol6bav --- addons/payment_acquirer/__openerp__.py | 8 +- addons/payment_acquirer/controllers/main.py | 74 ++- .../data/payment_acquirer_data.xml | 31 +- addons/payment_acquirer/models/__init__.py | 2 + .../models/payment_acquirer.py | 530 ++++++------------ .../payment_acquirer/views/acquirer_view.xml | 63 --- .../views/payment_acquirer_views.xml | 136 +++++ 7 files changed, 415 insertions(+), 429 deletions(-) delete mode 100644 addons/payment_acquirer/views/acquirer_view.xml create mode 100644 addons/payment_acquirer/views/payment_acquirer_views.xml diff --git a/addons/payment_acquirer/__openerp__.py b/addons/payment_acquirer/__openerp__.py index 1452489c876..6fd1d82489a 100644 --- a/addons/payment_acquirer/__openerp__.py +++ b/addons/payment_acquirer/__openerp__.py @@ -26,10 +26,14 @@ 'version': '0.1', 'description': """Payment acquirer module, use to display payment method and validate the payments.""", 'author': 'OpenERP SA', - 'depends': ['decimal_precision'], + 'depends': ['decimal_precision', 'mail'], 'data': [ - 'views/acquirer_view.xml', + 'views/payment_acquirer_views.xml', + 'views/ogone.xml', + 'views/paypal.xml', 'data/payment_acquirer_data.xml', + 'data/ogone.xml', + 'data/paypal.xml', 'security/ir.model.access.csv', ], 'installable': True, diff --git a/addons/payment_acquirer/controllers/main.py b/addons/payment_acquirer/controllers/main.py index 1aa84ebdbbc..9f1dcdc0f58 100644 --- a/addons/payment_acquirer/controllers/main.py +++ b/addons/payment_acquirer/controllers/main.py @@ -21,12 +21,76 @@ from openerp.addons.web import http from openerp.addons.web.http import request +# from openerp.addons.payment_acquirer.models.payment_acquirer import ValidationError from openerp.addons.website.models import website +import logging +import requests +from urllib import urlencode -class website_project(http.Controller): +_logger = logging.getLogger(__name__) - @website.route(['/payment_acquirer//'], type='http', auth="public") - def project(self, acquirer=None, **post): - obj = request.registry['payment.acquirer'] - return obj.transaction_feedback(request.cr, request.uid, acquirer, context=request.context, **post) + +class PaypalController(http.Controller): + _notify_url = '/payment/paypal/ipn/' + _return_url = '/payment/paypal/dpn/' + _cancel_url = '/payment/paypal/cancel/' + # _ipn_url2 = '/payment/paypal//ipn/' + + @website.route('/payment/paypal//ipn/', type='http', auth='admin') + def paypal_ipn(self, **post): + print 'Entering paypal_ipn with post', post + # step 1: return an empty HTTP 200 response -> will be done at the end by returning '' + + # step 2: POST the complete, unaltered message back to Paypal (preceded by cmd=_notify-validate), with same encoding + paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr" + post_url = '%s?cmd=_notify-validate&%s' % (paypal_url, urlencode(post)) + resp = requests.post(post_url) + print '\tReceived response', resp, resp.text + + # step 3: paypal send either VERIFIED or INVALID (single word) + if resp.text == 'VERIFIED': + # _logger.warning('') + cr, uid, context = request.cr, request.uid, request.context + # payment_transaction = request.registry['payment.transaction'] + # payment_transaction.validate() + elif resp.text == 'INVALID': + # _logger.warning('') + pass + else: + # _logger.warning('') -> something went wrong + pass + + return '' + + @website.route([ + '/payment/paypal/test/dpn', + ], type='http', auth="public") + def paypal_test_success(self, **post): + """ TODO + """ + cr, uid, context = request.cr, request.uid, request.context + print post + return '' + + +class OgoneController(http.Controller): + _accept_url = '/payment/ogone/test/accept' + _decline_url = '/payment/ogone/test/decline' + _exception_url = '/payment/ogone/test/exception' + _cancel_url = '/payment/ogone/test/cancel' + + @website.route([ + '/payment/ogone/feedback', '/payment/ogone/test/accept', + '/payment/ogone/decline', '/payment/ogone/test/decline', + '/payment/ogone/exception', '/payment/ogone/test/exception', + '/payment/ogone/cancel', '/payment/ogone/test/cancel', + ], type='http', auth='admin') + def feedback(self, **post): + cr, uid, context = request.cr, request.uid, request.context + Payment = request.registry['payment.transaction'] + print 'Entering ogone feedback with', post + + res = Payment.tx_ogone_feedback(cr, uid, post, context) + print res + return '' diff --git a/addons/payment_acquirer/data/payment_acquirer_data.xml b/addons/payment_acquirer/data/payment_acquirer_data.xml index dd8df209b59..e99186dc922 100644 --- a/addons/payment_acquirer/data/payment_acquirer_data.xml +++ b/addons/payment_acquirer/data/payment_acquirer_data.xml @@ -3,7 +3,7 @@ - + - + + + + + -