Files
odoo_source/addons/payment_stripe/models/payment_token.py
T
Horacio Tellez f7b8f07501 [IMP] payment: rename of acquirer to provider
Changing the name of model payment.acquirer to payment.provider
and everything that it touches. It is technically incorrect to
use the term "acquirer" for systems that only provide a service
of payment.
After this commit the model payment.acquirer and all related to
it will be renamed to payment.provider.

Task - 2842088

closes odoo/odoo#90899

Related: odoo/upgrade#3542
Related: odoo/documentation#1981
Related: odoo/enterprise#27131
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2022-09-09 13:38:08 +02:00

51 lines
2.0 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import pprint
from odoo import _, fields, models
from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
class PaymentToken(models.Model):
_inherit = 'payment.token'
stripe_payment_method = fields.Char(string="Stripe Payment Method ID", readonly=True)
def _stripe_sca_migrate_customer(self):
""" Migrate a token from the old implementation of Stripe to the SCA-compliant one.
In the old implementation, it was possible to create a Charge by giving only the customer id
and let Stripe use the default source (= default payment method). Stripe now requires to
specify the payment method for each new PaymentIntent. To do so, we fetch the payment method
associated to a customer and save its id on the token.
This migration happens once per token created with the old implementation.
Note: self.ensure_one()
:return: None
"""
self.ensure_one()
# Fetch the available payment method of type 'card' for the given customer
response_content = self.provider_id._stripe_make_request(
'payment_methods',
payload={
'customer': self.provider_ref,
'type': 'card',
'limit': 1, # A new customer is created for each new token. Never > 1 card.
},
method='GET'
)
_logger.info("received payment_methods response:\n%s", pprint.pformat(response_content))
# Store the payment method ID on the token
payment_methods = response_content.get('data', [])
payment_method_id = payment_methods and payment_methods[0].get('id')
if not payment_method_id:
raise ValidationError("Stripe: " + _("Unable to convert payment token to new API."))
self.stripe_payment_method = payment_method_id
_logger.info("converted token with id %s to new API", self.id)