Skip to content

Conversation

kashif-m
Copy link
Contributor

@kashif-m kashif-m commented Jun 26, 2025

Type of Change

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

Description

This pull request enhances the data migration API to support migrating customer and payment method data across multiple business profiles in a single request.

Specifically, the following changes have been made:

  1. Customer Data Migration:

    • Updated PaymentMethodRecord to allow merchant_connector_id to accept comma-separated string values.
    • Modified PaymentMethodCustomerMigrate to use a Vec of connector-specific customer details.
    • The TryFrom<PaymentMethodRecord> implementation for PaymentMethodCustomerMigrate has been updated to parse this comma-separated string.
  2. Payment Method Migration:

    • Updated PaymentMethodsMigrateForm to accept a comma-separated string for merchant_connector_id.
    • The get_payment_method_records and migrate_payment_methods functions are updated to process multiple merchant_connector_ids.
    • The TryFrom implementation for PaymentMethodMigrate is modified to create a PaymentsMandateReference for each merchant_connector_id provided.

Additional Changes

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

Motivation and Context

This allows migrating a payment method entity across multiple profiles (as MerchantConnectorAccountId is tied to a profile) during batch migration.

How did you test it?

1. Batch migration for multiple profiles

cURL

curl --location --request POST 'http://localhost:8080/payment_methods/migrate-batch' \
    --header 'api-key: test_admin' \
    --form 'merchant_id="merchant_1751020165"' \
    --form 'merchant_connector_ids="mca_lwpasOxD1FtFmG4SVdjX,mca_4tsKLvIinX1uVL8p9mhy"' \
    --form 'file=@"migrate.csv"'

Response

[{"line_number":1,"payment_method_id":"pm_AO2rTJwFIH0I9yQiZ0zT","payment_method":"card","payment_method_type":"debit","customer_id":"45CC60D1F2283097BB1DE41A2636414445908518D50B8B4CDC57959CD7FB4539","migration_status":"Success","card_number_masked":"4360000 xxxx 0005","card_migrated":null,"network_token_migrated":true,"connector_mandate_details_migrated":true,"network_transaction_id_migrated":null},{"line_number":2,"payment_method_id":"pm_ZN9z4oKF439uxyBerwfL","payment_method":"card","payment_method_type":"credit","customer_id":"782BC898951D910C1A99DA69A4E4FAD6CEE53AB9311FA2C552028DA89428DB7F","migration_status":"Success","card_number_masked":"4111111 xxxx 1111","card_migrated":null,"network_token_migrated":true,"connector_mandate_details_migrated":true,"network_transaction_id_migrated":null}]

Things to verify in DB

  1. connector_mandate_details for a given payment_method_id in response has connector_mandate_id for multiple MCAs
Screenshot 2025-06-28 at 3 09 18 PM
  1. connector_customer for a given customer_id in response has mappings for multiple MCAs
Screenshot 2025-06-28 at 3 09 41 PM
2. Batch migration for a single profile - For ensuring backwards compatibility

cURL

curl --location --request POST 'http://localhost:8080/payment_methods/migrate-batch' \
    --header 'api-key: test_admin' \
    --form 'merchant_id="merchant_1751020165"' \
    --form 'merchant_connector_id="mca_lwpasOxD1FtFmG4SVdjX"' \
    --form 'file=@"migrate.csv"'

Response

[{"line_number":1,"payment_method_id":"pm_ZGPPsRrU5f4IgVpMS9tj","payment_method":"card","payment_method_type":"debit","customer_id":"45CC60D1F2283097BB1DE41A2636414445908518D50B8B4CDC57959CD7FB4539","migration_status":"Success","card_number_masked":"4360000 xxxx 0005","card_migrated":null,"network_token_migrated":true,"connector_mandate_details_migrated":true,"network_transaction_id_migrated":null},{"line_number":2,"payment_method_id":"pm_Lf2vcheQkYIiZx8PIDHt","payment_method":"card","payment_method_type":"credit","customer_id":"782BC898951D910C1A99DA69A4E4FAD6CEE53AB9311FA2C552028DA89428DB7F","migration_status":"Success","card_number_masked":"4111111 xxxx 1111","card_migrated":null,"network_token_migrated":true,"connector_mandate_details_migrated":true,"network_transaction_id_migrated":null}]

Things to verify in DB

  • PM migration happens for a single MCA (connector_mandate_details)
  • Customer migration happens for a single MCA (connector_customer)

Sample migration data for multi profile migration
multi-migrate-sample.csv

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

Copy link

semanticdiff-com bot commented Jun 26, 2025

@kashif-m kashif-m linked an issue Jun 28, 2025 that may be closed by this pull request
2 tasks
@kashif-m kashif-m force-pushed the 8464-feature-allow-data-migration-at-profile-level branch 2 times, most recently from 8b48cee to bb9e2fa Compare June 28, 2025 09:30
@kashif-m kashif-m self-assigned this Jun 28, 2025
@kashif-m kashif-m added the A-payment-methods Area: Payment Methods label Jun 28, 2025
@kashif-m kashif-m marked this pull request as ready for review June 28, 2025 09:44
@kashif-m kashif-m requested review from a team as code owners June 28, 2025 09:44
@kashif-m kashif-m requested a review from jagan-jaya June 30, 2025 07:00
jagan-jaya
jagan-jaya previously approved these changes Jun 30, 2025
Copy link
Member

@jarnura jarnura left a comment

Choose a reason for hiding this comment

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

Is the MCA are validated against merchant?

@kashif-m kashif-m requested a review from jarnura June 30, 2025 10:03
@jarnura
Copy link
Member

jarnura commented Jun 30, 2025

Is the MCA are validated against merchant?

@likhinbopanna likhinbopanna added this pull request to the merge queue Jul 1, 2025
Merged via the queue into main with commit ce2b90b Jul 1, 2025
17 of 20 checks passed
@likhinbopanna likhinbopanna deleted the 8464-feature-allow-data-migration-at-profile-level branch July 1, 2025 10:07
kashif-m added a commit that referenced this pull request Jul 4, 2025
…ort for multiple profiles (#8473)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
(cherry picked from commit ce2b90b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-payment-methods Area: Payment Methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] allow data migration at profile level
4 participants