UPDATE
I got this to work. Turns out the id for the payment acquirer is not pass to the controller class, furthermore, there could potentially be two payment acquirer of the same type for the site (maybe I am not sure). In any case, I am putting the payment acquire ID in the form. When I post, I can get the actual acquire used, then get the private key (which does not change per transaction but should never be put on the form). Once I got the ID it was trivial to get the other stuff.
I tried that but I got
File "/home/rlavaud/addons/payment_stripe/controllers/main.py", line 24, in transfer_form_feedback
stripe.api_key = self.env['payment.stripe'].stripe_get_secret_key()
AttributeError: 'StripeController' object has no attribute 'env'
I think it has to be something like
request.registry['payment.acquirer'].stripe_get_secret_key(cr, uid, id, context)
but I am not sure of the syntax
I get this error
File "/home/rlavaud/addons/payment_stripe/controllers/main.py", line 23, in transfer_form_feedback
stripe.api_key = request.registry['payment.acquirer'].stripe_get_secret_key(cr, uid, id, context)
File "/opt/odoo/server/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/rlavaud/addons/payment_stripe/models/payment_acquirer.py", line 27, in stripe_get_secret_key
acquirer = self.browse(cr, uid, id, context=context)
File "/opt/odoo/server/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/server/openerp/models.py", line 5205, in browse
ids = _normalize_ids(arg)
File "/opt/odoo/server/openerp/models.py", line 6069, in _normalize_ids
return tuple(arg)
TypeError: 'builtin_function_or_method' object is not iterable
File "/home/rlavaud/addons/payment_stripe/controllers/main.py", line 23, in transfer_form_feedback
stripe.api_key = request.registry['payment.acquirer'].stripe_get_secret_key(cr, uid, id, context)
File "/opt/odoo/server/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/rlavaud/addons/payment_stripe/models/payment_acquirer.py", line 27, in stripe_get_secret_key
acquirer = self.browse(cr, uid, id, context=context)
File "/opt/odoo/server/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/server/openerp/models.py", line 5205, in browse
ids = _normalize_ids(arg)
File "/opt/odoo/server/openerp/models.py", line 6069, in _normalize_ids
return tuple(arg)
TypeError: 'builtin_function_or_method' object is not iterable
And here is the code I am calling
Printing the variables cr uid id and context I get this. I think id is undefined, where would I get id from?
2015-05-17 18:28:51,121 14605 INFO demo openerp.addons.payment_stripe.controllers.main: Print cr <openerp.sql_db.Cursor object at 0x7fbb46c25250>
2015-05-17 18:28:51,122 14605 INFO demo openerp.addons.payment_stripe.controllers.main: Print uid 1
2015-05-17 18:28:51,122 14605 INFO demo openerp.addons.payment_stripe.controllers.main: Print id <built-in function id>
2015-05-17 18:28:51,122 14605 INFO demo openerp.addons.payment_stripe.controllers.main: Print context {'lang': u'en_US', 'tz': u'Europe/Brussels', 'uid': 1}
2015-05-17 18:28:51,133 14605 INFO demo werkzeug: 127.0.0.1 - - [17/May/2015 18:28:51] "POST /payment/stripe/feedback HTTP/1.0" 500 -
def transfer_form_feedback(self, **post):
cr, uid, context = request.cr, SUPERUSER_ID, request.context
_logger.info('Beginning form_feedback with post data %s', pprint.pformat(post)) # debug
stripe.api_key = request.registry['payment.acquirer'].stripe_get_secret_key(cr, uid, id, context)
resp = stripe.Charge.create (
amount= post.pop('data-amount'),
currency=post.pop('data-currency'),
source=post.pop('data-token'),
description=post.pop('data-description')
)
_logger.info('Stripe response: %s', pprint.pformat(resp)) # debug
request.registry['payment.transaction'].form_feedback(cr, uid, post, 'stripe', context)
return werkzeug.utils.redirect(post.pop('return_url', '/'))