Payment Provider

class odoo.addons.payment.models.payment_provider.PaymentProvider[源代码]
_build_request_auth(**_kwargs)[源代码]

Set the basic HTTP Auth of the request.

This method serves as a hook to allow providers to build the request’s basic HTTP Auth.

参数

_kwargs (dict) – Provider-specific data.

返回

The basic HTTP Auth, if any.

返回类型

tuple

_build_request_headers(method, endpoint, payload, **_kwargs)[源代码]

Build the headers of the request.

This method serves as a hook to allow providers to build the request headers.

参数
  • method (str) – The HTTP method of the request.

  • endpoint (str) – The endpoint of the API to reach with the request.

  • payload (dict) – The payload of the request.

  • _kwargs (dict) – Provider-specific data.

返回

The request headers.

返回类型

dict

_build_request_url(endpoint, **_kwargs)[源代码]

Build the URL of the request.

This method serves as a hook to allow providers to build the request URL.

参数
  • endpoint (str) – The endpoint of the API to reach with the request.

  • _kwargs (dict) – Provider-specific data.

返回

The request URL.

返回类型

str

_compute_feature_support_fields()[源代码]

Compute the feature support fields based on the provider.

Feature support fields are used to specify which additional features are supported by a given provider. These fields are as follows:

  • support_express_checkout: Whether the “express checkout” feature is supported. False by default.

  • support_manual_capture: Whether the “manual capture” feature is supported. False by default.

  • support_refund: Which type of the “refunds” feature is supported: None, 'full_only', or 'partial'. None by default.

  • support_tokenization: Whether the “tokenization feature” is supported. False by default.

For a provider to specify that it supports additional features, it must override this method and set the related feature support fields to the desired value on the appropriate payment.provider records.

返回

None

_find_available_payment_methods(partner_id, *, currency_id=None, force_tokenization=False, is_express_checkout=False, report=None, **_kwargs)[源代码]

Find the providers’ payment methods available for the given payment context.

参数
  • partner_id (int) – The partner making the payment, as a res.partner id

  • currency_id (int) – The payment currency, as a res.currency id

  • force_tokenization (bool) – Whether payment methods must support tokenization

  • is_express_checkout (bool) – Whether payment methods must support express checkout

  • report (dict) – The report into which availability statuses are to be logged

返回

The available payment methods

返回类型

payment.method

_find_available_providers(company_id, partner_id, amount, *, currency_id=None, force_tokenization=False, is_express_checkout=False, is_validation=False, report=None, **kwargs)[源代码]

Find the providers available for the given payment context.

参数
  • company_id (int) – The company to which providers must belong, as a res.company id

  • partner_id (int) – The partner making the payment, as a res.partner id

  • amount (float) – The amount to pay (0 for validation transactions)

  • currency_id (int) – The payment currency, as a res.currency id

  • force_tokenization (bool) – Whether providers must allow tokenization

  • is_express_checkout (bool) – Whether providers must allow express checkout

  • is_validation (bool) – Whether the operation is a validation

  • report (dict) – The report into which availability statuses are to be logged

  • kwargs (dict) – Forwarded to _is_tokenization_required and available to overrides

返回

The available providers

返回类型

payment.provider

_find_available_tokens(partner_id, **_kwargs)[源代码]

Find the providers’ tokens available for the given payment context.

参数

partner_id (int) – The partner making the payment, as a res.partner id

返回

The available tokens

返回类型

payment.token

_get_code()[源代码]

Return the code of the provider.

Note: self.ensure_one()

返回

The code of the provider.

返回类型

str

_get_default_payment_method_codes()[源代码]

Return the default payment methods for this provider.

Note: self.ensure_one()

返回

The default payment method codes.

返回类型

set

_get_pm_from_code(generic_code, mapping=None)[源代码]

Return the payment method with the given code linked to the provider.

If a mapping is given, the search uses the generic payment method code that corresponds to the given provider-specific code.

参数
  • generic_code (str) – The provider-specific code of the payment method to get

  • mapping (dict) – A non-exhaustive mapping of generic payment method codes to provider-specific codes

返回

The matching payment method, if any

返回类型

payment.method

_get_redirect_form_view(is_validation=False)[源代码]

Return the view of the template used to render the redirect form.

For a provider to return a different view depending on whether the operation is a validation, it must override this method and return the appropriate view.

Note: self.ensure_one()

参数

is_validation (bool) – Whether the operation is a validation.

返回

The view of the redirect form template.

返回类型

record of ir.ui.view

_get_provider_domain(provider_code, **_kwargs)[源代码]

Return the payment provider domain.

参数
  • provider_code (str) – The code of the provider to search for.

  • _kwargs (dict) – Additional keyword arguments.

返回

The domain to search for the provider.

返回类型

list[tuple]

_get_removal_values()[源代码]

Return the values to update a provider with when its module is uninstalled.

For a module to specify additional removal values, it must override this method and complete the generic values with its specific values.

返回

The removal values to update the removed provider with.

返回类型

dict

_get_supported_currencies()[源代码]

Return the supported currencies for the payment provider.

By default, all currencies are considered supported, including the inactive ones. For a provider to filter out specific currencies, it must override this method and return the subset of supported currencies.

Note: self.ensure_one()

返回

The supported currencies.

返回类型

res.currency

_get_validation_amount()[源代码]

Return the amount to use for validation operations.

For a provider to support tokenization, it must override this method and return the validation amount. If it is 0, it is not necessary to create the override.

Note: self.ensure_one()

返回

The validation amount.

返回类型

float

_get_validation_currency()[源代码]

Return the currency to use for validation operations.

The validation currency must be supported by both the provider and the payment method. If the payment method is not passed, only the provider’s supported currencies are considered. If no suitable currency is found, the provider’s company’s currency is returned instead.

For a provider to support tokenization and specify a different validation currency, it must override this method and return the appropriate validation currency.

Note: self.ensure_one()

返回

The validation currency.

返回类型

recordset of res.currency

_is_tokenization_required(**_kwargs)[源代码]

Return whether tokenizing the transaction is required given its context.

For a module to make the tokenization required based on the payment context, it must override this method and return whether it is required.

参数

_kwargs (dict) – The payment context

返回

Whether tokenizing the transaction is required

返回类型

bool

_parse_response_content(response, **_kwargs)[源代码]

Retrieve the JSON-formatted content of the response.

This method serves as a hook to allow providers to parse the response content.

参数
  • response (requests.Response) – The response to parse.

  • _kwargs (dict) – Provider-specific data.

返回

The response content.

返回类型

dict

_parse_response_error(response)[源代码]

Retrieve the error message from the response.

This method serves as a hook to allow providers to parse the response’s error message.

参数

response (requests.Response) – The response to parse.

返回

The error message.

返回类型

str

_send_api_request(method, endpoint, *, params=None, data=None, json=None, reference=None, **kwargs)[源代码]

Send a request to the API.

Whenever possible, calls to this method should be wrapped in a try-except block to prevent the ValidationError that is raised when the request fails from bubbling up. Exceptions to this rule include calls from a controller that must return the error message to the client.

Note: self.ensure_one()

参数
  • method (str) – The HTTP method of the request.

  • endpoint (str) – The endpoint of the API to reach with the request.

  • params (dict) – The query string parameters of the request.

  • data (dict|str) – The body of the request.

  • json (dict) – The JSON-formatted body of the request.

  • reference (str) – The reference of the transaction, if any.

  • kwargs (dict) – Provider-specific data forwarded to the specialized helper methods.

返回

The formatted content of the response.

返回类型

dict|str

引发

ValidationError – If an HTTP error occurs.