Merge lp:~openerp-dev/openobject-addons/trunk-payment-buckaroo-dka into lp:openobject-addons
- trunk-payment-buckaroo-dka
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~openerp-dev/openobject-addons/trunk-payment-buckaroo-dka |
Merge into: | lp:openobject-addons |
Diff against target: |
744 lines (+579/-19) 15 files modified
payment/models/res_config.py (+3/-0) payment/views/res_config_view.xml (+4/-0) payment_buckaroo/__init__.py (+23/-0) payment_buckaroo/__openerp__.py (+17/-0) payment_buckaroo/controllers/__init__.py (+3/-0) payment_buckaroo/controllers/main.py (+38/-0) payment_buckaroo/data/buckaroo.xml (+18/-0) payment_buckaroo/models/__init__.py (+3/-0) payment_buckaroo/models/buckaroo.py (+191/-0) payment_buckaroo/tests/__init__.py (+7/-0) payment_buckaroo/tests/test_buckaroo.py (+178/-0) payment_buckaroo/views/buckaroo.xml (+34/-0) payment_buckaroo/views/payment_acquirer.xml (+35/-0) website_sale/controllers/main.py (+15/-19) website_sale/static/src/js/website_sale_payment.js (+10/-0) |
To merge this branch: | bzr merge lp:~openerp-dev/openobject-addons/trunk-payment-buckaroo-dka |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Thibault Delavallée (OpenERP) (community) | technical | Needs Fixing | |
Review via email: mp+208589@code.launchpad.net |
Commit message
Description of the change
[ADD] New payment acquirer: Buckaroo.
- 9087. By Niko (OpenERP)
-
[IMP] Add some video to manisfest ( website, website_blog, website_event, website_ecommerce)
- 9184. By Darshan Kalola(OpenERP)
-
[IMP]remove unnecessary code.
- 9185. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9186. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9187. By Darshan Kalola(OpenERP)
-
[ADD]payment_
buckaroo: added websitekey. - 9188. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: added secretkey and improved digital signature. - 9189. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: added buckaroo_return method in controller to handel return url and added _buckaroo_ form_get_ tx_from_ data method in payment transaction. - 9190. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9191. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: improved method name. - 9192. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: added _buckaroo_ form_validate method. - 9193. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: added _buckaroo_ form_get_ invalid_ parameters method. - 9194. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: Removed unnecessary field. - 9195. By Darshan Kalola(OpenERP)
-
[IMP]website_sale : improved payment_transaction method to send post request to payment getway and added exception url and reject url in buckaroo parameter and removed unnecessary code.
- 9196. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9197. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9198. By Darshan Kalola(OpenERP)
-
[IMP]removed unnecessary code and typo.
- 9199. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: improved code and image. - 9200. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9201. By Darshan Kalola(OpenERP)
-
[IMP]improved typo.
- 9202. By Darshan Kalola(OpenERP)
-
[IMP]pyment_
buckaroo: inherited selection to add ('buckaroo' ,'Buckaroo' )in provider list , changed code accordinglly and rename file. - 9203. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9204. By Darshan Kalola(OpenERP)
-
[IMP]pyament_
buckaroo: added separate variable for buckarro status code. - 9205. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9206. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9207. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9208. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9209. By Darshan Kalola(OpenERP)
-
[IMP]verify the digital signature comming from buckaroo.
- 9210. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9211. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9212. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: rename fields name env to environment.
- 9213. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: added test case to check the module correctly work or not. - 9214. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9215. By Darshan Kalola(OpenERP)
-
[IMP]disabled test case.
- 9216. By Darshan Kalola(OpenERP)
-
[IMP]improved spacing.
- 9217. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9218. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9219. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9220. By Thibault Delavallée (OpenERP)
-
[MERGE] Sync with upstream (trunk)
Thibault Delavallée (OpenERP) (tde-openerp) wrote : | # |
Hello,
Some remarks :
- remove credentials from data now that the branch is about to be merged (set dummy / dummy)
- lint the module (some unused imports, space errors, ...)
One thing to add :
- management of tx_values[
Best regards,
Thibault.
- 9221. By Darshan Kalola(OpenERP)
-
[IMP]remove credential information and remove unneccessary import.
- 9222. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: added custome variable for return_url. - 9223. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9224. By Darshan Kalola(OpenERP)
-
[IMP]remove unnecessary import.
- 9225. By Thibault Delavallée (OpenERP)
-
[MERGE] Sync with trunk
- 9226. By Thibault Delavallée (OpenERP)
-
[CLEAN] payment_buckaroo: cleaned a bit the file for the tests, according
to new tests specifications in post-saas-4. - 9227. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: improved digital signature in test case. - 9228. By Thibault Delavallée (OpenERP)
-
[MERGE] Sync with trunk
- 9229. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9230. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9231. By Darshan Kalola(OpenERP)
-
[MERGE]merged lp:~openerp-dev/openobject-addons/trunk-ecommerce-post-tde and removed unnecessary code which handle the post request as got better solution in trunk-ecommerce
-post-tde branch. - 9232. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk and resolve conflicts from website_sale controller/ in payment_transaction method.
- 9233. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
Unmerged revisions
- 9233. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9232. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk and resolve conflicts from website_sale controller/ in payment_transaction method.
- 9231. By Darshan Kalola(OpenERP)
-
[MERGE]merged lp:~openerp-dev/openobject-addons/trunk-ecommerce-post-tde and removed unnecessary code which handle the post request as got better solution in trunk-ecommerce
-post-tde branch. - 9230. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9229. By Darshan Kalola(OpenERP)
-
[MERGE]sync with trunk.
- 9228. By Thibault Delavallée (OpenERP)
-
[MERGE] Sync with trunk
- 9227. By Darshan Kalola(OpenERP)
-
[IMP]payment_
buckaroo: improved digital signature in test case. - 9226. By Thibault Delavallée (OpenERP)
-
[CLEAN] payment_buckaroo: cleaned a bit the file for the tests, according
to new tests specifications in post-saas-4. - 9225. By Thibault Delavallée (OpenERP)
-
[MERGE] Sync with trunk
- 9224. By Darshan Kalola(OpenERP)
-
[IMP]remove unnecessary import.
Preview Diff
1 | === modified file 'payment/models/res_config.py' | |||
2 | --- payment/models/res_config.py 2014-03-05 16:37:37 +0000 | |||
3 | +++ payment/models/res_config.py 2014-05-21 05:25:49 +0000 | |||
4 | @@ -16,4 +16,7 @@ | |||
5 | 16 | 'module_payment_adyen': fields.boolean( | 16 | 'module_payment_adyen': fields.boolean( |
6 | 17 | 'Manage Payments Using Adyen', | 17 | 'Manage Payments Using Adyen', |
7 | 18 | help='-It installs the module payment_adyen.'), | 18 | help='-It installs the module payment_adyen.'), |
8 | 19 | 'module_payment_buckaroo': fields.boolean( | ||
9 | 20 | 'Manage Payments Using Buckaroo', | ||
10 | 21 | help='-It installs the module payment_buckaroo.'), | ||
11 | 19 | } | 22 | } |
12 | 20 | 23 | ||
13 | === modified file 'payment/views/res_config_view.xml' | |||
14 | --- payment/views/res_config_view.xml 2014-01-23 15:01:35 +0000 | |||
15 | +++ payment/views/res_config_view.xml 2014-05-21 05:25:49 +0000 | |||
16 | @@ -20,6 +20,10 @@ | |||
17 | 20 | <field name="module_payment_adyen" class="oe_inline"/> | 20 | <field name="module_payment_adyen" class="oe_inline"/> |
18 | 21 | <label for="module_payment_adyen"/> | 21 | <label for="module_payment_adyen"/> |
19 | 22 | </div> | 22 | </div> |
20 | 23 | <div> | ||
21 | 24 | <field name="module_payment_buckaroo" class="oe_inline"/> | ||
22 | 25 | <label for="module_payment_buckaroo"/> | ||
23 | 26 | </div> | ||
24 | 23 | </xpath> | 27 | </xpath> |
25 | 24 | </field> | 28 | </field> |
26 | 25 | </record> | 29 | </record> |
27 | 26 | 30 | ||
28 | === added directory 'payment_buckaroo' | |||
29 | === added file 'payment_buckaroo/__init__.py' | |||
30 | --- payment_buckaroo/__init__.py 1970-01-01 00:00:00 +0000 | |||
31 | +++ payment_buckaroo/__init__.py 2014-05-21 05:25:49 +0000 | |||
32 | @@ -0,0 +1,23 @@ | |||
33 | 1 | # -*- coding: utf-8 -*- | ||
34 | 2 | ############################################################################## | ||
35 | 3 | # | ||
36 | 4 | # OpenERP, Open Source Management Solution | ||
37 | 5 | # Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>). | ||
38 | 6 | # | ||
39 | 7 | # This program is free software: you can redistribute it and/or modify | ||
40 | 8 | # it under the terms of the GNU Affero General Public License as | ||
41 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
42 | 10 | # License, or (at your option) any later version. | ||
43 | 11 | # | ||
44 | 12 | # This program is distributed in the hope that it will be useful, | ||
45 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
46 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
47 | 15 | # GNU Affero General Public License for more details. | ||
48 | 16 | # | ||
49 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
50 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
51 | 19 | # | ||
52 | 20 | ############################################################################## | ||
53 | 21 | |||
54 | 22 | import models | ||
55 | 23 | import controllers | ||
56 | 0 | 24 | ||
57 | === added file 'payment_buckaroo/__openerp__.py' | |||
58 | --- payment_buckaroo/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
59 | +++ payment_buckaroo/__openerp__.py 2014-05-21 05:25:49 +0000 | |||
60 | @@ -0,0 +1,17 @@ | |||
61 | 1 | # -*- coding: utf-8 -*- | ||
62 | 2 | |||
63 | 3 | { | ||
64 | 4 | 'name': 'Payment Buckaroo', | ||
65 | 5 | 'category': 'Hidden', | ||
66 | 6 | 'summary': 'Payment Acquirer: Buckaroo Implementation', | ||
67 | 7 | 'version': '1.0', | ||
68 | 8 | 'description': """Payment Buckaroo""", | ||
69 | 9 | 'author': 'OpenERP SA', | ||
70 | 10 | 'depends': ['payment'], | ||
71 | 11 | 'data': [ | ||
72 | 12 | 'views/buckaroo.xml', | ||
73 | 13 | 'views/payment_acquirer.xml', | ||
74 | 14 | 'data/buckaroo.xml', | ||
75 | 15 | ], | ||
76 | 16 | 'installable': True, | ||
77 | 17 | } | ||
78 | 0 | 18 | ||
79 | === added directory 'payment_buckaroo/controllers' | |||
80 | === added file 'payment_buckaroo/controllers/__init__.py' | |||
81 | --- payment_buckaroo/controllers/__init__.py 1970-01-01 00:00:00 +0000 | |||
82 | +++ payment_buckaroo/controllers/__init__.py 2014-05-21 05:25:49 +0000 | |||
83 | @@ -0,0 +1,3 @@ | |||
84 | 1 | # -*- coding: utf-8 -*- | ||
85 | 2 | |||
86 | 3 | import main | ||
87 | 0 | 4 | ||
88 | === added file 'payment_buckaroo/controllers/main.py' | |||
89 | --- payment_buckaroo/controllers/main.py 1970-01-01 00:00:00 +0000 | |||
90 | +++ payment_buckaroo/controllers/main.py 2014-05-21 05:25:49 +0000 | |||
91 | @@ -0,0 +1,38 @@ | |||
92 | 1 | # -*- coding: utf-8 -*- | ||
93 | 2 | try: | ||
94 | 3 | import simplejson as json | ||
95 | 4 | except ImportError: | ||
96 | 5 | import json | ||
97 | 6 | |||
98 | 7 | import logging | ||
99 | 8 | import pprint | ||
100 | 9 | import werkzeug | ||
101 | 10 | |||
102 | 11 | from openerp import http, SUPERUSER_ID | ||
103 | 12 | from openerp.http import request | ||
104 | 13 | |||
105 | 14 | _logger = logging.getLogger(__name__) | ||
106 | 15 | |||
107 | 16 | |||
108 | 17 | class BuckarooController(http.Controller): | ||
109 | 18 | _return_url = '/payment/buckaroo/return' | ||
110 | 19 | _cancel_url = '/payment/buckaroo/cancel' | ||
111 | 20 | _exception_url = '/payment/buckaroo/error' | ||
112 | 21 | _reject_url = '/payment/buckaroo/reject' | ||
113 | 22 | |||
114 | 23 | @http.route([ | ||
115 | 24 | '/payment/buckaroo/return', | ||
116 | 25 | '/payment/buckaroo/cancel', | ||
117 | 26 | '/payment/buckaroo/error', | ||
118 | 27 | '/payment/buckaroo/reject', | ||
119 | 28 | ], type='http', auth='none') | ||
120 | 29 | def buckaroo_return(self, **post): | ||
121 | 30 | """ Buckaroo.""" | ||
122 | 31 | _logger.info('Buckaroo: entering form_feedback with post data %s', pprint.pformat(post)) # debug | ||
123 | 32 | request.registry['payment.transaction'].form_feedback(request.cr, SUPERUSER_ID, post, 'buckaroo', context=request.context) | ||
124 | 33 | return_url = post.pop('return_url', '') | ||
125 | 34 | if not return_url: | ||
126 | 35 | data ='' + post.pop('ADD_RETURNDATA', '{}').replace("'", "\"") | ||
127 | 36 | custom = json.loads(data) | ||
128 | 37 | return_url = custom.pop('return_url', '/') | ||
129 | 38 | return werkzeug.utils.redirect(return_url) | ||
130 | 0 | 39 | ||
131 | === added directory 'payment_buckaroo/data' | |||
132 | === added file 'payment_buckaroo/data/buckaroo.xml' | |||
133 | --- payment_buckaroo/data/buckaroo.xml 1970-01-01 00:00:00 +0000 | |||
134 | +++ payment_buckaroo/data/buckaroo.xml 2014-05-21 05:25:49 +0000 | |||
135 | @@ -0,0 +1,18 @@ | |||
136 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
137 | 2 | <openerp> | ||
138 | 3 | <data noupdate="1"> | ||
139 | 4 | |||
140 | 5 | <record id="payment_acquirer_buckaroo" model="payment.acquirer"> | ||
141 | 6 | <field name="name">Buckarro</field> | ||
142 | 7 | <field name="provider">buckaroo</field> | ||
143 | 8 | <field name="company_id" ref="base.main_company"/> | ||
144 | 9 | <field name="view_template_id" ref="buckaroo_acquirer_button"/> | ||
145 | 10 | <field name="environment">test</field> | ||
146 | 11 | <field name="pre_msg"><![CDATA[ | ||
147 | 12 | <p>You will be redirected to the Buckaroo website after cliking on the payment button.</p>]]></field> | ||
148 | 13 | <field name="brq_websitekey">dummy</field> | ||
149 | 14 | <field name="brq_secretkey">dummy</field> | ||
150 | 15 | </record> | ||
151 | 16 | |||
152 | 17 | </data> | ||
153 | 18 | </openerp> | ||
154 | 0 | 19 | ||
155 | === added directory 'payment_buckaroo/models' | |||
156 | === added file 'payment_buckaroo/models/__init__.py' | |||
157 | --- payment_buckaroo/models/__init__.py 1970-01-01 00:00:00 +0000 | |||
158 | +++ payment_buckaroo/models/__init__.py 2014-05-21 05:25:49 +0000 | |||
159 | @@ -0,0 +1,3 @@ | |||
160 | 1 | # -*- coding: utf-8 -*- | ||
161 | 2 | |||
162 | 3 | import buckaroo | ||
163 | 0 | 4 | ||
164 | === added file 'payment_buckaroo/models/buckaroo.py' | |||
165 | --- payment_buckaroo/models/buckaroo.py 1970-01-01 00:00:00 +0000 | |||
166 | +++ payment_buckaroo/models/buckaroo.py 2014-05-21 05:25:49 +0000 | |||
167 | @@ -0,0 +1,191 @@ | |||
168 | 1 | # -*- coding: utf-'8' "-*-" | ||
169 | 2 | from hashlib import sha1 | ||
170 | 3 | import logging | ||
171 | 4 | import urlparse | ||
172 | 5 | |||
173 | 6 | from openerp.addons.payment.models.payment_acquirer import ValidationError | ||
174 | 7 | from openerp.addons.payment_buckaroo.controllers.main import BuckarooController | ||
175 | 8 | from openerp.osv import osv, fields | ||
176 | 9 | from openerp.tools.float_utils import float_compare | ||
177 | 10 | |||
178 | 11 | _logger = logging.getLogger(__name__) | ||
179 | 12 | |||
180 | 13 | |||
181 | 14 | class AcquirerBuckaroo(osv.Model): | ||
182 | 15 | _inherit = 'payment.acquirer' | ||
183 | 16 | |||
184 | 17 | def _get_buckaroo_urls(self, cr, uid, environment, context=None): | ||
185 | 18 | """ Buckaroo URLs | ||
186 | 19 | """ | ||
187 | 20 | if environment == 'prod': | ||
188 | 21 | return { | ||
189 | 22 | 'buckaroo_form_url': 'https://checkout.buckaroo.nl/html/', | ||
190 | 23 | } | ||
191 | 24 | else: | ||
192 | 25 | return { | ||
193 | 26 | 'buckaroo_form_url': 'https://testcheckout.buckaroo.nl/html/', | ||
194 | 27 | } | ||
195 | 28 | |||
196 | 29 | def _get_providers(self, cr, uid, context=None): | ||
197 | 30 | providers = super(AcquirerBuckaroo, self)._get_providers(cr, uid, context=context) | ||
198 | 31 | providers.append(['buckaroo', 'Buckaroo']) | ||
199 | 32 | return providers | ||
200 | 33 | |||
201 | 34 | _columns = { | ||
202 | 35 | 'brq_websitekey': fields.char('WebsiteKey', required_if_provider='buckaroo'), | ||
203 | 36 | 'brq_secretkey': fields.char('SecretKey', required_if_provider='buckaroo'), | ||
204 | 37 | } | ||
205 | 38 | |||
206 | 39 | def _buckaroo_generate_digital_sign(self, acquirer, inout, values): | ||
207 | 40 | """ Generate the shasign for incoming or outgoing communications. | ||
208 | 41 | |||
209 | 42 | :param browse acquirer: the payment.acquirer browse record. It should | ||
210 | 43 | have a shakey in shaky out | ||
211 | 44 | :param string inout: 'in' (openerp contacting buckaroo) or 'out' (buckaroo | ||
212 | 45 | contacting openerp). | ||
213 | 46 | :param dict values: transaction values | ||
214 | 47 | |||
215 | 48 | :return string: shasign | ||
216 | 49 | """ | ||
217 | 50 | assert inout in ('in', 'out') | ||
218 | 51 | assert acquirer.provider == 'buckaroo' | ||
219 | 52 | |||
220 | 53 | keys = "add_returndata Brq_amount Brq_culture Brq_currency Brq_invoicenumber Brq_return Brq_returncancel Brq_returnerror Brq_returnreject brq_test Brq_websitekey".split() | ||
221 | 54 | |||
222 | 55 | def get_value(key): | ||
223 | 56 | if values.get(key): | ||
224 | 57 | return values[key] | ||
225 | 58 | return '' | ||
226 | 59 | |||
227 | 60 | if inout == 'out': | ||
228 | 61 | if 'BRQ_SIGNATURE' in values: | ||
229 | 62 | del values['BRQ_SIGNATURE'] | ||
230 | 63 | items = sorted((k.upper(), v) for k, v in values.items()) | ||
231 | 64 | sign = ''.join('%s=%s' % (k, v) for k, v in items) | ||
232 | 65 | else: | ||
233 | 66 | sign = ''.join('%s=%s' % (k,get_value(k)) for k in keys) | ||
234 | 67 | #Add the pre-shared secret key at the end of the signature | ||
235 | 68 | sign = sign + acquirer.brq_secretkey | ||
236 | 69 | if isinstance(sign, str): | ||
237 | 70 | sign = urlparse.parse_qsl(sign) | ||
238 | 71 | shasign = sha1(sign).hexdigest() | ||
239 | 72 | return shasign | ||
240 | 73 | |||
241 | 74 | |||
242 | 75 | def buckaroo_form_generate_values(self, cr, uid, id, partner_values, tx_values, context=None): | ||
243 | 76 | base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') | ||
244 | 77 | acquirer = self.browse(cr, uid, id, context=context) | ||
245 | 78 | buckaroo_tx_values = dict(tx_values) | ||
246 | 79 | buckaroo_tx_values.update({ | ||
247 | 80 | 'Brq_websitekey': acquirer.brq_websitekey, | ||
248 | 81 | 'Brq_amount': tx_values['amount'], | ||
249 | 82 | 'Brq_currency': tx_values['currency'] and tx_values['currency'].name or '', | ||
250 | 83 | 'Brq_invoicenumber': tx_values['reference'], | ||
251 | 84 | 'brq_test' : True, | ||
252 | 85 | 'Brq_return': '%s' % urlparse.urljoin(base_url, BuckarooController._return_url), | ||
253 | 86 | 'Brq_returncancel': '%s' % urlparse.urljoin(base_url, BuckarooController._cancel_url), | ||
254 | 87 | 'Brq_returnerror': '%s' % urlparse.urljoin(base_url, BuckarooController._exception_url), | ||
255 | 88 | 'Brq_returnreject': '%s' % urlparse.urljoin(base_url, BuckarooController._reject_url), | ||
256 | 89 | 'Brq_culture': 'en-US', | ||
257 | 90 | }) | ||
258 | 91 | if buckaroo_tx_values.get('return_url'): | ||
259 | 92 | buckaroo_tx_values['add_returndata'] = {'return_url': '%s' % buckaroo_tx_values.pop('return_url')} | ||
260 | 93 | else: | ||
261 | 94 | buckaroo_tx_values['add_returndata'] = '' | ||
262 | 95 | buckaroo_tx_values['Brq_signature'] = self._buckaroo_generate_digital_sign(acquirer, 'in', buckaroo_tx_values) | ||
263 | 96 | return partner_values, buckaroo_tx_values | ||
264 | 97 | |||
265 | 98 | def buckaroo_get_form_action_url(self, cr, uid, id, context=None): | ||
266 | 99 | acquirer = self.browse(cr, uid, id, context=context) | ||
267 | 100 | return self._get_buckaroo_urls(cr, uid, acquirer.environment, context=context)['buckaroo_form_url'] | ||
268 | 101 | |||
269 | 102 | class TxBuckaroo(osv.Model): | ||
270 | 103 | _inherit = 'payment.transaction' | ||
271 | 104 | |||
272 | 105 | # buckaroo status | ||
273 | 106 | _buckaroo_valid_tx_status = [190] | ||
274 | 107 | _buckaroo_pending_tx_status = [790, 791, 792, 793] | ||
275 | 108 | _buckaroo_cancel_tx_status = [890, 891] | ||
276 | 109 | _buckaroo_error_tx_status = [490, 491, 492] | ||
277 | 110 | _buckaroo_reject_tx_status = [690] | ||
278 | 111 | |||
279 | 112 | _columns = { | ||
280 | 113 | 'buckaroo_txnid': fields.char('Transaction ID'), | ||
281 | 114 | } | ||
282 | 115 | |||
283 | 116 | |||
284 | 117 | # -------------------------------------------------- | ||
285 | 118 | # FORM RELATED METHODS | ||
286 | 119 | # -------------------------------------------------- | ||
287 | 120 | |||
288 | 121 | def _buckaroo_form_get_tx_from_data(self, cr, uid, data, context=None): | ||
289 | 122 | """ Given a data dict coming from buckaroo, verify it and find the related | ||
290 | 123 | transaction record. """ | ||
291 | 124 | reference, pay_id, shasign = data.get('BRQ_INVOICENUMBER'), data.get('BRQ_PAYMENT'), data.get('BRQ_SIGNATURE') | ||
292 | 125 | if not reference or not pay_id or not shasign: | ||
293 | 126 | error_msg = 'Buckaroo: received data with missing reference (%s) or pay_id (%s) or shashign (%s)' % (reference, pay_id, shasign) | ||
294 | 127 | _logger.error(error_msg) | ||
295 | 128 | raise ValidationError(error_msg) | ||
296 | 129 | |||
297 | 130 | tx_ids = self.search(cr, uid, [('reference', '=', reference)], context=context) | ||
298 | 131 | if not tx_ids or len(tx_ids) > 1: | ||
299 | 132 | error_msg = 'Buckaroo: received data for reference %s' % (reference) | ||
300 | 133 | if not tx_ids: | ||
301 | 134 | error_msg += '; no order found' | ||
302 | 135 | else: | ||
303 | 136 | error_msg += '; multiple order found' | ||
304 | 137 | _logger.error(error_msg) | ||
305 | 138 | raise ValidationError(error_msg) | ||
306 | 139 | tx = self.pool['payment.transaction'].browse(cr, uid, tx_ids[0], context=context) | ||
307 | 140 | |||
308 | 141 | #verify shasign | ||
309 | 142 | shasign_check = self.pool['payment.acquirer']._buckaroo_generate_digital_sign(tx.acquirer_id, 'out' ,data) | ||
310 | 143 | if shasign_check.upper() != shasign.upper(): | ||
311 | 144 | error_msg = 'Buckaroo: invalid shasign, received %s, computed %s, for data %s' % (shasign, shasign_check, data) | ||
312 | 145 | _logger.error(error_msg) | ||
313 | 146 | raise ValidationError(error_msg) | ||
314 | 147 | |||
315 | 148 | return tx | ||
316 | 149 | |||
317 | 150 | def _buckaroo_form_get_invalid_parameters(self, cr, uid, tx, data, context=None): | ||
318 | 151 | invalid_parameters = [] | ||
319 | 152 | |||
320 | 153 | if tx.acquirer_reference and data.get('BRQ_TRANSACTIONS') != tx.acquirer_reference: | ||
321 | 154 | invalid_parameters.append(('Transaction Id', data.get('BRQ_TRANSACTIONS'), tx.acquirer_reference)) | ||
322 | 155 | # check what is buyed | ||
323 | 156 | if float_compare(float(data.get('BRQ_AMOUNT', '0.0')), tx.amount, 2) != 0: | ||
324 | 157 | invalid_parameters.append(('Amount', data.get('BRQ_AMOUNT'), '%.2f' % tx.amount)) | ||
325 | 158 | if data.get('BRQ_CURRENCY') != tx.currency_id.name: | ||
326 | 159 | invalid_parameters.append(('Currency', data.get('BRQ_CURRENCY'), tx.currency_id.name)) | ||
327 | 160 | |||
328 | 161 | return invalid_parameters | ||
329 | 162 | |||
330 | 163 | def _buckaroo_form_validate(self, cr, uid, tx, data, context=None): | ||
331 | 164 | status_code = int(data.get('BRQ_STATUSCODE','0')) | ||
332 | 165 | if status_code in self._buckaroo_valid_tx_status: | ||
333 | 166 | tx.write({ | ||
334 | 167 | 'state': 'done', | ||
335 | 168 | 'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'), | ||
336 | 169 | }) | ||
337 | 170 | return True | ||
338 | 171 | elif status_code in self._buckaroo_pending_tx_status: | ||
339 | 172 | tx.write({ | ||
340 | 173 | 'state': 'pending', | ||
341 | 174 | 'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'), | ||
342 | 175 | }) | ||
343 | 176 | return True | ||
344 | 177 | elif status_code in self._buckaroo_cancel_tx_status: | ||
345 | 178 | tx.write({ | ||
346 | 179 | 'state': 'cancel', | ||
347 | 180 | 'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'), | ||
348 | 181 | }) | ||
349 | 182 | return True | ||
350 | 183 | else: | ||
351 | 184 | error = 'Buckaroo: feedback error' | ||
352 | 185 | _logger.info(error) | ||
353 | 186 | tx.write({ | ||
354 | 187 | 'state': 'error', | ||
355 | 188 | 'state_message': error, | ||
356 | 189 | 'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'), | ||
357 | 190 | }) | ||
358 | 191 | return False | ||
359 | 0 | 192 | ||
360 | === added directory 'payment_buckaroo/static' | |||
361 | === added directory 'payment_buckaroo/static/description' | |||
362 | === added file 'payment_buckaroo/static/description/icon.png' | |||
363 | 1 | Binary files payment_buckaroo/static/description/icon.png 1970-01-01 00:00:00 +0000 and payment_buckaroo/static/description/icon.png 2014-05-21 05:25:49 +0000 differ | 193 | Binary files payment_buckaroo/static/description/icon.png 1970-01-01 00:00:00 +0000 and payment_buckaroo/static/description/icon.png 2014-05-21 05:25:49 +0000 differ |
364 | === added directory 'payment_buckaroo/static/src' | |||
365 | === added directory 'payment_buckaroo/static/src/img' | |||
366 | === added file 'payment_buckaroo/static/src/img/buckaroo_icon.png' | |||
367 | 2 | Binary files payment_buckaroo/static/src/img/buckaroo_icon.png 1970-01-01 00:00:00 +0000 and payment_buckaroo/static/src/img/buckaroo_icon.png 2014-05-21 05:25:49 +0000 differ | 194 | Binary files payment_buckaroo/static/src/img/buckaroo_icon.png 1970-01-01 00:00:00 +0000 and payment_buckaroo/static/src/img/buckaroo_icon.png 2014-05-21 05:25:49 +0000 differ |
368 | === added file 'payment_buckaroo/static/src/img/logo.png' | |||
369 | 3 | Binary files payment_buckaroo/static/src/img/logo.png 1970-01-01 00:00:00 +0000 and payment_buckaroo/static/src/img/logo.png 2014-05-21 05:25:49 +0000 differ | 195 | Binary files payment_buckaroo/static/src/img/logo.png 1970-01-01 00:00:00 +0000 and payment_buckaroo/static/src/img/logo.png 2014-05-21 05:25:49 +0000 differ |
370 | === added directory 'payment_buckaroo/tests' | |||
371 | === added file 'payment_buckaroo/tests/__init__.py' | |||
372 | --- payment_buckaroo/tests/__init__.py 1970-01-01 00:00:00 +0000 | |||
373 | +++ payment_buckaroo/tests/__init__.py 2014-05-21 05:25:49 +0000 | |||
374 | @@ -0,0 +1,7 @@ | |||
375 | 1 | # -*- coding: utf-8 -*- | ||
376 | 2 | |||
377 | 3 | from openerp.addons.payment_buckaroo.tests import test_buckaroo | ||
378 | 4 | |||
379 | 5 | checks = [ | ||
380 | 6 | test_buckaroo, | ||
381 | 7 | ] | ||
382 | 0 | 8 | ||
383 | === added file 'payment_buckaroo/tests/test_buckaroo.py' | |||
384 | --- payment_buckaroo/tests/test_buckaroo.py 1970-01-01 00:00:00 +0000 | |||
385 | +++ payment_buckaroo/tests/test_buckaroo.py 2014-05-21 05:25:49 +0000 | |||
386 | @@ -0,0 +1,178 @@ | |||
387 | 1 | # -*- coding: utf-8 -*- | ||
388 | 2 | |||
389 | 3 | from lxml import objectify | ||
390 | 4 | import urlparse | ||
391 | 5 | |||
392 | 6 | import openerp | ||
393 | 7 | from openerp.addons.payment.models.payment_acquirer import ValidationError | ||
394 | 8 | from openerp.addons.payment.tests.common import PaymentAcquirerCommon | ||
395 | 9 | from openerp.addons.payment_buckaroo.controllers.main import BuckarooController | ||
396 | 10 | from openerp.tools import mute_logger | ||
397 | 11 | |||
398 | 12 | |||
399 | 13 | @openerp.tests.common.at_install(False) | ||
400 | 14 | @openerp.tests.common.post_install(False) | ||
401 | 15 | class BuckarooCommon(PaymentAcquirerCommon): | ||
402 | 16 | |||
403 | 17 | def setUp(self): | ||
404 | 18 | super(BuckarooCommon, self).setUp() | ||
405 | 19 | cr, uid = self.cr, self.uid | ||
406 | 20 | self.base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url') | ||
407 | 21 | |||
408 | 22 | # get the buckaroo account | ||
409 | 23 | model, self.buckaroo_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_buckaroo', 'payment_acquirer_buckaroo') | ||
410 | 24 | |||
411 | 25 | |||
412 | 26 | @openerp.tests.common.at_install(False) | ||
413 | 27 | @openerp.tests.common.post_install(False) | ||
414 | 28 | class BuckarooForm(BuckarooCommon): | ||
415 | 29 | |||
416 | 30 | def test_10_Buckaroo_form_render(self): | ||
417 | 31 | cr, uid, context = self.cr, self.uid, {} | ||
418 | 32 | # be sure not to do stupid things | ||
419 | 33 | buckaroo = self.payment_acquirer.browse(self.cr, self.uid, self.buckaroo_id, None) | ||
420 | 34 | self.assertEqual(buckaroo.environment, 'test', 'test without test environment') | ||
421 | 35 | |||
422 | 36 | # ---------------------------------------- | ||
423 | 37 | # Test: button direct rendering | ||
424 | 38 | # ---------------------------------------- | ||
425 | 39 | |||
426 | 40 | form_values = { | ||
427 | 41 | 'add_returndata': None, | ||
428 | 42 | 'Brq_websitekey': buckaroo.brq_websitekey, | ||
429 | 43 | 'Brq_amount': '2240.0', | ||
430 | 44 | 'Brq_currency': 'EUR', | ||
431 | 45 | 'Brq_invoicenumber': 'SO004', | ||
432 | 46 | 'Brq_signature': '1b8c10074c622d965272a91a9e88b5b3777d2474', # update me | ||
433 | 47 | 'brq_test': 'True', | ||
434 | 48 | 'Brq_return': '%s' % urlparse.urljoin(self.base_url, BuckarooController._return_url), | ||
435 | 49 | 'Brq_returncancel': '%s' % urlparse.urljoin(self.base_url, BuckarooController._cancel_url), | ||
436 | 50 | 'Brq_returnerror': '%s' % urlparse.urljoin(self.base_url, BuckarooController._exception_url), | ||
437 | 51 | 'Brq_returnreject': '%s' % urlparse.urljoin(self.base_url, BuckarooController._reject_url), | ||
438 | 52 | 'Brq_culture': 'en-US', | ||
439 | 53 | } | ||
440 | 54 | |||
441 | 55 | # render the button | ||
442 | 56 | res = self.payment_acquirer.render( | ||
443 | 57 | cr, uid, self.buckaroo_id, | ||
444 | 58 | 'SO004', 2240.0, self.currency_euro_id, | ||
445 | 59 | partner_id=None, | ||
446 | 60 | partner_values=self.buyer_values, | ||
447 | 61 | context=context) | ||
448 | 62 | |||
449 | 63 | # check form result | ||
450 | 64 | tree = objectify.fromstring(res) | ||
451 | 65 | self.assertEqual(tree.get('action'), 'https://testcheckout.buckaroo.nl/html/', 'Buckaroo: wrong form POST url') | ||
452 | 66 | for form_input in tree.input: | ||
453 | 67 | if form_input.get('name') in ['submit']: | ||
454 | 68 | continue | ||
455 | 69 | self.assertEqual( | ||
456 | 70 | form_input.get('value'), | ||
457 | 71 | form_values[form_input.get('name')], | ||
458 | 72 | 'Buckaroo: wrong value for input %s: received %s instead of %s' % (form_input.get('name'), form_input.get('value'), form_values[form_input.get('name')]) | ||
459 | 73 | ) | ||
460 | 74 | |||
461 | 75 | # ---------------------------------------- | ||
462 | 76 | # Test2: button using tx + validation | ||
463 | 77 | # ---------------------------------------- | ||
464 | 78 | |||
465 | 79 | # create a new draft tx | ||
466 | 80 | tx_id = self.payment_transaction.create( | ||
467 | 81 | cr, uid, { | ||
468 | 82 | 'amount': 2240.0, | ||
469 | 83 | 'acquirer_id': self.buckaroo_id, | ||
470 | 84 | 'currency_id': self.currency_euro_id, | ||
471 | 85 | 'reference': 'SO004', | ||
472 | 86 | 'partner_id': self.buyer_id, | ||
473 | 87 | }, context=context | ||
474 | 88 | ) | ||
475 | 89 | |||
476 | 90 | # render the button | ||
477 | 91 | res = self.payment_acquirer.render( | ||
478 | 92 | cr, uid, self.buckaroo_id, | ||
479 | 93 | 'should_be_erased', 2240.0, self.currency_euro, | ||
480 | 94 | tx_id=tx_id, | ||
481 | 95 | partner_id=None, | ||
482 | 96 | partner_values=self.buyer_values, | ||
483 | 97 | context=context) | ||
484 | 98 | |||
485 | 99 | # check form result | ||
486 | 100 | tree = objectify.fromstring(res) | ||
487 | 101 | self.assertEqual(tree.get('action'), 'https://testcheckout.buckaroo.nl/html/', 'Buckaroo: wrong form POST url') | ||
488 | 102 | for form_input in tree.input: | ||
489 | 103 | if form_input.get('name') in ['submit']: | ||
490 | 104 | continue | ||
491 | 105 | self.assertEqual( | ||
492 | 106 | form_input.get('value'), | ||
493 | 107 | form_values[form_input.get('name')], | ||
494 | 108 | 'Buckaroo: wrong value for form input %s: received %s instead of %s' % (form_input.get('name'), form_input.get('value'), form_values[form_input.get('name')]) | ||
495 | 109 | ) | ||
496 | 110 | |||
497 | 111 | @mute_logger('openerp.addons.payment_buckaroo.models.buckaroo', 'ValidationError') | ||
498 | 112 | def test_20_buckaroo_form_management(self): | ||
499 | 113 | cr, uid, context = self.cr, self.uid, {} | ||
500 | 114 | # be sure not to do stupid thing | ||
501 | 115 | buckaroo = self.payment_acquirer.browse(self.cr, self.uid, self.buckaroo_id, None) | ||
502 | 116 | self.assertEqual(buckaroo.environment, 'test', 'test without test environment') | ||
503 | 117 | |||
504 | 118 | # typical data posted by buckaroo after client has successfully paid | ||
505 | 119 | buckaroo_post_data = { | ||
506 | 120 | 'BRQ_RETURNDATA': u'', | ||
507 | 121 | 'BRQ_AMOUNT': u'2240.00', | ||
508 | 122 | 'BRQ_CURRENCY': u'EUR', | ||
509 | 123 | 'BRQ_CUSTOMER_NAME': u'Jan de Tester', | ||
510 | 124 | 'BRQ_INVOICENUMBER': u'SO004', | ||
511 | 125 | 'BRQ_PAYMENT': u'573311D081B04069BD6336001611DBD4', | ||
512 | 126 | 'BRQ_PAYMENT_METHOD': u'paypal', | ||
513 | 127 | 'BRQ_SERVICE_PAYPAL_PAYERCOUNTRY': u'NL', | ||
514 | 128 | 'BRQ_SERVICE_PAYPAL_PAYEREMAIL': u'fhe@openerp.com', | ||
515 | 129 | 'BRQ_SERVICE_PAYPAL_PAYERFIRSTNAME': u'Jan', | ||
516 | 130 | 'BRQ_SERVICE_PAYPAL_PAYERLASTNAME': u'Tester', | ||
517 | 131 | 'BRQ_SERVICE_PAYPAL_PAYERMIDDLENAME': u'de', | ||
518 | 132 | 'BRQ_SERVICE_PAYPAL_PAYERSTATUS': u'verified', | ||
519 | 133 | 'BRQ_SIGNATURE': u'175d82dd53a02bad393fee32cb1eafa3b6fbbd91', | ||
520 | 134 | 'BRQ_STATUSCODE': u'190', | ||
521 | 135 | 'BRQ_STATUSCODE_DETAIL': u'S001', | ||
522 | 136 | 'BRQ_STATUSMESSAGE': u'Transaction successfully processed', | ||
523 | 137 | 'BRQ_TEST': u'true', | ||
524 | 138 | 'BRQ_TIMESTAMP': u'2014-05-08 12:41:21', | ||
525 | 139 | 'BRQ_TRANSACTIONS': u'D6106678E1D54EEB8093F5B3AC42EA7B', | ||
526 | 140 | 'BRQ_WEBSITEKEY': u'5xTGyGyPyl', | ||
527 | 141 | } | ||
528 | 142 | |||
529 | 143 | # should raise error about unknown tx | ||
530 | 144 | with self.assertRaises(ValidationError): | ||
531 | 145 | self.payment_transaction.form_feedback(cr, uid, buckaroo_post_data, 'buckaroo', context=context) | ||
532 | 146 | |||
533 | 147 | tx_id = self.payment_transaction.create( | ||
534 | 148 | cr, uid, { | ||
535 | 149 | 'amount': 2240.0, | ||
536 | 150 | 'acquirer_id': self.buckaroo_id, | ||
537 | 151 | 'currency_id': self.currency_euro_id, | ||
538 | 152 | 'reference': 'SO004', | ||
539 | 153 | 'partner_name': 'Norbert Buyer', | ||
540 | 154 | 'partner_country_id': self.country_france_id, | ||
541 | 155 | }, context=context | ||
542 | 156 | ) | ||
543 | 157 | # validate it | ||
544 | 158 | self.payment_transaction.form_feedback(cr, uid, buckaroo_post_data, 'buckaroo', context=context) | ||
545 | 159 | # check state | ||
546 | 160 | tx = self.payment_transaction.browse(cr, uid, tx_id, context=context) | ||
547 | 161 | self.assertEqual(tx.state, 'done', 'Buckaroo: validation did not put tx into done state') | ||
548 | 162 | self.assertEqual(tx.buckaroo_txnid, buckaroo_post_data.get('BRQ_TRANSACTIONS'), 'Buckaroo: validation did not update tx payid') | ||
549 | 163 | |||
550 | 164 | # reset tx | ||
551 | 165 | tx.write({'state': 'draft', 'date_validate': False, 'buckaroo_txnid': False}) | ||
552 | 166 | |||
553 | 167 | # now buckaroo post is ok: try to modify the SHASIGN | ||
554 | 168 | buckaroo_post_data['BRQ_SIGNATURE'] = '54d928810e343acf5fb0c3ee75fd747ff159ef7a' | ||
555 | 169 | with self.assertRaises(ValidationError): | ||
556 | 170 | self.payment_transaction.form_feedback(cr, uid, buckaroo_post_data, 'buckaroo', context=context) | ||
557 | 171 | |||
558 | 172 | # simulate an error | ||
559 | 173 | buckaroo_post_data['BRQ_STATUSCODE'] = 2 | ||
560 | 174 | buckaroo_post_data['BRQ_SIGNATURE'] = '4164b52adb1e6a2221d3d8a39d8c3e18a9ecb90b' | ||
561 | 175 | self.payment_transaction.form_feedback(cr, uid, buckaroo_post_data, 'buckaroo', context=context) | ||
562 | 176 | # check state | ||
563 | 177 | tx = self.payment_transaction.browse(cr, uid, tx_id, context=context) | ||
564 | 178 | self.assertEqual(tx.state, 'error', 'Buckaroo: erroneous validation did not put tx into error state') | ||
565 | 0 | 179 | ||
566 | === added directory 'payment_buckaroo/views' | |||
567 | === added file 'payment_buckaroo/views/buckaroo.xml' | |||
568 | --- payment_buckaroo/views/buckaroo.xml 1970-01-01 00:00:00 +0000 | |||
569 | +++ payment_buckaroo/views/buckaroo.xml 2014-05-21 05:25:49 +0000 | |||
570 | @@ -0,0 +1,34 @@ | |||
571 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
572 | 2 | <openerp> | ||
573 | 3 | <data noupdate="1"> | ||
574 | 4 | |||
575 | 5 | <template id="buckaroo_acquirer_button"> | ||
576 | 6 | <form t-if="acquirer.brq_websitekey" t-att-action="tx_url" method="post" target="_self"> | ||
577 | 7 | <input type="hidden" name="Brq_websitekey" t-att-value="tx_values['Brq_websitekey']"/> | ||
578 | 8 | <input type="hidden" name="Brq_amount" t-att-value="tx_values['Brq_amount'] or '0.0'"/> | ||
579 | 9 | <input type="hidden" name="Brq_currency" t-att-value="tx_values['Brq_currency']"/> | ||
580 | 10 | <input type="hidden" name="Brq_invoicenumber" t-att-value="tx_values['Brq_invoicenumber']"/> | ||
581 | 11 | <input type="hidden" name="Brq_signature" t-att-value="tx_values['Brq_signature']"/> | ||
582 | 12 | <input type="hidden" name="brq_test" t-att-value="tx_values['brq_test']"/> | ||
583 | 13 | <input type="hidden" name="Brq_culture" t-att-value="tx_values['Brq_culture']"/> | ||
584 | 14 | <!-- URLs --> | ||
585 | 15 | <input t-if="tx_values.get('Brq_return')" type='hidden' name='Brq_return' | ||
586 | 16 | t-att-value="tx_values.get('Brq_return')"/> | ||
587 | 17 | <input t-if="tx_values.get('Brq_returncancel')" type='hidden' name='Brq_returncancel' | ||
588 | 18 | t-att-value="tx_values.get('Brq_returncancel')"/> | ||
589 | 19 | <input t-if="tx_values.get('Brq_returnerror')" type='hidden' name='Brq_returnerror' | ||
590 | 20 | t-att-value="tx_values.get('Brq_returnerror')"/> | ||
591 | 21 | <input t-if="tx_values.get('Brq_returnreject')" type='hidden' name='Brq_returnreject' | ||
592 | 22 | t-att-value="tx_values.get('Brq_returnreject')"/> | ||
593 | 23 | <input type='hidden' name='add_returndata' t-att-value="tx_values.get('add_returndata')"/> | ||
594 | 24 | <!-- submit --> | ||
595 | 25 | <button type="image" name="submit" width="100px" | ||
596 | 26 | t-att-class="submit_class"> | ||
597 | 27 | <img t-if="not submit_txt" src="/payment_buckaroo/static/src/img/buckaroo_icon.png"/> | ||
598 | 28 | <span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span> | ||
599 | 29 | </button> | ||
600 | 30 | </form> | ||
601 | 31 | </template> | ||
602 | 32 | |||
603 | 33 | </data> | ||
604 | 34 | </openerp> | ||
605 | 0 | 35 | ||
606 | === added file 'payment_buckaroo/views/payment_acquirer.xml' | |||
607 | --- payment_buckaroo/views/payment_acquirer.xml 1970-01-01 00:00:00 +0000 | |||
608 | +++ payment_buckaroo/views/payment_acquirer.xml 2014-05-21 05:25:49 +0000 | |||
609 | @@ -0,0 +1,35 @@ | |||
610 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
611 | 2 | <openerp> | ||
612 | 3 | <data> | ||
613 | 4 | |||
614 | 5 | <record id="acquirer_form_buckaroo" model="ir.ui.view"> | ||
615 | 6 | <field name="name">acquirer.form.buckaroo</field> | ||
616 | 7 | <field name="model">payment.acquirer</field> | ||
617 | 8 | <field name="inherit_id" ref="payment.acquirer_form"/> | ||
618 | 9 | <field name="arch" type="xml"> | ||
619 | 10 | <xpath expr='//group[@name="acquirer_display"]' position='after'> | ||
620 | 11 | <group attrs="{'invisible': [('provider', '!=', 'buckaroo')]}"> | ||
621 | 12 | <field name="brq_websitekey"/> | ||
622 | 13 | <field name="brq_secretkey"/> | ||
623 | 14 | </group> | ||
624 | 15 | </xpath> | ||
625 | 16 | </field> | ||
626 | 17 | </record> | ||
627 | 18 | |||
628 | 19 | <record id="transaction_form_buckaroo" model="ir.ui.view"> | ||
629 | 20 | <field name="name">acquirer.transaction.form.buckaroo</field> | ||
630 | 21 | <field name="model">payment.transaction</field> | ||
631 | 22 | <field name="inherit_id" ref="payment.transaction_form"/> | ||
632 | 23 | <field name="arch" type="xml"> | ||
633 | 24 | <xpath expr='//notebook' position='inside'> | ||
634 | 25 | <page string="Buckaroo TX Details"> | ||
635 | 26 | <group> | ||
636 | 27 | <field name="buckaroo_txnid"/> | ||
637 | 28 | </group> | ||
638 | 29 | </page> | ||
639 | 30 | </xpath> | ||
640 | 31 | </field> | ||
641 | 32 | </record> | ||
642 | 33 | |||
643 | 34 | </data> | ||
644 | 35 | </openerp> | ||
645 | 0 | 36 | ||
646 | === modified file 'website_sale/controllers/main.py' | |||
647 | --- website_sale/controllers/main.py 2014-05-19 10:12:46 +0000 | |||
648 | +++ website_sale/controllers/main.py 2014-05-21 05:25:49 +0000 | |||
649 | @@ -489,7 +489,6 @@ | |||
650 | 489 | values['acquirers'] = payment_obj.browse(cr, uid, acquirer_ids, context=context) | 489 | values['acquirers'] = payment_obj.browse(cr, uid, acquirer_ids, context=context) |
651 | 490 | render_ctx = dict(context, submit_class='btn btn-primary', submit_txt='Pay Now') | 490 | render_ctx = dict(context, submit_class='btn btn-primary', submit_txt='Pay Now') |
652 | 491 | for acquirer in values['acquirers']: | 491 | for acquirer in values['acquirers']: |
653 | 492 | render_ctx['tx_url'] = '/shop/payment/transaction/%s' % acquirer.id | ||
654 | 493 | acquirer.button = payment_obj.render( | 492 | acquirer.button = payment_obj.render( |
655 | 494 | cr, SUPERUSER_ID, acquirer.id, | 493 | cr, SUPERUSER_ID, acquirer.id, |
656 | 495 | order.name, | 494 | order.name, |
657 | @@ -503,32 +502,35 @@ | |||
658 | 503 | 502 | ||
659 | 504 | return request.website.render("website_sale.payment", values) | 503 | return request.website.render("website_sale.payment", values) |
660 | 505 | 504 | ||
665 | 506 | @http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='http', methods=['POST'], auth="public", website=True) | 505 | @http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='json', auth="public", website=True) |
666 | 507 | def payment_transaction(self, acquirer_id, **post): | 506 | def payment_transaction(self, acquirer_id): |
667 | 508 | """ Hook method that creates a payment.transaction and redirect to the | 507 | """ Json method that creates a payment.transaction, used to create a |
668 | 509 | acquirer, using post values to re-create the post action. | 508 | transaction when the user clicks on 'pay now' button. After having |
669 | 509 | created the transaction, the event continues and the user is redirected | ||
670 | 510 | to the acquirer website. | ||
671 | 510 | 511 | ||
672 | 511 | :param int acquirer_id: id of a payment.acquirer record. If not set the | 512 | :param int acquirer_id: id of a payment.acquirer record. If not set the |
673 | 512 | user is redirected to the checkout page | 513 | user is redirected to the checkout page |
674 | 513 | :param dict post: should coutain all post data for the acquirer | ||
675 | 514 | """ | 514 | """ |
676 | 515 | # @TDEFIXME: don't know why we received those data, but should not be send to the acquirer | ||
677 | 516 | post.pop('submit.x', None) | ||
678 | 517 | post.pop('submit.y', None) | ||
679 | 518 | cr, uid, context = request.cr, request.uid, request.context | 515 | cr, uid, context = request.cr, request.uid, request.context |
680 | 519 | payment_obj = request.registry.get('payment.acquirer') | ||
681 | 520 | transaction_obj = request.registry.get('payment.transaction') | 516 | transaction_obj = request.registry.get('payment.transaction') |
682 | 521 | sale_order_obj = request.registry['sale.order'] | 517 | sale_order_obj = request.registry['sale.order'] |
683 | 522 | order = request.website.sale_get_order(context=context) | 518 | order = request.website.sale_get_order(context=context) |
684 | 523 | 519 | ||
685 | 524 | if not order or not order.order_line or acquirer_id is None: | 520 | if not order or not order.order_line or acquirer_id is None: |
687 | 525 | return request.redirect("/shop/checkout") | 521 | return False |
688 | 526 | 522 | ||
689 | 527 | assert order.partner_id.id != request.website.partner_id.id | 523 | assert order.partner_id.id != request.website.partner_id.id |
690 | 528 | 524 | ||
691 | 529 | # find an already existing transaction | 525 | # find an already existing transaction |
692 | 530 | tx = request.website.sale_get_transaction() | 526 | tx = request.website.sale_get_transaction() |
694 | 531 | if not tx: | 527 | if tx: |
695 | 528 | if tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ? | ||
696 | 529 | tx.write({ | ||
697 | 530 | 'acquirer_id': acquirer_id, | ||
698 | 531 | }) | ||
699 | 532 | tx_id = tx.id | ||
700 | 533 | else: | ||
701 | 532 | tx_id = transaction_obj.create(cr, SUPERUSER_ID, { | 534 | tx_id = transaction_obj.create(cr, SUPERUSER_ID, { |
702 | 533 | 'acquirer_id': acquirer_id, | 535 | 'acquirer_id': acquirer_id, |
703 | 534 | 'type': 'form', | 536 | 'type': 'form', |
704 | @@ -540,10 +542,6 @@ | |||
705 | 540 | 'sale_order_id': order.id, | 542 | 'sale_order_id': order.id, |
706 | 541 | }, context=context) | 543 | }, context=context) |
707 | 542 | request.session['sale_transaction_id'] = tx_id | 544 | request.session['sale_transaction_id'] = tx_id |
708 | 543 | elif tx and tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ? | ||
709 | 544 | tx.write({ | ||
710 | 545 | 'acquirer_id': acquirer_id, | ||
711 | 546 | }) | ||
712 | 547 | 545 | ||
713 | 548 | # update quotation | 546 | # update quotation |
714 | 549 | sale_order_obj.write( | 547 | sale_order_obj.write( |
715 | @@ -554,9 +552,7 @@ | |||
716 | 554 | # confirm the quotation | 552 | # confirm the quotation |
717 | 555 | sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context) | 553 | sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context) |
718 | 556 | 554 | ||
722 | 557 | acquirer_form_post_url = payment_obj.get_form_action_url(cr, uid, acquirer_id, context=context) | 555 | return tx_id |
720 | 558 | acquirer_total_url = '%s?%s' % (acquirer_form_post_url, werkzeug.url_encode(post)) | ||
721 | 559 | return request.redirect(acquirer_total_url) | ||
723 | 560 | 556 | ||
724 | 561 | @http.route('/shop/payment/get_status/<int:sale_order_id>', type='json', auth="public", website=True) | 557 | @http.route('/shop/payment/get_status/<int:sale_order_id>', type='json', auth="public", website=True) |
725 | 562 | def payment_get_status(self, sale_order_id, **post): | 558 | def payment_get_status(self, sale_order_id, **post): |
726 | 563 | 559 | ||
727 | === modified file 'website_sale/static/src/js/website_sale_payment.js' | |||
728 | --- website_sale/static/src/js/website_sale_payment.js 2014-01-24 11:42:24 +0000 | |||
729 | +++ website_sale/static/src/js/website_sale_payment.js 2014-05-21 05:25:49 +0000 | |||
730 | @@ -9,4 +9,14 @@ | |||
731 | 9 | }) | 9 | }) |
732 | 10 | .find("input[name='acquirer']:checked").click(); | 10 | .find("input[name='acquirer']:checked").click(); |
733 | 11 | 11 | ||
734 | 12 | // When clicking on payment button: create the tx using json then continue to the acquirer | ||
735 | 13 | $payment.on("click", "button[name='submit']", function (ev) { | ||
736 | 14 | var acquirer_id = $(ev.currentTarget).parents('div.oe_sale_acquirer_button').first().data('id'); | ||
737 | 15 | if (! acquirer_id) { | ||
738 | 16 | return false; | ||
739 | 17 | } | ||
740 | 18 | return openerp.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {}).then(function (data) { | ||
741 | 19 | return true; | ||
742 | 20 | }); | ||
743 | 21 | }); | ||
744 | 12 | }); | 22 | }); |
Hello,
At first sight seems quite correct. But could you write tests like the one present in paypal or ogone ? They should be disabled by default because there is no valid data in the module; but test them locally using the credentials you have.
Best regards,