summaryrefslogtreecommitdiff
path: root/addons/payment_stripe/controllers
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2016-04-04 11:37:34 +0200
committerMartin Trigaux <mat@odoo.com>2016-04-04 17:09:08 +0200
commit33c094d218b9afc33260cb92ae80273aa8fef463 (patch)
tree7629a6bbb536b3fed29006f86049ea76a7da51b9 /addons/payment_stripe/controllers
parent8b596e8e1b33962011635c85d12bcc088f45732c (diff)
[ADD] payment_stripe
https://stripe.com/docs/api Closes #11587
Diffstat (limited to 'addons/payment_stripe/controllers')
-rw-r--r--addons/payment_stripe/controllers/__init__.py3
-rw-r--r--addons/payment_stripe/controllers/main.py51
2 files changed, 54 insertions, 0 deletions
diff --git a/addons/payment_stripe/controllers/__init__.py b/addons/payment_stripe/controllers/__init__.py
new file mode 100644
index 00000000000..bbd183e955b
--- /dev/null
+++ b/addons/payment_stripe/controllers/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+import main
diff --git a/addons/payment_stripe/controllers/main.py b/addons/payment_stripe/controllers/main.py
new file mode 100644
index 00000000000..3075ec68399
--- /dev/null
+++ b/addons/payment_stripe/controllers/main.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+import logging
+import pprint
+import werkzeug
+
+from odoo import http
+from odoo.http import request
+
+_logger = logging.getLogger(__name__)
+
+
+class StripeController(http.Controller):
+
+ @http.route(['/payment/stripe/s2s/create_json'], type='json', auth='public')
+ def stripe_s2s_create_json(self, **kwargs):
+ acquirer_id = int(kwargs.get('acquirer_id'))
+ acquirer = request.env['payment.acquirer'].browse(acquirer_id)
+ return acquirer.s2s_process(kwargs)
+
+ @http.route(['/payment/stripe/s2s/create'], type='http', auth='public')
+ def stripe_s2s_create(self, **post):
+ acquirer_id = int(post.get('acquirer_id'))
+ acquirer = request.env['payment.acquirer'].browse(acquirer_id)
+ acquirer.s2s_process(post)
+ return werkzeug.utils.redirect(post.get('return_url', '/'))
+
+ @http.route(['/payment/stripe/create_charge'], type='json', auth='public')
+ def stripe_create_charge(self, **post):
+ """ Create a payment transaction
+
+ Expects the result from the user input from checkout.js popup"""
+ acquirer = request.env['payment.acquirer'].browse(int(post.get('acquirer_id')))
+ order = request.env['sale.order'].sudo().browse(int(request.session.get('sale_order_id')))
+ tx = request.env['payment.transaction'].sudo().create({
+ 'acquirer_id': acquirer.id,
+ 'reference': str(post.get('invoice_num')),
+ 'amount': float(post.get('amount')),
+ 'currency_id': request.env['res.currency'].search([('name', '=', post.get('currency'))], limit=1).id,
+ 'partner_id': request.env.user.partner_id.id,
+ 'sale_order_id': order.id
+ })
+ order.write({
+ 'payment_acquirer_id': acquirer.id,
+ 'payment_tx_id': tx.id
+ })
+ request.session['sale_transaction_id'] = tx.id
+ response = tx._create_stripe_charge(tokenid=post['tokenid'])
+ _logger.info('Stripe: entering form_feedback with post data %s', pprint.pformat(response))
+ if response:
+ request.env['payment.transaction'].sudo().form_feedback(response, 'stripe')
+ return post.pop('return_url', '/')