WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Nov 27, 2025

Type of Change

  • New feature
  • Bugfix
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR introduces provider context support for Payment Methods, extending the platform-connected model that already exists for customers. The objective is to ensure that payment methods are consistently treated as platform-owned resources, while still allowing connected merchants within the same organization to access and use them.

Key Changes

1. Provider Context for Payment Methods

  • Payment methods are now associated with the provider merchant (Platform) rather than the connected merchant that performs the operation.
  • All connected merchants under the same platform organization can access the shared pool of payment methods.
  • Eliminates duplicated payment methods across connected merchants.
  • Platform merchants can operate:
    • With X-Connected-Merchant-Id header (acting on behalf of a connected merchant).
    • Without the header (acting as the platform itself).

2. Provider / Processor Role Separation

  • Provider (Platform Merchant) owns shared resources such as payment methods and customers.
  • Processor (Connected or Platform Merchant) is used only for transaction processing.
  • This PR ensures payment method operations consistently use provider context, without altering processor-related behavior.

3. Updated Payment Method Endpoints

  • All v1/v2 CRUD endpoints and attach/detach routes now resolve provider context before executing business logic.
  • Authentication flags for v1 payment method endpoints updated to:
is_connected_allowed: true
is_platform_allowed: true
  • Removed legacy assumptions where payment methods were tied to the processor merchant.

4. Core Refactoring

  • Updated domain models and validation logic to carry provider-related fields.
  • Centralized provider context resolution for all payment method operations.

5. Webhook and Compatibility Adjustments

  • Incoming webhook handlers updated to resolve provider context consistently.
  • Stripe compatibility layer updated to support platform-owned payment methods.
  • Ensures webhook-originated updates operate under the provider model.

Scope Clarification (Important)

This PR does not include:

  • Account-PML filtering based on processor merchant capabilities
  • Customer-PML filtering based on supported payment methods
  • SDK changes for sending connected merchant context
  • 3DS or callback-based connected context handling

These enhancements will be implemented in follow-up PRs.


Motivation and Context

Problems Addressed

  1. Payment methods were owned by individual connected merchants, causing duplication and fragmentation.
  2. Provider context was inconsistently handled across payment method operations.
  3. Platform merchants lacked proper visibility and operational consistency.
  4. Payment method behavior did not match the customer-sharing model already in place.

Solution Summary

  1. Introduced provider-context ownership for payment methods.
  2. Centralized and unified provider context resolution across all payment method operations.
  3. Enabled connected merchants to access shared platform-owned payment methods.
  4. Aligned payment methods with the customer-sharing model for consistency across the platform organization.

APIs Affected

  • POST /payment_methods (v1, v2)
  • GET /payment_methods/:id (v1, v2)
  • GET /payment_methods (list) (v1, v2)
  • PATCH /payment_methods/:id (v1, v2)
  • DELETE /payment_methods/:id (v1, v2)
  • Attach/Detach operations
  • Tokenization flows involving payment method ownership

Diagram: Current (Incorrect) Merchant-Scoped Model

Image

Diagram: Proposed Platform-Scoped Model

image

How did you test it?

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

…onality

This change introduces provider context support throughout the payment methods
module, enabling better handling of provider-specific configurations and
enhancing the flexibility of payment method operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@tsdk02 tsdk02 requested review from a team as code owners November 27, 2025 19:33
@semanticdiff-com
Copy link

semanticdiff-com bot commented Nov 27, 2025

@tsdk02 tsdk02 self-assigned this Nov 27, 2025
@tsdk02 tsdk02 added A-core Area: Core flows T-Core For Work done by the core team platform labels Nov 27, 2025
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

❌ Patch coverage is 0% with 95 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@8e33f24). Learn more about missing BASE report.

Files with missing lines Patch % Lines
crates/router/src/core/payment_methods.rs 0.00% 37 Missing ⚠️
crates/router/src/routes/payment_methods.rs 0.00% 35 Missing ⚠️
crates/router/src/core/customers.rs 0.00% 8 Missing ⚠️
crates/router/src/core/payments/payment_methods.rs 0.00% 6 Missing ⚠️
crates/router/src/core/payment_methods/cards.rs 0.00% 5 Missing ⚠️
crates/router/src/routes/customers.rs 0.00% 2 Missing ⚠️
...ment_methods/src/core/migration/payment_methods.rs 0.00% 1 Missing ⚠️
crates/router/src/core/payment_methods/vault.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10458   +/-   ##
=======================================
  Coverage        ?    6.46%           
=======================================
  Files           ?     1251           
  Lines           ?   311788           
  Branches        ?        0           
=======================================
  Hits            ?    20164           
  Misses          ?   291624           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tsdk02 tsdk02 changed the title feat(platform): Add provider context to payment methods feat(platform): implement payment method sharing model for platform-connected setup Nov 28, 2025
Copy link
Contributor

@apoorvdixit88 apoorvdixit88 left a comment

Choose a reason for hiding this comment

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

We can consider making wrapper wherever we are making direct db call with platform.

let mut updated_card_expiry = false;

let payment_method = db
.find_payment_method(
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we can consider making the wrapper, i think its already there in the get_tracker PR, we can use the same.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will take this up in a separate PR, once the wrapper setup is finalized

let response = db
.update_payment_method(
platform.get_processor().get_key_store(),
platform.get_provider().get_key_store(),
Copy link
Contributor

Choose a reason for hiding this comment

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

here as well we can consider making platform wrapper.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will take this up in a separate PR, once the wrapper setup is finalized

jarnura
jarnura previously approved these changes Dec 3, 2025
let mut updated_card_expiry = false;

let payment_method = db
.find_payment_method(
Copy link
Member

Choose a reason for hiding this comment

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

+1

let response = db
.update_payment_method(
platform.get_processor().get_key_store(),
platform.get_provider().get_key_store(),
Copy link
Member

Choose a reason for hiding this comment

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

+1

Sakilmostak
Sakilmostak previously approved these changes Dec 3, 2025
ShankarSinghC
ShankarSinghC previously approved these changes Dec 3, 2025

#[cfg(feature = "v1")]
let payment_intent = db
.find_payment_intent_by_payment_id_merchant_id(
Copy link
Contributor

@apoorvdixit88 apoorvdixit88 Dec 4, 2025

Choose a reason for hiding this comment

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

Wrapper needed, and we need to check working of this function, in this flow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified this to use processor, queries also need to be changed later to query on processor_merchant_id.

Wrappers will be added in a subsequent PR.

customer_id,
&payment_method_id,
Some(stored_resp.card_reference.clone()),
platform.get_processor().get_account().get_id(),
Copy link
Contributor

Choose a reason for hiding this comment

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

won't it be provider?

Copy link
Contributor Author

@tsdk02 tsdk02 Dec 4, 2025

Choose a reason for hiding this comment

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

Yes, it should be. But this change was done only to remove the error as I had changed platform to provider in PmCards struct.

I haven't touched this flow yet, as it comes under payouts.
Will modify this in a separate PR when working on adding the provider context in payouts.

prasunna09
prasunna09 previously approved these changes Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: Core flows platform T-Core For Work done by the core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants