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: explicitly specify top redirections for secure payment and payout links #6494

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

kashif-m
Copy link
Contributor

@kashif-m kashif-m commented Nov 6, 2024

Type of Change

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

Description

Described in juspay/hyperswitch-web#773

Additional Changes

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

Motivation and Context

Helps secure links handle redirections for 3ds txns for payments and end return URLs for payouts.

How did you test it?

Locally, using iframed links.

1. Enable secure links by setting up allowed domains

cURL

curl --location 'http://localhost:8080/account/merchant_1730884662/business_profile/pro_4eqlNAJWOPckKqn59OBB' \
    --header 'Content-Type: application/json' \
    --header 'api-key: test_admin' \
    --data '{"payment_link_config":{"allowed_domains":["*"],"enabled_saved_payment_method":false,"theme":"#1A1A1A","logo":"https://hyperswitch.io/favicon.ico"}}'
2. Create a payment link

cURL

curl --location 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_tMyRpU4sj6bZ7z3j6Ho0NJGCRJvx7bkdu6e2MNtBb8225cKSV1YZkJDXoOpqv1ao' \
    --data-raw '{"authentication_type":"three_ds","customer_id":"cus_thvkuYBbjlREiSblofy9","profile_id":"pro_4eqlNAJWOPckKqn59OBB","amount":100,"currency":"USD","payment_link":true,"setup_future_usage":"on_session","connector":["stripe"],"email":"[email protected]","session_expiry":10000,"return_url":"https://example.com","payment_link_config":{"theme":"#14356f","logo":"https://hyperswitch.io/favicon.ico","seller_name":"HyperSwitch Inc."}}'

Response

{"payment_id":"pay_63XbTYdh5nBWx41iK6qM","merchant_id":"merchant_1730884662","status":"requires_payment_method","amount":100,"net_amount":100,"shipping_cost":null,"amount_capturable":100,"amount_received":null,"connector":null,"client_secret":"pay_63XbTYdh5nBWx41iK6qM_secret_GcI9m8tIxoFMxgl8RKsQ","created":"2024-11-07T12:07:53.674Z","currency":"USD","customer_id":"cus_thvkuYBbjlREiSblofy9","customer":{"id":"cus_thvkuYBbjlREiSblofy9","name":"John Doe","email":"[email protected]","phone":"6168205366","phone_country_code":"+1"},"description":null,"refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":"on_session","off_session":null,"capture_on":null,"capture_method":null,"payment_method":null,"payment_method_data":null,"payment_token":null,"shipping":null,"billing":null,"order_details":null,"email":"[email protected]","name":"John Doe","phone":"6168205366","return_url":"https://example.com/","authentication_type":"three_ds","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_thvkuYBbjlREiSblofy9","created_at":1730981273,"expires":1730984873,"secret":"epk_9093c895ec7f41838498599676c8195a"},"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_1730884662/pay_63XbTYdh5nBWx41iK6qM?locale=en","secure_link":"http://localhost:8080/payment_link/s/merchant_1730884662/pay_63XbTYdh5nBWx41iK6qM?locale=en","payment_link_id":"plink_wEst8i1pAaM90cI1EfFZ"},"profile_id":"pro_4eqlNAJWOPckKqn59OBB","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":"2024-11-07T14:54:33.669Z","fingerprint":null,"browser_info":null,"payment_method_id":null,"payment_method_status":null,"updated":"2024-11-07T12:07:53.695Z","charges":null,"frm_metadata":null,"merchant_order_reference_id":null,"order_tax_amount":null,"connector_mandate_id":null}

Open payment link inside an iframe and complete the txn

Payment links with top redirection: true
payment_link.webm

3. Setup allowed domains for payout links

cURL

curl --location 'http://localhost:8080/account/merchant_1730884662/business_profile/pro_4eqlNAJWOPckKqn59OBB' \
    --header 'Content-Type: application/json' \
    --header 'api-key: test_admin' \
    --data '{"payout_link_config":{"allowed_domains":["http://localhost:5500","localhost:5500"],"theme":"#1A1A1A","logo":"https://hyperswitch.io/favicon.ico"}}'
4. Create a payout link

cURL

curl --location 'http://localhost:8080/payouts/create' \
    --header 'Content-Type: application/json' \
    --header 'api-key: dev_tMyRpU4sj6bZ7z3j6Ho0NJGCRJvx7bkdu6e2MNtBb8225cKSV1YZkJDXoOpqv1ao' \
    --data '{"amount":1,"currency":"EUR","customer_id":"cus_thvkuYBbjlREiSblofy9","description":"Its my first payout request","entity_type":"Individual","confirm":false,"auto_fulfill":true,"session_expiry":1000000,"priority":"instant","profile_id":"pro_4eqlNAJWOPckKqn59OBB","payout_link":true,"return_url":"https://www.google.com","billing":{"address":{"line1":"Raadhuisplein","line2":"92","state":"FL","zip":"7901 BW","country":"NL","first_name":"John","last_name":"Doe"}},"payout_link_config":{"theme":"#0066ff","logo":"https://hyperswitch.io/favicon.ico","merchant_name":"HyperSwitch Inc.","enabled_payment_methods":[{"payment_method":"card","payment_method_types":["debit","credit"]},{"payment_method":"bank_transfer","payment_method_types":["ach","bacs","sepa"]},{"payment_method":"wallet","payment_method_types":["pix","paypal","venmo"]}]}}'

Response

{"payout_id":"20a97a1f-948a-48cc-acfb-836bb2a9440a","merchant_id":"merchant_1730884662","amount":1,"currency":"EUR","connector":null,"payout_type":null,"payout_method_data":null,"billing":{"address":{"city":null,"country":"NL","line1":"Raadhuisplein","line2":"92","line3":null,"zip":"7901 BW","state":"FL","first_name":"John","last_name":"Doe"},"phone":null,"email":null},"auto_fulfill":true,"customer_id":"cus_thvkuYBbjlREiSblofy9","customer":{"id":"cus_thvkuYBbjlREiSblofy9","name":"John Doe","email":"[email protected]","phone":"6168205366","phone_country_code":"+1"},"client_secret":"payout_20a97a1f-948a-48cc-acfb-836bb2a9440a_secret_m15ekjiQ9h6ba3Vtqr6P","return_url":"https://www.google.com","business_country":null,"business_label":null,"description":"Its my first payout request","entity_type":"Individual","recurring":false,"metadata":{},"merchant_connector_id":null,"status":"requires_payout_method_data","error_message":null,"error_code":null,"profile_id":"pro_4eqlNAJWOPckKqn59OBB","created":"2024-11-07T12:09:58.421Z","connector_transaction_id":null,"priority":"instant","payout_link":{"payout_link_id":"payout_link_ryMUNr5ZK0cJpvCwLxXU","link":"http://localhost:8080/payout_link/merchant_1730884662/20a97a1f-948a-48cc-acfb-836bb2a9440a?locale=en"},"email":"[email protected]","name":"John Doe","phone":"6168205366","phone_country_code":"+1","unified_code":null,"unified_message":null}

Open payout link in an iframe and complete the txn

Payout links with top redirection: true
payout_link.webm

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 Nov 6, 2024
@kashif-m kashif-m requested a review from a team as a code owner November 6, 2024 12:19
Copy link

semanticdiff-com bot commented Nov 6, 2024

@kashif-m kashif-m linked an issue Nov 7, 2024 that may be closed by this pull request
2 tasks
@Gnanasundari24
Copy link
Contributor

@kashif-m Can you please adding payout link in cypress

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Nov 11, 2024
Merged via the queue into main with commit 0a506b1 Nov 11, 2024
28 of 29 checks passed
@Gnanasundari24 Gnanasundari24 deleted the 5593-iframe-top-redirectioins branch November 11, 2024 08:07
bsayak03 pushed a commit that referenced this pull request Nov 26, 2024
bsayak03 pushed a commit that referenced this pull request Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] handle redirections for iframed content served by HyperSwitch
5 participants