Skip to content

Conversation

kashif-m
Copy link
Contributor

Type of Change

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

Description

This PR adds a validation for return_url when creating payment links. Return URL must be a required parameter as payment links is client side facing and needs to be redirected to an end URL post payment completion.

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 PR fixes a bug in the payment links flow which allowed creating payment links without validating presence of return_url. This allows merchants to be careful of payment link integration.

How did you test it?

1. Create a payment link without return_url in the payments create request

cURL

curl --location --request POST 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_ddmeaxUlgRPHkcqtmZZm5nGMRhejMxXijYCnsp070Oqn2y4lrfUNBCb9UmedwgMt' \
    --data-raw '{"customer_id":"cus_ttQVCva9zDC2q8jfJaiy","profile_id":"pro_510ieWUUX4pc0bUWmBW3","customer_acceptance":{"acceptance_type":"online","accepted_at":"1963-05-03T04:07:52.723Z","online":{"ip_address":"127.0.0.1","user_agent":"amet irure esse"}},"amount":10,"currency":"EUR","payment_link":true,"capture_method":"automatic","billing":{"address":{"line1":"1467","line2":"Harrison Street","line3":"Harrison Street","city":"San Fransico","state":"CA","zip":"94122","country":"HK","first_name":"John","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":"[email protected]"}}'

Response

{
    "error": {
        "type": "invalid_request",
        "message": "return_url must be sent while creating a payment link",
        "code": "IR_06"
    }
}
2. Create a payment link with return_url in the payments create request

cURL

curl --location --request POST 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_ddmeaxUlgRPHkcqtmZZm5nGMRhejMxXijYCnsp070Oqn2y4lrfUNBCb9UmedwgMt' \
    --data-raw '{"customer_id":"cus_ttQVCva9zDC2q8jfJaiy","profile_id":"pro_510ieWUUX4pc0bUWmBW3","customer_acceptance":{"acceptance_type":"online","accepted_at":"1963-05-03T04:07:52.723Z","online":{"ip_address":"127.0.0.1","user_agent":"amet irure esse"}},"amount":10,"currency":"EUR","payment_link":true,"capture_method":"automatic","billing":{"address":{"line1":"1467","line2":"Harrison Street","line3":"Harrison Street","city":"San Fransico","state":"CA","zip":"94122","country":"HK","first_name":"John","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":"[email protected]"},"return_url":"https://example.com"}'

Response

{"payment_id":"pay_jqWIxxAzZ55ObDFPUi3u","merchant_id":"merchant_1744368926","status":"requires_payment_method","amount":10,"net_amount":10,"shipping_cost":null,"amount_capturable":10,"amount_received":null,"connector":null,"client_secret":"pay_jqWIxxAzZ55ObDFPUi3u_secret_R696m3FdANBfOlBHs7e3","created":"2025-04-11T15:32:20.593Z","currency":"EUR","customer_id":"cus_ttQVCva9zDC2q8jfJaiy","customer":{"id":"cus_ttQVCva9zDC2q8jfJaiy","name":null,"email":null,"phone":null,"phone_country_code":null},"description":null,"refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":null,"off_session":null,"capture_on":null,"capture_method":"automatic","payment_method":null,"payment_method_data":null,"payment_token":null,"shipping":null,"billing":{"address":{"city":"San Fransico","country":"HK","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"CA","first_name":"John","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":"[email protected]"},"order_details":null,"email":null,"name":null,"phone":null,"return_url":"https://example.com/","authentication_type":null,"statement_descriptor_name":null,"statement_descriptor_suffix":null,"next_action":null,"cancellation_reason":null,"error_code":null,"error_message":null,"unified_code":null,"unified_message":null,"payment_experience":null,"payment_method_type":null,"connector_label":null,"business_country":null,"business_label":"default","business_sub_label":null,"allowed_payment_method_types":null,"ephemeral_key":{"customer_id":"cus_ttQVCva9zDC2q8jfJaiy","created_at":1744385540,"expires":1744389140,"secret":"epk_4687716462814249b8cad4ebb30c18a3"},"manual_retry_allowed":null,"connector_transaction_id":null,"frm_message":null,"metadata":null,"connector_metadata":null,"feature_metadata":null,"reference_id":null,"payment_link":{"link":"http://localhost:8080/payment_link/merchant_1744368926/pay_jqWIxxAzZ55ObDFPUi3u?locale=en","secure_link":null,"payment_link_id":"plink_2tsEloeZ8SeUXyOQfRsu"},"profile_id":"pro_510ieWUUX4pc0bUWmBW3","surcharge_details":null,"attempt_count":1,"merchant_decision":null,"merchant_connector_id":null,"incremental_authorization_allowed":null,"authorization_count":null,"incremental_authorizations":null,"external_authentication_details":null,"external_3ds_authentication_attempted":false,"expires_on":"2025-04-11T15:47:20.588Z","fingerprint":null,"browser_info":null,"payment_method_id":null,"payment_method_status":null,"updated":"2025-04-11T15:32:20.612Z","split_payments":null,"frm_metadata":null,"extended_authorization_applied":null,"capture_before":null,"merchant_order_reference_id":null,"order_tax_amount":null,"connector_mandate_id":null,"card_discovery":null,"force_3ds_challenge":false,"force_3ds_challenge_trigger":false,"issuer_error_code":null,"issuer_error_message":null}

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

@kashif-m kashif-m self-assigned this Apr 11, 2025
@kashif-m kashif-m requested a review from a team as a code owner April 11, 2025 15:36
@kashif-m kashif-m linked an issue Apr 11, 2025 that may be closed by this pull request
Copy link

semanticdiff-com bot commented Apr 11, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/helpers.rs  48% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller

sahkal
sahkal previously approved these changes Apr 11, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Apr 12, 2025
Merged via the queue into main with commit 81eaf39 Apr 12, 2025
18 of 23 checks passed
@Gnanasundari24 Gnanasundari24 deleted the 7800-enhancement-add-validation-for-return_url-for-payment-links branch April 12, 2025 15:04
pixincreate added a commit that referenced this pull request Apr 15, 2025
…acilitapay-pix-pmt

* 'main' of github.com:juspay/hyperswitch:
  feat(docker): add webhook notifiers for installation tracking (#7653)
  refactor(customer): refactor customer db with storage utils and move trait to domain_models and impl to storage_model (#7538)
  feat(core): Add support for updating metadata after payment has been authorized (#7776)
  chore(version): 2025.04.14.0
  fix: script for one click docker setup (#7762)
  fix(payment_link): add validation for return_url during payment link creation (#7802)
  chore: address Rust 1.86.0 clippy lints (#7735)
  fix(connector): Add network error message support for payment connectors (#7760)
  feat(webhook): add filter by event class and type (#7275)
  ci(cypress): verify if card fields are populated on updating card info (#7743)
  chore(version): 2025.04.11.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] add validation for return_url for Payment Links
4 participants