[REF] payment: moved paypal and ogone stuff into their dedicated modules.

Added payment_acquirer_paypal and .._ogone modules. Those modules hold
the model / data / controllers related to the specific acquirer.

Also updated website_payment, to use website.menu instead of custom change
in header, as menus are now editable.

bzr revid: tde@openerp.com-20131107180444-bbzobquqq9o6pctv
This commit is contained in:
Thibault Delavallée
2013-11-07 19:04:44 +01:00
parent 35619dfe12
commit b2ea74e4e6
29 changed files with 510 additions and 204 deletions
-4
View File
@@ -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,
+2 -68
View File
@@ -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/<int:acquirer_id>/ipn/'
@website.route('/payment/paypal/<int:acquirer_id>/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
@@ -20,5 +20,3 @@
##############################################################################
import payment_acquirer
import paypal
import ogone
+1 -7
View File
@@ -19,10 +19,4 @@
#
##############################################################################
from . import test_payment_acquirer
checks = [
test_payment_acquirer,
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
import common
+2 -2
View File
@@ -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')
+23
View File
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import models
import controllers
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}
@@ -0,0 +1 @@
import main
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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 ''
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import ogone
@@ -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
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_ogone
checks = [
test_ogone,
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -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&notify_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&notify_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(
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import models
import controllers
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}
@@ -0,0 +1 @@
import main
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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/<int:acquirer_id>/ipn/'
@website.route('/payment/paypal/<int:acquirer_id>/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 ''
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import paypal
@@ -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
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_paypal
checks = [
test_paypal,
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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&notify_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&notify_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)
+1 -1
View File
@@ -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',
],
@@ -1,42 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Layout add nav and footer -->
<template id="header_footer_custom" inherit_id="website.layout">
<xpath expr="//header//ul[@id='top_menu']/li[@name='contactus']" position="before">
<li><a t-attf-href="/payment/paypal/test">Test (Paypal)</a></li>
</xpath>
<xpath expr="//header//ul[@id='top_menu']/li[@name='contactus']" position="before">
<li><a t-attf-href="/payment/ogone/test">Test (Ogone)</a></li>
</xpath>
</template>
<data noupdate="0">
<record id="menu_paypal_test" model="website.menu">
<field name="name">Paypal (Test)</field>
<field name="url">/payment/paypal/test</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">50</field>
</record>
</data>
<data noupdate="0">
<record id="menu_paypal_ogone" model="website.menu">
<field name="name">Ogone (Test)</field>
<field name="url">/payment/ogone/test</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">50</field>
</record>
</data>
<!-- Page -->
<template id="index_paypal" name="Paypal (Test)" page="True">
<t t-call="website.layout">
<div id="wrap">
<div class="container mt16 js_website_blog">
<div class="row">
Paypal payment
<t t-raw="acquirer_form"/>
<data>
<template id="index_paypal" name="Paypal (Test)" page="True">
<t t-call="website.layout">
<div id="wrap">
<div class="container mt16 js_website_blog">
<div class="row">
Paypal payment
<t t-raw="acquirer_form"/>
</div>
</div>
</div>
</div>
</t>
</template>
</t>
</template>
<template id="index_ogone" name="Ogone (Test)" page="True">
<t t-call="website.layout">
<div id="wrap">
<div class="container mt16 js_website_blog">
<div class="row">
Ogone payment
<t t-raw="acquirer_form"/>
<template id="index_ogone" name="Ogone (Test)" page="True">
<t t-call="website.layout">
<div id="wrap">
<div class="container mt16 js_website_blog">
<div class="row">
Ogone payment
<t t-raw="acquirer_form"/>
</div>
</div>
</div>
</div>
</t>
</template>
</t>
</template>
</data>
</data>
</openerp>