Payment Transaction

class odoo.addons.payment.models.payment_transaction.PaymentTransaction[código fonte]
_compute_reference(provider_code, prefix=None, separator='-', **kwargs)[código fonte]

Compute a unique reference for the transaction.

The reference corresponds to the prefix if no other transaction with that prefix already exists. Otherwise, it follows the pattern {computed_prefix}{separator}{sequence_number} where:

  • {computed_prefix} is:

    • The provided custom prefix, if any.

    • The computation result of _compute_reference_prefix() if the custom prefix is not filled, but the kwargs are.

    • 'tx-{datetime}' if neither the custom prefix nor the kwargs are filled.

  • {separator} is the string that separates the prefix from the sequence number.

  • {sequence_number} is the next integer in the sequence of references sharing the same prefix. The sequence starts with 1 if there is only one matching reference.

Example

  • Given the custom prefix 'example' which has no match with an existing reference, the full reference will be 'example'.

  • Given the custom prefix 'example' which matches the existing reference 'example', and the custom separator '-', the full reference will be 'example-1'.

  • Given the kwargs {'invoice_ids': [1, 2]}, the custom separator '-' and no custom prefix, the full reference will be 'INV1-INV2' (or similar) if no existing reference has the same prefix, or 'INV1-INV2-n' if n existing references have the same prefix.

Parâmetros
  • provider_code (str) – The code of the provider handling the transaction.

  • prefix (str) – The custom prefix used to compute the full reference.

  • separator (str) – The custom separator used to separate the prefix from the suffix.

  • kwargs (dict) – Optional values passed to _compute_reference_prefix() if no custom prefix is provided.

Retorna

The unique reference for the transaction.

Tipo de retorno

str

_compute_reference_prefix(provider_code, separator, **values)[código fonte]

Compute the reference prefix from the transaction values.

Note: This method should be called in sudo mode to give access to the documents (invoices, sales orders) referenced in the transaction values.

Parâmetros
  • provider_code (str) – The code of the provider handling the transaction.

  • separator (str) – The custom separator used to separate parts of the computed reference prefix.

  • values (dict) – The transaction values used to compute the reference prefix.

Retorna

The computed reference prefix.

Tipo de retorno

str

_get_post_processing_values()[código fonte]

Return a dict of values used to display the status of the transaction.

For a provider to handle transaction status display, it must override this method and return a dict of values. Provider-specific values take precedence over those of the dict of generic post-processing values.

The returned dict contains the following entries:

  • provider_code: The code of the provider.

  • provider_name: The name of the provider.

  • reference: The reference of the transaction.

  • amount: The rounded amount of the transaction.

  • currency_id: The currency of the transaction, as a res.currency id.

  • state: The transaction state: draft, pending, authorized, done, cancel, or error.

  • state_message: The information message about the state.

  • operation: The operation of the transaction.

  • is_post_processed: Whether the transaction has already been post-processed.

  • landing_route: The route the user is redirected to after the transaction.

  • Additional provider-specific entries.

Note: self.ensure_one()

Retorna

The dict of processing values.

Tipo de retorno

dict

_get_specific_create_values(provider_code, values)[código fonte]

Complete the values of the create method with provider-specific values.

For a provider to add its own create values, it must overwrite this method and return a dict of values. Provider-specific values take precedence over those of the dict of generic create values.

Parâmetros
  • provider_code (str) – The code of the provider that handled the transaction.

  • values (dict) – The original create values.

Retorna

The dict of provider-specific create values.

Tipo de retorno

dict

_get_specific_processing_values(processing_values)[código fonte]

Return a dict of provider-specific values used to process the transaction.

For a provider to add its own processing values, it must overwrite this method and return a dict of provider-specific values based on the generic values returned by this method. Provider-specific values take precedence over those of the dict of generic processing values.

Parâmetros

processing_values (dict) – The generic processing values of the transaction.

Retorna

The dict of provider-specific processing values.

Tipo de retorno

dict

_get_specific_rendering_values(processing_values)[código fonte]

Return a dict of provider-specific values used to render the redirect form.

For a provider to add its own rendering values, it must overwrite this method and return a dict of provider-specific values based on the processing values (provider-specific processing values included).

Parâmetros

processing_values (dict) – The processing values of the transaction.

Retorna

The dict of provider-specific rendering values.

Tipo de retorno

dict

_get_tx_from_notification_data(provider_code, notification_data)[código fonte]

Find the transaction based on the notification data.

For a provider to handle transaction processing, it must overwrite this method and return the transaction matching the notification data.

Parâmetros
  • provider_code (str) – The code of the provider handling the transaction.

  • notification_data (dict) – The notification data sent by the provider.

Retorna

The transaction, if found.

Tipo de retorno

recordset of payment.transaction

_handle_notification_data(provider_code, notification_data)[código fonte]

Match the transaction with the notification data, update its state and return it.

Parâmetros
  • provider_code (str) – The code of the provider handling the transaction.

  • notification_data (dict) – The notification data sent by the provider.

Retorna

The transaction.

Tipo de retorno

recordset of payment.transaction

_process_notification_data(notification_data)[código fonte]

Update the transaction state and the provider reference based on the notification data.

This method should usually not be called directly. The correct method to call upon receiving notification data is _handle_notification_data().

For a provider to handle transaction processing, it must overwrite this method and process the notification data.

Note: self.ensure_one()

Parâmetros

notification_data (dict) – The notification data sent by the provider.

Retorna

None

_send_capture_request(amount_to_capture=None)[código fonte]

Request the provider handling the transaction to capture the payment.

For partial captures, create a child transaction linked to the source transaction.

For a provider to support authorization, it must override this method and make an API request to capture the payment.

Note: self.ensure_one()

Parâmetros

amount_to_capture (float) – The amount to capture.

Retorna

The created capture child transaction, if any.

Tipo de retorno

payment.transaction

_send_payment_request()[código fonte]

Request the provider handling the transaction to make the payment.

This method is exclusively used to make payments by token, which correspond to both the online_token and the offline transaction’s operation field.

For a provider to support tokenization, it must override this method and make an API request to make a payment.

Note: self.ensure_one()

Retorna

None

_send_refund_request(amount_to_refund=None)[código fonte]

Request the provider handling the transaction to refund it.

For a provider to support refunds, it must override this method and make an API request to make a refund.

Note: self.ensure_one()

Parâmetros

amount_to_refund (float) – The amount to be refunded.

Retorna

The refund transaction created to process the refund request.

Tipo de retorno

recordset of payment.transaction

_send_void_request(amount_to_void=None)[código fonte]

Request the provider handling the transaction to void the payment.

For partial voids, create a child transaction linked to the source transaction.

For a provider to support authorization, it must override this method and make an API request to void the payment.

Note: self.ensure_one()

Parâmetros

amount_to_void (float) – The amount to be voided.

Retorna

The created void child transaction, if any.

Tipo de retorno

payment.transaction

_set_authorized(state_message=None, extra_allowed_states=())[código fonte]

Update the transactions’ state to authorized.

Parâmetros
  • state_message (str) – The reason for setting the transactions in the state authorized.

  • extra_allowed_states (tuple[str]) – The extra states that should be considered allowed target states for the source state ‘authorized’.

Retorna

The updated transactions.

Tipo de retorno

recordset of payment.transaction

_set_canceled(state_message=None, extra_allowed_states=())[código fonte]

Update the transactions’ state to cancel.

Parâmetros
  • state_message (str) – The reason for setting the transactions in the state cancel.

  • extra_allowed_states (tuple[str]) – The extra states that should be considered allowed target states for the source state ‘canceled’.

Retorna

The updated transactions.

Tipo de retorno

recordset of payment.transaction

_set_done(state_message=None, extra_allowed_states=())[código fonte]

Update the transactions’ state to done.

Parâmetros
  • state_message (str) – The reason for setting the transactions in the state done.

  • extra_allowed_states (tuple[str]) – The extra states that should be considered allowed target states for the source state ‘done’.

Retorna

The updated transactions.

Tipo de retorno

recordset of payment.transaction

_set_error(state_message, extra_allowed_states=())[código fonte]

Update the transactions’ state to error.

Parâmetros
  • state_message (str) – The reason for setting the transactions in the state error.

  • extra_allowed_states (tuple[str]) – The extra states that should be considered allowed target states for the source state ‘error’.

Retorna

The updated transactions.

Tipo de retorno

recordset of payment.transaction

_set_pending(state_message=None, extra_allowed_states=())[código fonte]

Update the transactions’ state to pending.

Parâmetros
  • state_message (str) – The reason for setting the transactions in the state pending.

  • extra_allowed_states (tuple[str]) – The extra states that should be considered allowed target states for the source state ‘pending’.

Retorna

The updated transactions.

Tipo de retorno

recordset of payment.transaction