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: Add dynamic secure link #7133

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mrudulvajpayee4935
Copy link
Contributor

@mrudulvajpayee4935 mrudulvajpayee4935 commented Jan 28, 2025

Type of Change

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

Description

We need to refactor the flow of generating payments link. Instead of having two separate routes for generating simple payment link and secure payment link we will maintain single route which will generate payment links accordingly with certain checks.

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?

This can be tested by creating payment link using payment create curl. Single link will be provided in payment_link struct which can be used accordingly in secure or open environment.

  • Curl
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_****' \
--data-raw '{
    "amount": 100,
    "currency": "EUR",
    "payment_link": true,
    "connector": [
        "novalnet"
    ],
    "session_expiry": 1000000,
    "return_url": "https://google.com",
    "payment_link_config": {
        "theme": "#14356f",
        "logo": "https://logosandtypes.com/wp-content/uploads/2020/08/zurich.svg",
        "seller_name": "Zurich Inc."
    },
    "customer": {
        "id": "cus_ZUT9N3LGGMVUkcxlC6xG",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "customer_id": "cus_ZUT9N3LGGMVUkcxlC6xG"
}'

1) Open environment
Screenshot 2025-01-30 at 9 49 16 PM
2) Secure environment
Screenshot 2025-01-30 at 9 49 24 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

@mrudulvajpayee4935 mrudulvajpayee4935 requested review from a team as code owners January 28, 2025 13:56
Copy link

semanticdiff-com bot commented Jan 28, 2025

@mrudulvajpayee4935 mrudulvajpayee4935 self-assigned this Jan 28, 2025
@mrudulvajpayee4935 mrudulvajpayee4935 added the C-refactor Category: Refactor label Jan 28, 2025
@hyperswitch-bot hyperswitch-bot bot added M-database-changes Metadata: This PR involves database schema changes M-api-contract-changes Metadata: This PR involves API contract changes labels Jan 28, 2025
@@ -982,8 +982,6 @@ diesel::table! {
description -> Nullable<Varchar>,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
#[max_length = 255]
Copy link
Contributor

Choose a reason for hiding this comment

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

please add the corresponding up and down sql for migration

Copy link
Contributor

Choose a reason for hiding this comment

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

You can choose to remove this in V2 though!

Copy link
Contributor

Choose a reason for hiding this comment

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

Same with this, this is automatically generated

@@ -55,5 +54,4 @@ pub struct PaymentLinkNew {
pub payment_link_config: Option<serde_json::Value>,
pub description: Option<String>,
pub profile_id: Option<common_utils::id_type::ProfileId>,
pub secure_link: Option<String>,
Copy link
Contributor

@kashif-m kashif-m Jan 29, 2025

Choose a reason for hiding this comment

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

@mrudulvajpayee4935 DB alterations are not allowed, this is a column removal, so let's not remove this one

You can add a comment on top of it saying this column is deprecated

@@ -1019,8 +1019,6 @@ diesel::table! {
description -> Nullable<Varchar>,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
#[max_length = 255]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, don't remove

Copy link
Contributor

Choose a reason for hiding this comment

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

This file is automatically generated when you do a diesel migration, don't make manual changes here

)
}

pub fn is_secure_payment_link_request(
Copy link
Contributor

Choose a reason for hiding this comment

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

This fn is performing two steps - checking if request was for secure payment link and also validating the request if it was!

We can break it into two fns, and consume it in the main parent flow (initiate_payment_link_flow)

First function will tell you the type of payment link, and once you match on it, you can use validation

Why? It helps keep the code readable and ensure the fn is doing what it is named after!

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, instead of returning a bool, can we make an enum? Something like PaymentLinkType with two variants - OpenPaymentLink & SecurePaymentLink

)
})?;

// Validate origin / referer
Copy link
Contributor

Choose a reason for hiding this comment

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

Move validation bits to validator.rs

Copy link
Contributor

@kashif-m kashif-m left a comment

Choose a reason for hiding this comment

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

Added some comments around refactoring

@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 30, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 30, 2025
@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 31, 2025
kashif-m
kashif-m previously approved these changes Jan 31, 2025
@@ -1019,8 +1019,6 @@ diesel::table! {
description -> Nullable<Varchar>,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
#[max_length = 255]
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is automatically generated when you do a diesel migration, don't make manual changes here

@@ -982,8 +982,6 @@ diesel::table! {
description -> Nullable<Varchar>,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
#[max_length = 255]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with this, this is automatically generated

@@ -6967,7 +6967,7 @@ pub struct RetrievePaymentLinkRequest {
pub struct PaymentLinkResponse {
/// URL for rendering the open payment link
pub link: String,
/// URL for rendering the secure payment link
/// URL for rendering the secure payment link. It is deprecated now.
pub secure_link: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove from API models

@@ -6997,7 +6997,7 @@ pub struct RetrievePaymentLinkResponse {
pub status: PaymentLinkStatus,
#[schema(value_type = Option<Currency>)]
pub currency: Option<api_enums::Currency>,
/// Secure payment link (with security checks and listing saved payment methods)
/// Secure payment link (with security checks and listing saved payment methods). It is deprecated now.
pub secure_link: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

And in the response

.and_then(|v| v.to_str().ok())
{
Some("iframe") => Self::SecurePaymentLink,
Some(_) | None => Self::OpenPaymentLink,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
Some(_) | None => Self::OpenPaymentLink,
_ => Self::OpenPaymentLink,

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 31, 2025
@mrudulvajpayee4935 mrudulvajpayee4935 changed the title refactor: Add dynamic scure link refactor: Add dynamic secure link Jan 31, 2025
kashif-m
kashif-m previously approved these changes Jan 31, 2025
cookieg13
cookieg13 previously approved these changes Jan 31, 2025
@hyperswitch-bot hyperswitch-bot bot removed M-database-changes Metadata: This PR involves database schema changes M-api-contract-changes Metadata: This PR involves API contract changes labels Jan 31, 2025
@hyperswitch-bot hyperswitch-bot bot dismissed stale reviews from kashif-m and cookieg13 via a5b3419 January 31, 2025 14:26
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants