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

feat(core): Add support for v2 payments get intent using merchant reference id #7123

Merged
merged 11 commits into from
Feb 6, 2025

Conversation

srujanchikke
Copy link
Contributor

@srujanchikke srujanchikke commented Jan 28, 2025

Type of Change

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

Description

This PR adds support for payments get intent in v2 using merchant reference id.

Note : In a distributed setup we will be having many partition, to access data efficiently we need partition_key. For payments partition_key is payment_intent global-id . So to get the partition_key, we need to create a reverse_lookup table which map merchant_reference_id+profile to payment_intent global-id. A constraint based mechanism will be implemented on those tables.

Additional Changes

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

Motivation and Context

How did you test it?

Test case 1:

request :

curl --location 'http://localhost:8080/v2/payments/ref/example' \
--header 'x-profile-id: pro_xVG6fBFDok3HxeI2vklo' \
--header 'api-key: dev_pICbNgHQUSohctLw03CxJUszzttJpYWcuaeqyTS1SjBoaSHulQsdq9y1uqnc1jNq' \
--data ''

response

{
    "id": "12345_pay_0194a76014af73b19c5d487667c0e00e",
    "status": "requires_payment_method",
    "amount_details": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null
    },
    "client_secret": "12345_pay_0194a76014af73b19c5d487667c0e00e_secret_0194a76014ba74439ec0fc14e9808ea2",
    "profile_id": "pro_xVG6fBFDok3HxeI2vklo",
    "merchant_reference_id": "example",
    "routing_algorithm_id": null,
    "capture_method": "manual",
    "authentication_type": "no_three_ds",
    "billing": {
        "address": {
            "city": null,
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": null,
            "state": null,
            "first_name": "John",
            "last_name": "Dough"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "shipping": {
        "address": {
            "city": "Karwar",
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": "581301",
            "state": "Karnataka",
            "first_name": "John",
            "last_name": "Dough"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "customer_id": null,
    "customer_present": "present",
    "description": null,
    "return_url": null,
    "setup_future_usage": "on_session",
    "apply_mit_exemption": "Skip",
    "statement_descriptor": null,
    "order_details": null,
    "allowed_payment_method_types": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": null,
        "apple_pay_recurring_details": null
    },
    "payment_link_enabled": "Skip",
    "payment_link_config": null,
    "request_incremental_authorization": "default",
    "expires_on": "2025-01-27T11:02:59.418Z",
    "frm_metadata": null,
    "request_external_three_ds_authentication": "Skip"
}

Test case 2 :
Invalid merchant reference id

curl --location 'http://localhost:8080/v2/payments/ref/example1' \
--header 'x-profile-id: pro_xVG6fBFDok3HxeI2vklo' \
--header 'api-key: ••••••' \
--data ''

response

{
    "error": {
        "type": "invalid_request",
        "message": "Payment does not exist in our records",
        "code": "HE_02"
    }
}

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 Jan 28, 2025

@srujanchikke srujanchikke self-assigned this Jan 28, 2025
@srujanchikke srujanchikke added A-core Area: Core flows api-v2 labels Jan 28, 2025
@srujanchikke srujanchikke marked this pull request as ready for review January 28, 2025 07:21
@srujanchikke srujanchikke requested review from a team as code owners January 28, 2025 07:21
@srujanchikke srujanchikke changed the title feat(core) : Add support for v2 payments get intent using merchant reference id feat(core): Add support for v2 payments get intent using merchant reference id Jan 28, 2025
@srujanchikke srujanchikke requested a review from jarnura January 28, 2025 10:30
merchant_reference_id: &common_utils::id_type::PaymentReferenceId,
profile_id: &common_utils::id_type::ProfileId,
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
Copy link
Member

Choose a reason for hiding this comment

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

can you check if we have this unique index or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have unique index on merchant_reference_id & profile id in intent table. We can only get unique intent entry by implementing look up table.
cc : @jarnura

Copy link
Member

Choose a reason for hiding this comment

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

In a distributed setup we will be having many partition, to access data efficiently we need partition_key. For payments partition_key is payment_intent global-id. So to get the partition_key, we need to create a reverse_lookup table which map merchant_reference_id+profile to payment_intent global-id. A constraint based mechanism will be implemented on those tables.

merchant_reference_id: &common_utils::id_type::PaymentReferenceId,
profile_id: &common_utils::id_type::ProfileId,
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
Copy link
Member

Choose a reason for hiding this comment

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

In a distributed setup we will be having many partition, to access data efficiently we need partition_key. For payments partition_key is payment_intent global-id. So to get the partition_key, we need to create a reverse_lookup table which map merchant_reference_id+profile to payment_intent global-id. A constraint based mechanism will be implemented on those tables.

@@ -555,6 +555,11 @@ impl Payments {
web::resource("/create-intent").route(web::post().to(payments::payments_create_intent)),
);

route = route.service(
web::resource("/merchant-reference-id/{merchant_reference_id}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
web::resource("/merchant-reference-id/{merchant_reference_id}")
web::resource("/ref/{merchant_reference_id}")

Narayanbhat166
Narayanbhat166 previously approved these changes Jan 29, 2025
jarnura
jarnura previously approved these changes Jan 30, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Feb 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 5, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Feb 5, 2025
@srujanchikke srujanchikke dismissed stale reviews from jarnura and Narayanbhat166 via d16f521 February 5, 2025 16:14
@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 6, 2025
Merged via the queue into main with commit e17ffd1 Feb 6, 2025
17 of 20 checks passed
@likhinbopanna likhinbopanna deleted the payments_get_intent_using_merchant_ref branch February 6, 2025 15:07
pixincreate added a commit that referenced this pull request Feb 7, 2025
…unt-configurable

* 'main' of github.com:juspay/hyperswitch: (37 commits)
  refactor(router): add display_name field to connector feature api  (#7121)
  ci(cypress): Add Tests for Customer Deletion and Psync flows (#7158)
  feat(connector): [DataTrans] ADD 3DS Flow (#6026)
  chore(version): 2025.02.07.0
  chore(connectors): [fiuu] update pm_filters for apple pay and google pay (#7182)
  feat(router): add `organization_id` in authentication table and add it in authentication events (#7168)
  fix(dashboard_metadata): mask `poc_email` and `data_value` for DashboardMetadata (#7130)
  feat(core): Add support for v2 payments get intent using merchant reference id (#7123)
  refactor(customer): return redacted customer instead of error (#7122)
  fix(connector): handle unexpected error response from bluesnap connector (#7120)
  feat(routing): Contract based routing integration  (#6761)
  refactor(dynamic_fields): dynamic fields for Adyen and Stripe, renaming klarnaCheckout, WASM for KlarnaCheckout (#7015)
  feat(connector): [COINGATE] Add Template PR  (#7052)
  chore(roles): remove redundant variant from PermissionGroup (#6985)
  refactor(router): store `network_transaction_id` for `off_session` payments irrespective of the `is_connector_agnostic_mit_enabled` config (#7083)
  chore(connector): [Fiuu] log keys in the PSync response (#7189)
  ci(cypress): fix nmi and paypal (#7173)
  chore(version): 2025.02.06.0
  chore(postman): update Postman collection files
  feat(connector): [Deutschebank] Add Access Token Error struct (#7127)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows api-v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants