Skip to content

feat(payment-methods): [Proxy] add saved card flow for proxy payments#8964

Merged
bernard-eugine merged 48 commits intomainfrom
saved_card_proxy
Aug 20, 2025
Merged

feat(payment-methods): [Proxy] add saved card flow for proxy payments#8964
bernard-eugine merged 48 commits intomainfrom
saved_card_proxy

Conversation

@Sakilmostak
Copy link
Contributor

@Sakilmostak Sakilmostak commented Aug 14, 2025

Type of Change

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

Description

Add saved card flow for proxy payments:

  • Card metadata is collected in the request along with tokens (bin_number and last_four digits for Card Number)
  • Card Bin API is used to fetch data against card like card_network and issuer using bin number
  • Card metadata is stored in payment method table along with tokens
  • This component works along with Proxy Payments (needs confirm-intent/external-vault-proxy)
  • Internally no locker is used since we don't store raw card data
  • Data for subsequent payments (tokens) are fetched from payment method table
  • Only cvc and card_holder_name is collected in subsequent payment with saved card

Additional Changes

  • This PR modifies the API contract
    First payment to save card in confirm-intent/external-vault-proxy:
"payment_method_data": {
        "vault_data_card": {
            "card_number": "tok_sandbox_ZgPN54WU8y8tDjc6qfEs",
            "card_exp_month": "04",
            "card_exp_year": "29",
            "card_cvc": "tok_sandbox_3EniLX4zKbwxV1PPZFopd",
            "bin_number": "424242",
            "last_four": "4242",
            "card_holder_name": "john doe"
        }
    },

Subsequent payment with saved card in confirm-intent/external-vault-proxy:

"payment_method_data": {
        "vault_token": {
            "card_cvc": "737"
        }
    },
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

This PR is dependent in proxy module. Need the whole module to be present for testing.

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

@Sakilmostak Sakilmostak self-assigned this Aug 14, 2025
@Sakilmostak Sakilmostak requested review from a team as code owners August 14, 2025 11:58
@Sakilmostak Sakilmostak added the A-core Area: Core flows label Aug 14, 2025
@Sakilmostak Sakilmostak requested a review from a team as a code owner August 14, 2025 11:58
@Sakilmostak Sakilmostak added C-feature Category: Feature request or enhancement A-payment-methods Area: Payment Methods M-api-contract-changes Metadata: This PR involves API contract changes labels Aug 14, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Aug 14, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/operations/payment_confirm_intent.rs  100% smaller
  crates/router/src/core/payment_methods/vault.rs  92% smaller
  crates/router/src/types/api/payment_methods.rs  86% smaller
  crates/hyperswitch_domain_models/src/vault.rs  32% smaller
  crates/api_models/src/payments.rs  11% smaller
  crates/openapi/src/openapi_v2.rs  9% smaller
  crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs  6% smaller
  crates/hyperswitch_domain_models/src/payment_method_data.rs  6% smaller
  crates/router/src/core/payment_methods.rs  1% smaller
  api-reference/v2/openapi_spec_v2.json  0% smaller
  crates/api_models/src/payment_methods.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/diesel_models/src/payment_method.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/hyperswitch_domain_models/src/payment_methods.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  0% smaller
  crates/router/src/core/payments.rs  0% smaller
  crates/router/src/core/payments/operations.rs  0% smaller
  crates/router/src/core/unified_connector_service.rs  0% smaller
  v2_compatible_migrations/2025-07-29-080133_add-external_vault_token_data-column-to-payment-methods/down.sql Unsupported file format
  v2_compatible_migrations/2025-07-29-080133_add-external_vault_token_data-column-to-payment-methods/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Aug 14, 2025
Comment on lines +360 to +362
let payment_method_id = common_utils::id_type::GlobalPaymentMethodId::generate(
&state.conf.cell_information.id,
)
Copy link
Contributor

@prasunna09 prasunna09 Aug 18, 2025

Choose a reason for hiding this comment

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

do not generate pm id in payments service. this should be handled by pm service only

Base automatically changed from add-confirm-proxy-flow to main August 18, 2025 11:23
pub struct ProxyCardDetails {
/// Tokenized Card Number
#[schema(value_type = String,example = "4111111145551142")]
pub card_number: masking::Secret<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

we ll have to ensure actual card raw num is not stored in pm entry.
may be we can do a luhn check before storing in pm table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im taking it in a separate pr

payment_data.payment_attempt.customer_acceptance.is_some(),
payment_data.payment_attempt.payment_method_id.clone(),
) {
payment_methods::update_payment_method_status_internal(
Copy link
Contributor

Choose a reason for hiding this comment

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

We ll have to introduce a new endpoint to activate the pm for internal use, instead payments directly calling update fn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a issue that could be picked up https://github.com/juspay/hyperswitch-cloud/issues/10702

prasunna09
prasunna09 previously approved these changes Aug 18, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Aug 18, 2025
}

pub fn is_success(self) -> bool {
matches!(self, Self::Charged | Self::PartialCharged)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should update payment method to active if Authentication is successful and other successful status. Even in psync flow, the update payment method should happen
We can pick this up in a seperate pr.

@Sakilmostak Sakilmostak changed the title feat(payment-methods): [Proxy] add saved card flow for proxy payemnts feat(payment-methods): [Proxy] add saved card flow for proxy payments Aug 20, 2025
@bernard-eugine bernard-eugine added this pull request to the merge queue Aug 20, 2025
Merged via the queue into main with commit 73dfa5e Aug 20, 2025
25 of 29 checks passed
@bernard-eugine bernard-eugine deleted the saved_card_proxy branch August 20, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: Core flows A-payment-methods Area: Payment Methods C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants