diff --git a/addons/payment_acquirer/__openerp__.py b/addons/payment_acquirer/__openerp__.py index 6fd1d82489a..164e1d77318 100644 --- a/addons/payment_acquirer/__openerp__.py +++ b/addons/payment_acquirer/__openerp__.py @@ -29,11 +29,7 @@ 'depends': ['decimal_precision', 'mail'], 'data': [ '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 9f1dcdc0f58..c0ef7f383d4 100644 --- a/addons/payment_acquirer/controllers/main.py +++ b/addons/payment_acquirer/controllers/main.py @@ -20,77 +20,11 @@ ############################################################################## 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 _logger = logging.getLogger(__name__) -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 '' +class PaymentController(http.Controller): + pass diff --git a/addons/payment_acquirer/models/__init__.py b/addons/payment_acquirer/models/__init__.py index fdedec55fe0..0ce2de595b2 100644 --- a/addons/payment_acquirer/models/__init__.py +++ b/addons/payment_acquirer/models/__init__.py @@ -20,5 +20,3 @@ ############################################################################## import payment_acquirer -import paypal -import ogone diff --git a/addons/payment_acquirer/tests/__init__.py b/addons/payment_acquirer/tests/__init__.py index ffdb032ee0f..8d0bb0195bf 100644 --- a/addons/payment_acquirer/tests/__init__.py +++ b/addons/payment_acquirer/tests/__init__.py @@ -19,10 +19,4 @@ # ############################################################################## -from . import test_payment_acquirer - -checks = [ - test_payment_acquirer, -] - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +import common diff --git a/addons/payment_acquirer/tests/common.py b/addons/payment_acquirer/tests/common.py index a99a5d1a610..df368f5b1dd 100644 --- a/addons/payment_acquirer/tests/common.py +++ b/addons/payment_acquirer/tests/common.py @@ -22,10 +22,10 @@ from openerp.tests import common -class TestPaymentAcquirer(common.TransactionCase): +class PaymentAcquirerCommon(common.TransactionCase): def setUp(self): - super(TestPaymentAcquirer, self).setUp() + super(PaymentAcquirerCommon, self).setUp() self.payment_acquirer = self.registry('payment.acquirer') self.payment_transaction = self.registry('payment.transaction') diff --git a/addons/payment_acquirer_ogone/__init__.py b/addons/payment_acquirer_ogone/__init__.py new file mode 100644 index 00000000000..dde6f25c728 --- /dev/null +++ b/addons/payment_acquirer_ogone/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import models +import controllers diff --git a/addons/payment_acquirer_ogone/__openerp__.py b/addons/payment_acquirer_ogone/__openerp__.py new file mode 100644 index 00000000000..9583319c4e5 --- /dev/null +++ b/addons/payment_acquirer_ogone/__openerp__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'Ogone Payment Acquirer', + 'category': 'Hidden', + 'summary': 'Payment acquirer: Ogone', + 'version': '0.1', + 'description': """Ogone Payment Acquirer""", + 'author': 'OpenERP SA', + 'depends': ['payment_acquirer'], + 'data': [ + 'views/ogone.xml', + 'data/ogone.xml', + ], + 'installable': True, +} diff --git a/addons/payment_acquirer_ogone/controllers/__init__.py b/addons/payment_acquirer_ogone/controllers/__init__.py new file mode 100644 index 00000000000..039d9715fab --- /dev/null +++ b/addons/payment_acquirer_ogone/controllers/__init__.py @@ -0,0 +1 @@ +import main \ No newline at end of file diff --git a/addons/payment_acquirer_ogone/controllers/main.py b/addons/payment_acquirer_ogone/controllers/main.py new file mode 100644 index 00000000000..8633ba30f12 --- /dev/null +++ b/addons/payment_acquirer_ogone/controllers/main.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +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 + +_logger = logging.getLogger(__name__) + + +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/__init__.py b/addons/payment_acquirer_ogone/data/__init__.py similarity index 100% rename from addons/payment_acquirer/data/__init__.py rename to addons/payment_acquirer_ogone/data/__init__.py diff --git a/addons/payment_acquirer/data/ogone.py b/addons/payment_acquirer_ogone/data/ogone.py similarity index 100% rename from addons/payment_acquirer/data/ogone.py rename to addons/payment_acquirer_ogone/data/ogone.py diff --git a/addons/payment_acquirer/data/ogone.xml b/addons/payment_acquirer_ogone/data/ogone.xml similarity index 100% rename from addons/payment_acquirer/data/ogone.xml rename to addons/payment_acquirer_ogone/data/ogone.xml diff --git a/addons/payment_acquirer_ogone/models/__init__.py b/addons/payment_acquirer_ogone/models/__init__.py new file mode 100644 index 00000000000..61f4cbeacf3 --- /dev/null +++ b/addons/payment_acquirer_ogone/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import ogone diff --git a/addons/payment_acquirer/models/ogone.py b/addons/payment_acquirer_ogone/models/ogone.py similarity index 99% rename from addons/payment_acquirer/models/ogone.py rename to addons/payment_acquirer_ogone/models/ogone.py index 1c7296e580f..af7535ade8e 100644 --- a/addons/payment_acquirer/models/ogone.py +++ b/addons/payment_acquirer_ogone/models/ogone.py @@ -30,8 +30,8 @@ import urllib2 # import urlparse from openerp.addons.payment_acquirer.data import ogone -from openerp.addons.payment_acquirer.controllers.main import OgoneController from openerp.addons.payment_acquirer.models.payment_acquirer import ValidationError +from openerp.addons.payment_acquirer_ogone.controllers.main import OgoneController from openerp.osv import osv, fields from openerp.tools import float_round diff --git a/addons/payment_acquirer_ogone/tests/__init__.py b/addons/payment_acquirer_ogone/tests/__init__.py new file mode 100644 index 00000000000..2381425068e --- /dev/null +++ b/addons/payment_acquirer_ogone/tests/__init__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import test_ogone + +checks = [ + test_ogone, +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/payment_acquirer/tests/test_payment_acquirer.py b/addons/payment_acquirer_ogone/tests/test_ogone.py similarity index 57% rename from addons/payment_acquirer/tests/test_payment_acquirer.py rename to addons/payment_acquirer_ogone/tests/test_ogone.py index 0de5813412e..cb34ed1ddda 100644 --- a/addons/payment_acquirer/tests/test_payment_acquirer.py +++ b/addons/payment_acquirer_ogone/tests/test_ogone.py @@ -19,98 +19,16 @@ # ############################################################################## -from openerp.addons.payment_acquirer.controllers.main import OgoneController -from openerp.addons.payment_acquirer.tests.common import TestPaymentAcquirer -from openerp.osv.orm import except_orm +from openerp.addons.payment_acquirer.tests.common import PaymentAcquirerCommon +from openerp.addons.payment_acquirer_ogone.controllers.main import OgoneController +# from openerp.osv.orm import except_orm from lxml import objectify # import requests # import urlparse -class BasicPayment(TestPaymentAcquirer): - - def test_10_paypal_basic(self): - pass - - def test_11_paypal_form(self): - cr, uid = self.cr, self.uid - context = {} - base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url') - # ogone_url = self.payment_acquirer._get_ogone_urls(cr, uid, [ogone_id], None, None)[ogone_id]['ogone_standard_order_url'] - - model, paypal_view_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_acquirer', 'paypal_acquirer_button') - - # forgot some mandatory fields: should crash - with self.assertRaises(except_orm): - paypal_id = self.payment_acquirer.create( - cr, uid, { - 'name': 'paypal', - 'env': 'test', - 'view_template_id': paypal_view_id, - 'paypal_email_id': 'tde+paypal-facilitator@openerp.com', - }, context=context - ) - # tde+buyer@openerp.com - - # create a new paypal account - paypal_id = self.payment_acquirer.create( - cr, uid, { - 'name': 'paypal', - 'env': 'test', - 'view_template_id': paypal_view_id, - 'paypal_email_id': 'tde+paypal-facilitator@openerp.com', - 'paypal_username': 'tde+paypal-facilitator_api1.openerp.com', - }, context=context - ) - # verify acquirer data - paypal = self.payment_acquirer.browse(cr, uid, paypal_id, context) - self.assertEqual(paypal.env, 'test', 'test without test env') - - # render the button - res = self.payment_acquirer.render( - cr, uid, paypal_id, - 'test_ref0', 0.01, self.currency_euro, - partner_id=None, - partner_values=self.buyer_values, - context=context) - print res - - # # check some basic paypal methods - # res = self.payment_transaction.validate_paypal_notification( - # cr, uid, - # 'http://localhost/payment?mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name=Test+User¬ify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00') - # self.assertEqual(res, False, 'payment: paypal validation on a txn_id that does not exists should return False') - - # txn_id = self.payment_transaction.create( - # cr, uid, { - # 'amount': 0.01, - # 'acquirer_id': paypal_id, - # 'currency_id': currency_id, - # 'reference': 'test_reference', - # 'paypal_txn_id': '61E67681CH3238416', - # }, context=context - # ) - # res = self.payment_transaction.validate_paypal_notification( - # cr, uid, - # 'http://localhost/payment?mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name=Test+User¬ify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00') - # print res - - # # user pays using Paypal - # resp = self.payment_transaction.create_paypal_command( - # cr, uid, cmd='_xclick', parameters={ - # 'business': 'tdelavallee-facilitator@gmail.com', - # 'amount': 50, - # 'item_name': 'test_item', - # 'quantity': 1, - # 'currency_code': 'USD', - # 'return': 'http://www.example.com', - # }) - # print resp - # print resp.url - # print resp.text - - # self.payment_transaction.validate(cr, uid, [tx_id], context=context) +class BasicPayment(PaymentAcquirerCommon): def test_20_ogone_form(self): cr, uid = self.cr, self.uid @@ -118,7 +36,7 @@ class BasicPayment(TestPaymentAcquirer): base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url') # ogone_url = self.payment_acquirer._get_ogone_urls(cr, uid, [ogone_id], None, None)[ogone_id]['ogone_standard_order_url'] - model, ogone_view_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_acquirer', 'ogone_acquirer_button') + model, ogone_view_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_acquirer_ogone', 'ogone_acquirer_button') # create a new ogone account ogone_id = self.payment_acquirer.create( @@ -211,7 +129,7 @@ class BasicPayment(TestPaymentAcquirer): cr, uid = self.cr, self.uid context = {} - model, ogone_view_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_acquirer', 'ogone_acquirer_button') + model, ogone_view_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_acquirer_ogone', 'ogone_acquirer_button') # create a new ogone account ogone_id = self.payment_acquirer.create( diff --git a/addons/payment_acquirer/views/ogone.xml b/addons/payment_acquirer_ogone/views/ogone.xml similarity index 100% rename from addons/payment_acquirer/views/ogone.xml rename to addons/payment_acquirer_ogone/views/ogone.xml diff --git a/addons/payment_acquirer_paypal/__init__.py b/addons/payment_acquirer_paypal/__init__.py new file mode 100644 index 00000000000..dde6f25c728 --- /dev/null +++ b/addons/payment_acquirer_paypal/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import models +import controllers diff --git a/addons/payment_acquirer_paypal/__openerp__.py b/addons/payment_acquirer_paypal/__openerp__.py new file mode 100644 index 00000000000..d9ceb1eeb8f --- /dev/null +++ b/addons/payment_acquirer_paypal/__openerp__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'Paypal Payment Acquirer', + 'category': 'Hidden', + 'summary': 'Paypal Payment Acquirer', + 'version': '0.1', + 'description': """Paypal Payment Acquirer""", + 'author': 'OpenERP SA', + 'depends': ['payment_acquirer'], + 'data': [ + 'views/paypal.xml', + 'data/paypal.xml', + ], + 'installable': True, +} diff --git a/addons/payment_acquirer_paypal/controllers/__init__.py b/addons/payment_acquirer_paypal/controllers/__init__.py new file mode 100644 index 00000000000..039d9715fab --- /dev/null +++ b/addons/payment_acquirer_paypal/controllers/__init__.py @@ -0,0 +1 @@ +import main \ No newline at end of file diff --git a/addons/payment_acquirer_paypal/controllers/main.py b/addons/payment_acquirer_paypal/controllers/main.py new file mode 100644 index 00000000000..7b9d654b30b --- /dev/null +++ b/addons/payment_acquirer_paypal/controllers/main.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +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 + +_logger = logging.getLogger(__name__) + + +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 '' diff --git a/addons/payment_acquirer/data/paypal.xml b/addons/payment_acquirer_paypal/data/paypal.xml similarity index 100% rename from addons/payment_acquirer/data/paypal.xml rename to addons/payment_acquirer_paypal/data/paypal.xml diff --git a/addons/payment_acquirer_paypal/models/__init__.py b/addons/payment_acquirer_paypal/models/__init__.py new file mode 100644 index 00000000000..d89c4a0fee3 --- /dev/null +++ b/addons/payment_acquirer_paypal/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import paypal diff --git a/addons/payment_acquirer/models/paypal.py b/addons/payment_acquirer_paypal/models/paypal.py similarity index 99% rename from addons/payment_acquirer/models/paypal.py rename to addons/payment_acquirer_paypal/models/paypal.py index 7fbc0638ff6..42113994e22 100644 --- a/addons/payment_acquirer/models/paypal.py +++ b/addons/payment_acquirer_paypal/models/paypal.py @@ -19,8 +19,8 @@ # ############################################################################## -from openerp.addons.payment_acquirer.controllers.main import PaypalController from openerp.addons.payment_acquirer.models.payment_acquirer import ValidationError +from openerp.addons.payment_acquirer_paypal.controllers.main import PaypalController from openerp.osv import osv, fields import logging diff --git a/addons/payment_acquirer_paypal/tests/__init__.py b/addons/payment_acquirer_paypal/tests/__init__.py new file mode 100644 index 00000000000..2868b3261e1 --- /dev/null +++ b/addons/payment_acquirer_paypal/tests/__init__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import test_paypal + +checks = [ + test_paypal, +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/payment_acquirer_paypal/tests/test_paypal.py b/addons/payment_acquirer_paypal/tests/test_paypal.py new file mode 100644 index 00000000000..bd6174930ab --- /dev/null +++ b/addons/payment_acquirer_paypal/tests/test_paypal.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.addons.payment_acquirer.tests.common import PaymentAcquirerCommon +from openerp.osv.orm import except_orm + +from lxml import objectify +# import requests +# import urlparse + + +class BasicPayment(PaymentAcquirerCommon): + + def test_10_paypal_basic(self): + pass + + def test_11_paypal_form(self): + cr, uid = self.cr, self.uid + context = {} + base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url') + # ogone_url = self.payment_acquirer._get_ogone_urls(cr, uid, [ogone_id], None, None)[ogone_id]['ogone_standard_order_url'] + + model, paypal_view_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_acquirer_paypal', 'paypal_acquirer_button') + + # forgot some mandatory fields: should crash + with self.assertRaises(except_orm): + paypal_id = self.payment_acquirer.create( + cr, uid, { + 'name': 'paypal', + 'env': 'test', + 'view_template_id': paypal_view_id, + 'paypal_email_id': 'tde+paypal-facilitator@openerp.com', + }, context=context + ) + # tde+buyer@openerp.com + + # create a new paypal account + paypal_id = self.payment_acquirer.create( + cr, uid, { + 'name': 'paypal', + 'env': 'test', + 'view_template_id': paypal_view_id, + 'paypal_email_id': 'tde+paypal-facilitator@openerp.com', + 'paypal_username': 'tde+paypal-facilitator_api1.openerp.com', + }, context=context + ) + # verify acquirer data + paypal = self.payment_acquirer.browse(cr, uid, paypal_id, context) + self.assertEqual(paypal.env, 'test', 'test without test env') + + # render the button + res = self.payment_acquirer.render( + cr, uid, paypal_id, + 'test_ref0', 0.01, self.currency_euro, + partner_id=None, + partner_values=self.buyer_values, + context=context) + print res + + # # check some basic paypal methods + # res = self.payment_transaction.validate_paypal_notification( + # cr, uid, + # 'http://localhost/payment?mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name=Test+User¬ify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00') + # self.assertEqual(res, False, 'payment: paypal validation on a txn_id that does not exists should return False') + + # txn_id = self.payment_transaction.create( + # cr, uid, { + # 'amount': 0.01, + # 'acquirer_id': paypal_id, + # 'currency_id': currency_id, + # 'reference': 'test_reference', + # 'paypal_txn_id': '61E67681CH3238416', + # }, context=context + # ) + # res = self.payment_transaction.validate_paypal_notification( + # cr, uid, + # 'http://localhost/payment?mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name=Test+User¬ify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00') + # print res + + # # user pays using Paypal + # resp = self.payment_transaction.create_paypal_command( + # cr, uid, cmd='_xclick', parameters={ + # 'business': 'tdelavallee-facilitator@gmail.com', + # 'amount': 50, + # 'item_name': 'test_item', + # 'quantity': 1, + # 'currency_code': 'USD', + # 'return': 'http://www.example.com', + # }) + # print resp + # print resp.url + # print resp.text + + # self.payment_transaction.validate(cr, uid, [tx_id], context=context) diff --git a/addons/payment_acquirer/views/paypal.xml b/addons/payment_acquirer_paypal/views/paypal.xml similarity index 100% rename from addons/payment_acquirer/views/paypal.xml rename to addons/payment_acquirer_paypal/views/paypal.xml diff --git a/addons/website_payment/__openerp__.py b/addons/website_payment/__openerp__.py index 4368363c312..05fe44a9260 100644 --- a/addons/website_payment/__openerp__.py +++ b/addons/website_payment/__openerp__.py @@ -27,7 +27,7 @@ 'description': """ """, 'author': 'OpenERP SA', - 'depends': ['website', 'payment_acquirer'], + 'depends': ['website', 'payment_acquirer', 'payment_acquirer_ogone', 'payment_acquirer_paypal'], 'data': [ 'views/website_payment_templates.xml', ], diff --git a/addons/website_payment/views/website_payment_templates.xml b/addons/website_payment/views/website_payment_templates.xml index 03b045bf716..924be2ed848 100644 --- a/addons/website_payment/views/website_payment_templates.xml +++ b/addons/website_payment/views/website_payment_templates.xml @@ -1,42 +1,51 @@ - + - + + + Paypal (Test) + /payment/paypal/test + + 50 + + + + + Ogone (Test) + /payment/ogone/test + + 50 + + - - + -