Skip to content

feat(router): Add support for updating wallet pm_data to PM update API#9388

Merged
likhinbopanna merged 8 commits intomainfrom
pm-update-api-wallet
Nov 3, 2025
Merged

feat(router): Add support for updating wallet pm_data to PM update API#9388
likhinbopanna merged 8 commits intomainfrom
pm-update-api-wallet

Conversation

@AnuthaDev
Copy link
Contributor

@AnuthaDev AnuthaDev commented Sep 15, 2025

Type of Change

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

Description

  • Added support for updating payment_method_data in case the payment_method_type is wallet.
  • Added new response type: CustomerPaymentMethodUpdateResponse to include the wallet details being updated in response

For wallets the following fields can be updated:

  • last4
  • card_network
  • type

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Closes #9387

How did you test it?

Request:

curl --location 'http://localhost:8080/payment_methods/pm_FiEUWFVVyrcdp6o2NW4T/update' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_x85W6hQprLRMbeArLC7rFicIiZRBWelCJCNV8a4Lf2kq2tgCfoHw9LvMRrQ4tn8D' \
--data '{
  "wallet": {
    "last4": "1024",
    "card_network": "Visa",
    "type": "credit"
  }
}'

Response:

{
    "merchant_id": "merchant_1759320450",
    "customer_id": "customer123",
    "payment_method_id": "pm_FiEUWFVVyrcdp6o2NW4T",
    "payment_method": "wallet",
    "payment_method_type": "apple_pay",
    "card": null,
    "wallet": {
      "last4": "1024",
      "card_network": "Visa",
      "type": "credit"
    }
    "recurring_enabled": false,
    "installment_payment_enabled": false,
    "payment_experience": [
        "redirect_to_url"
    ],
    "metadata": null,
    "created": "2025-10-01T12:10:05.824Z",
    "last_used_at": "2025-10-06T08:37:30.787Z",
    "client_secret": "pm_FiEUWFVVyrcdp6o2NW4T_secret_9o1ejWTPIzRzn4WdfoGm"
}

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

@AnuthaDev AnuthaDev self-assigned this Sep 15, 2025
@AnuthaDev AnuthaDev requested a review from a team as a code owner September 15, 2025 12:33
@AnuthaDev AnuthaDev added the enhancement New feature or request label Sep 15, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Sep 15, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/types/api/payment_methods.rs  81% smaller
  crates/api_models/src/events/payment.rs  26% smaller
  crates/router/src/core/payment_methods/cards.rs  16% smaller
  crates/openapi/src/openapi.rs  7% smaller
  api-reference/v1/openapi_spec_v1.json  0% smaller
  crates/api_models/src/payment_methods.rs  0% smaller

.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to update payment method in db")?;

Copy link
Contributor

Choose a reason for hiding this comment

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

Can all the changes be accommodated in a single update DB call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to have a single DB call for both card and wallet branches leads to convoluted code for response generation. It is cleaner to have 2 DB calls, contained within their branches.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can return storage::PaymentMethodUpdate from each of the branches and call update_payment_method once.

Copy link
Contributor

@kashif-m kashif-m left a comment

Choose a reason for hiding this comment

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

Added minor comments around refactoring the flow

@AnuthaDev AnuthaDev requested a review from a team as a code owner September 17, 2025 07:30
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Sep 17, 2025
kashif-m
kashif-m previously approved these changes Sep 22, 2025
@AnuthaDev AnuthaDev dismissed stale reviews from su-shivanshmathur and kashif-m via 7f6d03b October 27, 2025 06:30
@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

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

Files with missing lines Patch % Lines
crates/api_models/src/events/payment.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9388   +/-   ##
=======================================
  Coverage        ?    3.92%           
=======================================
  Files           ?     1223           
  Lines           ?   300980           
  Branches        ?        0           
=======================================
  Hits            ?    11803           
  Misses          ?   289177           
  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.

@AnuthaDev AnuthaDev requested a review from a team as a code owner October 27, 2025 06:49
kashif-m
kashif-m previously approved these changes Oct 27, 2025
Comment on lines +1643 to +1651
let pm = db
.find_payment_method(
&((&state).into()),
merchant_context.get_merchant_key_store(),
payment_method_id,
merchant_context.get_merchant_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we can fetch this after validating the client secret?

.into());
}

let updated_pmd = PaymentMethodsData::WalletDetails(wallet_update);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:

Can we handle this similarly to how it's handled for cards [ref]

We should be able to update individual fields for wallet data (last4, card_type)

@@ -481,6 +481,9 @@ pub struct PaymentMethodUpdate {
"card_holder_name": "John Doe"}))]
pub card: Option<CardDetailUpdate>,
Copy link
Contributor

Choose a reason for hiding this comment

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

PaymentMethodUpdate should be an enum. We shouldn't allow passing both card and wallet fields during update right?

@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 3, 2025
Merged via the queue into main with commit 2c3fa82 Nov 3, 2025
28 of 32 checks passed
@likhinbopanna likhinbopanna deleted the pm-update-api-wallet branch November 3, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for updating wallet pm_data to PM update API

5 participants