Odoo 18: payment.transaction set to 'done' but payment not created and is_post_processed remains False while using custom online payment gateway

Odoo 18: payment.transaction set to 'done' but payment not created and is_post_processed remains False while using custom online payment gateway
typescript
Ethan Jackson

I am developing a odoo18 custom payment provider. After a successful transaction and return response to odoo. When it comes to update the transaction status to done using tx._set_done() this only change the status to done however it still not creating payment and ransaction still remaining with status confirmed.

Below is my code portion for changing status to done

*if self.state != 'done': if status == 'COMPLETED': self._set_done() elif status in ('FAILED', 'CANCELED'): self._set_error("Square Payment Failed or Cancelled.") else: self._set_pending()*

I want Odoo 18 to behave like standard providers (Stripe, PayPal), where:

When the callback marks a transaction as 'done'

A corresponding account.payment is automatically created

The invoice or sales order is marked as paid

tx.is_post_processed becomes True

Answer

# Assuming 'tx' is your payment.transaction record # and 'status' is derived from your gateway's callback response if status == 'COMPLETED': if tx.state != 'done': # Check if not already done to prevent re-processing tx._set_done() # --- Crucial step: Trigger post-processing --- try: tx._post_process_tx() except Exception as e: # Handle potential errors during post-processing _logger.error("Error during payment transaction post-processing for tx %s: %s", tx.reference, e) tx._set_error(f"Post-processing failed: {e}") return False # Or handle as appropriate for your gateway's response elif status in ('FAILED', 'CANCELLED'): # Assuming you have similar states # ... your existing logic for failed/cancelled ... tx._set_error("Payment failed or cancelled.") # No post-processing for failed transactions else: tx._set_pending() # Assuming 'tx' is your payment.transaction record # and 'status' is derived from your gateway's callback response if status == 'COMPLETED': if tx.state != 'done': # Check if not already done to prevent re-processing tx._set_done() # --- Crucial step: Trigger post-processing --- try: tx._post_process_tx() except Exception as e: # Handle potential errors during post-processing _logger.error("Error during payment transaction post-processing for tx %s: %s", tx.reference, e) tx._set_error(f"Post-processing failed: {e}") return False # Or handle as appropriate for your gateway's response elif status in ('FAILED', 'CANCELLED'): # Assuming you have similar states # ... your existing logic for failed/cancelled ... tx._set_error("Payment failed or cancelled.") # No post-processing for failed transactions else: tx._set_pending()

Related Articles