The previous commit introduced some changes for SCA/PSD2 but some things were missing; most notably, registering payment cards in a s2s flow used the old Charge API that is not SCA-ready. This commit uses the SetupIntent API instead, allowing to register the card prior to payment. The global flow is described in the Stripe documentation in more details: https://stripe.com/docs/payments/cards/saving-cards Unfortunately, given the complete flow of payments, it is not possible to use the PaymentIntents API since this would require having the reference of the transaction before it gets created (the TX is created after the form submission, but the token must already exist at that point). Since this is meant to be backported, this changes are kept minimal in this feature branch. The PaymentIntents API would have been better since registering a card during a payment makes it more likely that future off-session transactions will not require an authentication step. We'll have to live with that for now; it's difficult to know exactly how this will affect customers before PSD2 goes into effect on september 14. Another branch might completely change the flow soon-ish to a more asynchroneous model, although it may miss the v13 freeze date -_-
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
import werkzeug
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class StripeController(http.Controller):
|
|
_success_url = '/payment/stripe/success'
|
|
_cancel_url = '/payment/stripe/cancel'
|
|
|
|
@http.route(['/payment/stripe/success', '/payment/stripe/cancel'], type='http', auth='public')
|
|
def stripe_success(self, **kwargs):
|
|
request.env['payment.transaction'].sudo().form_feedback(kwargs, 'stripe')
|
|
return werkzeug.utils.redirect('/payment/process')
|
|
|
|
@http.route(['/payment/stripe/s2s/create_json_3ds'], type='json', auth='public', csrf=False)
|
|
def stripe_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
|
|
if not kwargs.get('partner_id'):
|
|
kwargs = dict(kwargs, partner_id=request.env.user.partner_id.id)
|
|
token = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id'))).s2s_process(kwargs)
|
|
|
|
if not token:
|
|
res = {
|
|
'result': False,
|
|
}
|
|
return res
|
|
|
|
res = {
|
|
'result': True,
|
|
'id': token.id,
|
|
'short_name': token.short_name,
|
|
'3d_secure': False,
|
|
'verified': False,
|
|
}
|
|
|
|
if verify_validity != False:
|
|
token.validate()
|
|
res['verified'] = token.verified
|
|
|
|
return res
|
|
|
|
@http.route('/payment/stripe/s2s/create_setup_intent', type='json', auth='public', csrf=False)
|
|
def stripe_s2s_create_setup_intent(self, acquirer_id, **kwargs):
|
|
acquirer = request.env['payment.acquirer'].browse(int(acquirer_id))
|
|
res = acquirer._create_setup_intent(kwargs)
|
|
return res.get('client_secret')
|