Files
odoo_source/addons/payment_stripe/controllers/onboarding.py
T
Thibault Libioulle c5198b0bab [IMP] payment{,_stripe},{,website_}sale: improve stripe onboarding
This commit lighten payment onboarding form in order to take advantage
of the Stripe Connect Onboarding Flow. It integrates the Stripe
Onboarding using the IAP proxy.

Purpose
=======
Help users easily onboard with Stripe by using the Stripe Connect API.

Specifications
==============
During the payment onboarding, if the user selects Stripe, they will
start the Stripe Onboarding. (NB: The process uses a proxy that handles
the Stripe Onboarding calls and signs them with the Stripe Connect key)
1) A call is made through the proxy to get the Stripe account token;
2) A call is made through the proxy to get the Stripe account link which
   contains the URL of the Onboarding;
3) The user is redirected to the Stripe Onboarding;
4) The user completes the Stripe Onboarding;
5) The user comes back to the acquirer form of Stripe and is able to get
   their keys.
6) The user can directly create their webhook after having copied/pasted
   their API keys.

During the website sale onboarding, the user doesn't go through the
onboarding wizard but is directly prompted to activate their account.

Note that the Onboarding status isn't stored in the database so there is
no call to Stripe API to validate the account status.

API Documentation :
- Connect Onboarding: https://stripe.com/docs/connect/standard-accounts
- Webhook creation: https://stripe.com/docs/api/webhook_endpoints/create

task-2685160
task-2691213

closes odoo/odoo#84639

X-original-commit: 085f4af4e57c43127413585a8df5b3aa47843339
Related: odoo/enterprise#24376
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Thibault Libioulle (tle) <tle@odoo.com>
2022-02-15 16:51:24 +00:00

48 lines
2.4 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from werkzeug.urls import url_encode
from odoo import http
from odoo.http import request
class OnboardingController(http.Controller):
_onboarding_return_url = '/payment/stripe/onboarding/return'
_onboarding_refresh_url = '/payment/stripe/onboarding/refresh'
@http.route(_onboarding_return_url, type='http', methods=['GET'], auth='user')
def stripe_return_from_onboarding(self, acquirer_id, menu_id):
""" Redirect the user to the acquirer form of the onboarded Stripe account.
The user is redirected to this route by Stripe after or during (if the user clicks on a
dedicated button) the onboarding.
:param str acquirer_id: The acquirer linked to the Stripe account being onboarded, as a
`payment.acquirer` id
:param str menu_id: The menu from which the user started the onboarding step, as an
`ir.ui.menu` id
"""
stripe_acquirer = request.env['payment.acquirer'].browse(int(acquirer_id))
stripe_acquirer.company_id._mark_payment_onboarding_step_as_done()
action = request.env.ref(
'payment_stripe.action_payment_acquirer_onboarding', raise_if_not_found=False
) or request.env.ref('payment.action_payment_acquirer')
get_params_string = url_encode({'action': action.id, 'id': acquirer_id, 'menu_id': menu_id})
return request.redirect(f'/web?#{get_params_string}')
@http.route(_onboarding_refresh_url, type='http', methods=['GET'], auth='user')
def stripe_refresh_onboarding(self, acquirer_id, account_id, menu_id):
""" Redirect the user to a new Stripe Connect onboarding link.
The user is redirected to this route by Stripe if the onboarding link they used was expired.
:param str acquirer_id: The acquirer linked to the Stripe account being onboarded, as a
`payment.acquirer` id
:param str account_id: The id of the connected account
:param str menu_id: The menu from which the user started the onboarding step, as an
`ir.ui.menu` id
"""
stripe_acquirer = request.env['payment.acquirer'].browse(int(acquirer_id))
account_link = stripe_acquirer._stripe_create_account_link(account_id, int(menu_id))
return request.redirect(account_link, local=False)