Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(payments_v2): create customer at connector end and populate connector customer ID #7246

Merged
merged 5 commits into from
Feb 14, 2025

Conversation

SanchithHegde
Copy link
Member

@SanchithHegde SanchithHegde commented Feb 11, 2025

Type of Change

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

Description

This PR updates the payments v2 flows to create a customer at connector's end, where applicable, and populate the connector's customer ID in RouterData, so that the connector integrations which need the connector customer ID can access the field and pass it along.

Additionally, this PR includes some refactors done around relevant code:

  • Introduces a newtype instead of serde_json::Value for the connector_customer field in the customer v2 diesel and domain models.
  • Addresses a clippy::large_enum_variant warning arising with the CustomerUpdate v2 enum.
  • Addresses an unused variable warning for is_click_to_pay_enabled field in the business profile v2 code. (I just opened the file and my IDE displayed only this warning in the entire file, so I ended up fixing it.)

Motivation and Context

As of opening this PR, a customer is not created on the connector's end for those connectors that support / require such an operation. And with respect to the multi-use tokens that were created with Stripe (support added in #7106), the payment methods were created on Stripe's end, but were not associated with a customer, due to which they could not be used to make transactions again, we used to receive such an error:

The provided PaymentMethod cannot be attached. To reuse a PaymentMethod, you must attach it to a Customer first.

To address this, we have to create a customer on Stripe's end first, and then pass Stripe's customer ID when saving the payment method with Stripe.

How did you test it?

Locally, via Postman.

  • Create an organization, merchant account, API key, (business) profile, merchant connector account using the respective v2 APIs.
  • Create a customer using the customer create v2 API.
  • Create and confirm a payment intent, either using the separate APIs, or using the API introduced in feat(payments_v2): implement create and confirm intent flow #7106, while ensuring to pass customer_id field with the customer ID obtained in the previous step.
    • If a merchant connector account was set up with Stripe and the payment is also routed through Stripe, then a connector customer ID must be populated in the database for the customer entry:
      Screenshot of connector_customer field being populated in the database
  • Additionally, if trying a zero amount transaction using the API introduced in feat(payments_v2): implement create and confirm intent flow #7106, we should be able to use the Stripe's payment method ID returned in our payments response (within the connector_token_details field) to create payments with Stripe directly (provided we pass the same connector customer ID as well).

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

@SanchithHegde SanchithHegde added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed C-refactor Category: Refactor A-payments Area: payments api-v2 labels Feb 11, 2025
@SanchithHegde SanchithHegde added this to the February 2025 Release milestone Feb 11, 2025
@SanchithHegde SanchithHegde self-assigned this Feb 11, 2025
@SanchithHegde SanchithHegde requested review from a team as code owners February 11, 2025 20:30
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Feb 12, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Feb 14, 2025
Merged via the queue into main with commit 17f9e6e Feb 14, 2025
25 of 28 checks passed
@Gnanasundari24 Gnanasundari24 deleted the payments-v2-create-customer-at-connector branch February 14, 2025 10:19
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-payments Area: payments api-v2 C-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants