- When registering a payment token, validating it using a payment of a small amount (~1.50€) followed by a refund allows ensuring
that the payment method is valid (i.e. checksumming the card number simple ensure the number is valid but not that the card exists).
This commit introduces a generic approach that must be implemented for each acquirer that has tokenization support.
This commit also introduces a generic payment token registration/usage template that can be adapted according to one's need.
- Introducing a new payment form that handles payment, deletion and adding payment method (only for server2server for the moment).
- On /my/payment_method, changed strings 'Payment Acquirers' to 'Payment Methods' which is more clear.
- Stripe can now be used to pay subscriptions.
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
# -*- 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).id
|
|
|
|
@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/s2s/create_json_3ds'], type='json', auth='public', csrf=False)
|
|
def stripe_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
|
|
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/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"""
|
|
tx = request.env['payment.transaction'].sudo().browse(
|
|
int(request.session.get('sale_transaction_id') or request.session.get('website_payment_tx_id', False))
|
|
)
|
|
response = tx._create_stripe_charge(tokenid=post['tokenid'], email=post['email'])
|
|
_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', '/')
|