Skip to content

Conversation

@SamBachmann
Copy link
Contributor

@SamBachmann SamBachmann commented Jan 8, 2026

Related PR: T2853

Description:

This PR implements the secure addition and tokenization of modern payment methods (Credit/Debit cards, etc.) for recurring sponsorships on the MyCompassion 2.0 portal. It finalizes the work started in T2534 by connecting the frontend payment selection to the backend payment acquirer logic.

Key Changes:

  • Architectural Separation:

    • Compassion-website/my_compassion (Generic): Implements the generic flows for adding payment methods and handling user feedback (loading states, success/error messages), ensuring no region-specific logic leaks into the core module.

    • Compassion-switzerland/my_compassion (Specific): Contains the specific implementation for PostFinance Checkout, including API integrations for iframe embedding and transaction handling.

  • Payment Integration:

    • Iframe Integration: Integrates PostFinance Checkout to allow sponsors to add new payment methods via a secure iframe.

    • Token Management: Handles callback processing to create the payment token. Includes deduplication logic that queries the PostFinance API to prevent creating multiple tokens for the same payment instrument.

    • Contract Linking: Automatically creates or updates the partner's recurring.contract.group upon successful tokenization.

  • Recurring Billing & Invoicing:

    • Implements the backend logic to automatically charge the stored token for future invoices generated by the recurring contract groups.
    • Invoice Logic: Overrides _process_invoice_generation in the Swiss module to ensure correct payment terms and due dates are applied to automatically generated invoices.

⚠️ Still to be checked:

I got some changes requested by David the day I left, so I couldn't achieve to implement them / test them:
When a user change its payment method for a contract from a BVR/Recurring payment method to a tokenized one verify / implement the following

  • (Implement) : Warn the user that the not paid invoices previously emitted will be charged on the added card
  • (Verify): Check the code and test that there's the necessary logic in the code for that

Result :

Add Payment Methods Modal Add Payment Method List
Enter card data Success adding a card

Documentation:

As the processes are quite complex, I wrote some docs detailing the frontend-backend interactions and data flow.

…r a contract and to update differents groups of payment methods
@gemini-code-assist
Copy link

Summary of Changes

Hello @SamBachmann, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the MyCompassion 2.0 portal by introducing a robust system for managing recurring payment methods. It provides users with the ability to securely add new payment methods, such as credit/debit cards via PostFinance Checkout, and to easily change or update existing ones for their sponsorships. The changes involve a clear separation of concerns between generic and specific payment logic, alongside a revamped user interface for a more intuitive experience in handling recurring donations.

Highlights

  • Recurring Payment Method Integration: Implemented the secure addition and tokenization of modern payment methods (Credit/Debit cards) for recurring sponsorships on the MyCompassion 2.0 portal, specifically integrating PostFinance Checkout.
  • Architectural Separation: Separated generic payment method flows (Compassion-website/my_compassion) from specific PostFinance Checkout implementation (Compassion-switzerland/my_compassion), ensuring modularity and preventing region-specific logic from leaking into core modules.
  • Payment Method Management UI/UX: Introduced new UI components and modals for users to add, change, and update their recurring payment methods, including a secure iframe for online methods and handling of manual methods like BVR/Permanent Order.
  • Backend Logic for Payment Groups: Developed comprehensive backend logic in recurring.contract.group and my2_donations.py to manage payment tokens, create contract groups from transactions, and facilitate changing or merging payment methods for sponsorships.
  • Enhanced Sponsorships Section: Refactored the 'My Sponsorships' section to dynamically display sponsorships grouped by their payment methods, allowing for server-side re-rendering via AJAX calls for a smoother user experience.
  • Debug Functionality: Added a debug route (/my2/debug/charge_token) to allow developers to trigger a test charge on a token linked to a contract group, aiding in testing and development.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link

Summary of Changes

Hello @SamBachmann, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request completes the integration of recurring payment methods for the MyCompassion 2.0 portal, focusing on secure tokenization and automated billing. It introduces a robust architectural separation between generic and region-specific payment logic, primarily implementing PostFinance Checkout. Users can now manage their payment methods through a redesigned and interactive interface, improving the overall sponsorship experience.

Highlights

  • Modern Payment Method Integration: This PR introduces the capability to securely add and tokenize modern payment methods, such as Credit/Debit cards, for recurring sponsorships on the MyCompassion 2.0 portal. It specifically integrates with PostFinance Checkout for online payment processing.
  • Architectural Separation for Scalability: The codebase has been refactored to separate generic payment flows (in Compassion-website/my_compassion) from region-specific implementations (e.g., PostFinance Checkout in Compassion-switzerland/my_compassion). This ensures a cleaner architecture and prevents region-specific logic from affecting core modules.
  • Enhanced Recurring Billing Logic: Backend logic has been implemented to automatically charge stored payment tokens for future invoices generated by recurring contract groups, streamlining the billing process for sponsors.
  • User Interface for Payment Management: New modals and UI components have been added to the MyCompassion 2.0 donations page, allowing users to easily add new payment methods via a secure iframe, change payment methods for existing sponsorships, and update details of their payment groups.
  • Refactored Frontend JavaScript: The my2_donations.js file has been significantly refactored into a public widget, enhancing modularity and maintainability. It now handles complex interactions for payment method selection, addition, and updates, including dynamic loading of PostFinance iframes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant and well-architected feature for managing recurring payment methods with PostFinance. The separation of concerns, use of modern Odoo frontend patterns for AJAX updates, and robust backend logic are commendable. My review focuses on removing debug artifacts that pose a security risk in a production environment, along with minor suggestions to improve code style, consistency, and maintainability. Overall, this is a solid implementation.

@SamBachmann
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant enhancements to the 'My Donations' portal page, primarily focusing on managing payment methods for sponsorships. Key changes include adding new UI components for payment method selection and management, such as modals for updating, changing, and adding payment methods. The backend now supports grouping sponsorships by payment method, fetching payment method details, and new API endpoints for modifying contract groups and individual contracts' payment methods. It also integrates with external payment providers like PostFinance via iframes for adding new online payment methods. Additionally, the definition of 'active' sponsorships has been expanded to include the 'mandate' state across various models and controllers. Review comments highlight potential N+1 query issues in fetching payment icons and payment modes, suggest refining broad exception handling, and recommend improving the user experience by using the existing toast service instead of native alerts and avoiding full page reloads as a primary UI update mechanism. There's also a suggestion to dynamically fetch manual payment options instead of hardcoding them in templates.

Comment on lines +58 to +65
<select class="form-control" name="method_type" id="new_method_type">
<option value="" disabled="disabled" selected="selected">
Select a method...
</option>
<option value="permanent_order">Permanent Order</option>
<option value="bvr">BVR</option>
</select>
</t>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The options for manual payment methods ("Permanent Order" and "BVR") are hardcoded directly in the QWeb template. If the available manual payment methods change or new ones are introduced in the future, this template will require manual modification.

For better maintainability and flexibility, consider fetching these options dynamically from the backend. This would allow administrators to manage payment methods without code changes.

@SamBachmann
Copy link
Contributor Author

/gemini review

@SamBachmann SamBachmann marked this pull request as ready for review January 14, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants