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(router): changed payment method token TTL to api contract based config from const value #5115

Conversation

sahkal
Copy link
Contributor

@sahkal sahkal commented Jun 25, 2024

Type of Change

  • Bugfix
  • New feature

Description

Currently the payment method token TLL calculation was done based on const::TOKEN_TTL - payment_intent.created_at

where TOKEN_TTL was 15mins, but as we have a new contract called session_expiry we can make our payment live for longer time constraint than just 15mins,

due to this, the value const::TOKEN_TTL - payment_intent.created_at might go negative if the payment is done after 15mins. Which causes negative value at redis.

To solve, This problem we have used intent_fulfillment_time in business profile which is set by the merchant.

max value of intent_fulfillment_time can be 30mins and min can be 1min

How did you test it?

[Scenario 1] : Create a new business account
Create a merchant -> Create business profile with intent_fulfillment_time as 60s -> do payment connector step -> Create api key ->

Business Create

curl --location 'http://localhost:8080/account/merchant_1719312571/business_profile' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
  "profile_name": "fooddqw",
  "intent_fulfillment_time":60
}'

Do payment create with payment link

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Ccb0N9Nd43rBhCANbXit86h820vVpcXkexpgbAw5efxjwiUC6UYiTeOtW446kkpa' \
--data-raw '
{
    "amount": 250,
    "currency": "USD",
    "payment_link":true,
    "profile_id": "pro_D1CA5xM3jTuo1r0XHp9e",
    "amount_to_capture": 250,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "StripeCustomer123",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Please Pay for your XYZ",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "setup_future_usage": "off_session",
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "127.0.0.1"
    },
    "routing": {
        "type": "single",
        "data": "nmi"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "payment_link_config":{
        "enabled_saved_payment_method":true
      }}
    
'

Do the payment after 60 seconds it should fail, with log as
Screenshot 2024-06-25 at 4 35 39 PM

Screenshot 2024-06-25 at 4 35 51 PM

[Scenario 2] : Update business account

Now Do update business profile

curl --location 'http://localhost:8080/account/merchant_1719312571/business_profile/pro_D1CA5xM3jTuo1r0XHp9e' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
  "intent_fulfillment_time":900
}'

Now do payment link create

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Ccb0N9Nd43rBhCANbXit86h820vVpcXkexpgbAw5efxjwiUC6UYiTeOtW446kkpa' \
--data-raw '
{
    "amount": 250,
    "currency": "USD",
    "payment_link":true,
    "profile_id": "pro_D1CA5xM3jTuo1r0XHp9e",
    "amount_to_capture": 250,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "StripeCustomer123",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Please Pay for your XYZ",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "setup_future_usage": "off_session",
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "127.0.0.1"
    },
    "routing": {
        "type": "single",
        "data": "nmi"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "payment_link_config":{
        "enabled_saved_payment_method":true
      }}
'

Now doPay now after 3mins, it should pass
Screenshot 2024-06-25 at 4 42 10 PM

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

@sahkal sahkal added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed A-payment-methods Area: Payment Methods labels Jun 25, 2024
@sahkal sahkal added this to the June 2024 Release milestone Jun 25, 2024
@sahkal sahkal self-assigned this Jun 25, 2024
@sahkal sahkal requested review from a team as code owners June 25, 2024 10:33
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jun 25, 2024
…of-custom-expiration-more-than-15minutes' of https://github.com/juspay/hyperswitch into 5581-payment-link-fix-payment-token-expiry-bug-in-case-of-custom-expiration-more-than-15minutes
@sahkal sahkal requested a review from jarnura June 25, 2024 10:42
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.

LGTM

@sahkal sahkal requested a review from jarnura June 26, 2024 10:52
jarnura
jarnura previously approved these changes Jun 27, 2024
.contains(&intent_fulfillment_time)
{
Err(errors::ApiErrorResponse::InvalidRequestData {
message: "intent_fulfillment_time should be between 60(1 min) to 1800(30 mins)."
Copy link
Member

Choose a reason for hiding this comment

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

why is this value hard coded?

@sahkal sahkal requested a review from jarnura June 27, 2024 13:19
…ug-in-case-of-custom-expiration-more-than-15minutes
@sahkal sahkal requested a review from Chethan-rao June 27, 2024 14:33
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 1, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 1, 2024
…ug-in-case-of-custom-expiration-more-than-15minutes
…ug-in-case-of-custom-expiration-more-than-15minutes
…ug-in-case-of-custom-expiration-more-than-15minutes
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 2, 2024
Merged via the queue into main with commit 3bbdfb5 Jul 2, 2024
11 checks passed
@Gnanasundari24 Gnanasundari24 deleted the 5581-payment-link-fix-payment-token-expiry-bug-in-case-of-custom-expiration-more-than-15minutes branch July 2, 2024 08:35
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 M-api-contract-changes Metadata: This PR involves API contract changes S-waiting-on-review Status: This PR has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants