Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(core): introduce new field in payment_intent to handle longer return_url (#8135)

Sakil Mostaka88eebdec7e2
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 2dec1e1ce2..53631f9657 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -19838,7 +19838,8 @@
"type": "string",
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
"example": "https://hyperswitch.io",
- "nullable": true
+ "nullable": true,
+ "maxLength": 2048
},
"setup_future_usage": {
"allOf": [
@@ -20247,7 +20248,8 @@
"type": "string",
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
"example": "https://hyperswitch.io",
- "nullable": true
+ "nullable": true,
+ "maxLength": 2048
},
"setup_future_usage": {
"allOf": [
@@ -21514,7 +21516,8 @@
"type": "string",
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
"example": "https://hyperswitch.io",
- "nullable": true
+ "nullable": true,
+ "maxLength": 2048
},
"setup_future_usage": {
"allOf": [
@@ -22734,7 +22737,8 @@
"type": "string",
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
"example": "https://hyperswitch.io",
- "nullable": true
+ "nullable": true,
+ "maxLength": 2048
},
"setup_future_usage": {
"allOf": [
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 9dd1ac971a..c5b2f6f918 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -964,7 +964,7 @@ pub struct PaymentsRequest {
pub description: Option<String>,
/// The URL to which you want the user to be redirected after the completion of the payment operation
- #[schema(value_type = Option<String>, example = "https://hyperswitch.io")]
+ #[schema(value_type = Option<String>, example = "https://hyperswitch.io", max_length = 2048)]
pub return_url: Option<Url>,
#[schema(value_type = Option<FutureUsage>, example = "off_session")]
diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs
index ae2710c50e..719e40e82a 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -154,6 +154,7 @@ pub struct PaymentIntent {
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
pub created_by: Option<String>,
pub is_iframe_redirection_enabled: Option<bool>,
+ pub extended_return_url: Option<String>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression, PartialEq)]
@@ -423,6 +424,7 @@ pub struct PaymentIntentNew {
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
pub created_by: Option<String>,
pub is_iframe_redirection_enabled: Option<bool>,
+ pub extended_return_url: Option<String>,
}
#[cfg(feature = "v2")]
@@ -671,6 +673,7 @@ pub struct PaymentIntentUpdateInternal {
pub tax_details: Option<TaxDetails>,
pub force_3ds_challenge: Option<bool>,
pub is_iframe_redirection_enabled: Option<bool>,
+ pub extended_return_url: Option<String>,
}
#[cfg(feature = "v1")]
@@ -715,6 +718,7 @@ impl PaymentIntentUpdate {
tax_details,
force_3ds_challenge,
is_iframe_redirection_enabled,
+ extended_return_url,
} = self.into();
PaymentIntent {
amount: amount.unwrap_or(source.amount),
@@ -763,6 +767,7 @@ impl PaymentIntentUpdate {
force_3ds_challenge: force_3ds_challenge.or(source.force_3ds_challenge),
is_iframe_redirection_enabled: is_iframe_redirection_enabled
.or(source.is_iframe_redirection_enabled),
+ extended_return_url: extended_return_url.or(source.extended_return_url),
..source
}
}
@@ -814,6 +819,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::Update(value) => Self {
amount: Some(value.amount),
@@ -823,7 +829,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
customer_id: value.customer_id,
shipping_address_id: value.shipping_address_id,
billing_address_id: value.billing_address_id,
- return_url: value.return_url,
+ return_url: None, // deprecated
business_country: value.business_country,
business_label: value.business_label,
description: value.description,
@@ -855,6 +861,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: value.force_3ds_challenge,
is_iframe_redirection_enabled: value.is_iframe_redirection_enabled,
+ extended_return_url: value.return_url,
},
PaymentIntentUpdate::PaymentCreateUpdate {
return_url,
@@ -865,7 +872,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
customer_details,
updated_by,
} => Self {
- return_url,
+ return_url: None, // deprecated
status,
customer_id,
shipping_address_id,
@@ -903,6 +910,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: return_url,
},
PaymentIntentUpdate::PGStatusUpdate {
status,
@@ -947,6 +955,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::MerchantStatusUpdate {
status,
@@ -992,6 +1001,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::ResponseUpdate {
// amount,
@@ -1044,6 +1054,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
active_attempt_id,
@@ -1088,6 +1099,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::StatusAndAttemptUpdate {
status,
@@ -1133,6 +1145,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::ApproveUpdate {
status,
@@ -1177,6 +1190,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::RejectUpdate {
status,
@@ -1221,6 +1235,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::SurchargeApplicableUpdate {
surcharge_applicable,
@@ -1264,6 +1279,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::IncrementalAuthorizationAmountUpdate { amount } => Self {
amount: Some(amount),
@@ -1304,6 +1320,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::AuthorizationCountUpdate {
authorization_count,
@@ -1346,6 +1363,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::CompleteAuthorizeUpdate {
shipping_address_id,
@@ -1388,6 +1406,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::ManualUpdate { status, updated_by } => Self {
status,
@@ -1428,6 +1447,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
tax_details: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
PaymentIntentUpdate::SessionResponseUpdate {
tax_details,
@@ -1473,6 +1493,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
is_payment_processor_token_flow: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
+ extended_return_url: None,
},
}
}
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 9d4e4dab73..388fcc2375 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -1039,6 +1039,8 @@ diesel::table! {
#[max_length = 255]
created_by -> Nullable<Varchar>,
is_iframe_redirection_enabled -> Nullable<Bool>,
+ #[max_length = 2048]
+ extended_return_url -> Nullable<Varchar>,
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
index c08a813026..572c7d0844 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
@@ -1209,7 +1209,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
status,
amount_captured,
customer_id,
- return_url,
+ return_url: None, // deprecated
setup_future_usage,
off_session,
metadata,
@@ -1242,6 +1242,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
tax_details,
force_3ds_challenge,
is_iframe_redirection_enabled,
+ extended_return_url: return_url,
}
}
}
@@ -1957,7 +1958,7 @@ impl behaviour::Conversion for PaymentIntent {
amount_captured: self.amount_captured,
customer_id: self.customer_id,
description: self.description,
- return_url: self.return_url,
+ return_url: None, // deprecated
metadata: self.metadata,
connector_id: self.connector_id,
shipping_address_id: self.shipping_address_id,
@@ -2010,6 +2011,7 @@ impl behaviour::Conversion for PaymentIntent {
force_3ds_challenge: self.force_3ds_challenge,
force_3ds_challenge_trigger: self.force_3ds_challenge_trigger,
is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,
+ extended_return_url: self.return_url,
})
}
@@ -2052,7 +2054,9 @@ impl behaviour::Conversion for PaymentIntent {
amount_captured: storage_model.amount_captured,
customer_id: storage_model.customer_id,
description: storage_model.description,
- return_url: storage_model.return_url,
+ return_url: storage_model
+ .extended_return_url
+ .or(storage_model.return_url), // fallback to legacy
metadata: storage_model.metadata,
connector_id: storage_model.connector_id,
shipping_address_id: storage_model.shipping_address_id,
@@ -2126,7 +2130,7 @@ impl behaviour::Conversion for PaymentIntent {
amount_captured: self.amount_captured,
customer_id: self.customer_id,
description: self.description,
- return_url: self.return_url,
+ return_url: None, // deprecated
metadata: self.metadata,
connector_id: self.connector_id,
shipping_address_id: self.shipping_address_id,
@@ -2179,6 +2183,7 @@ impl behaviour::Conversion for PaymentIntent {
force_3ds_challenge: self.force_3ds_challenge,
force_3ds_challenge_trigger: self.force_3ds_challenge_trigger,
is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,
+ extended_return_url: self.return_url,
})
}
}
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.js
index 21179d831f..b14002f6d0 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js
@@ -1573,14 +1573,14 @@ export const connectorDetails = {
return_url_too_long: getCustomExchange({
Request: {
customer_id: "customer_1234567890",
- return_url: "http://example.com/" + "a".repeat(237),
+ return_url: "http://example.com/" + "a".repeat(2031),
},
Response: {
status: 400,
body: {
error: {
message:
- "return_url must be at most 255 characters long. Received 256 characters",
+ "return_url must be at most 2048 characters long. Received 2050 characters",
code: "IR_06",
type: "invalid_request",
},
diff --git a/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js b/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js
index 3fdf2dc414..92cbe8fa4f 100644
--- a/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js
@@ -152,16 +152,18 @@ describe("Corner cases", () => {
);
});
- // it("[Payment] return_url - too long", () => {
- // const data = getConnectorDetails(globalState.get("connectorId"))["return_url_variations"]["return_url_too_long"];
- // cy.createConfirmPaymentTest(
- // paymentCreateConfirmBody,
- // data,
- // "no_three_ds",
- // "automatic",
- // globalState
- // );
- // });
+ it("[Payment] return_url - too long", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "return_url_variations"
+ ]["return_url_too_long"];
+ cy.createConfirmPaymentTest(
+ paymentCreateConfirmBody,
+ data,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
it("[Payment] return_url - invalid format", () => {
const data = getConnectorDetails(globalState.get("connectorId"))[
diff --git a/migrations/2025-05-25-185220_add-merchant_return_url-column-to-payment_intent/down.sql b/migrations/2025-05-25-185220_add-merchant_return_url-column-to-payment_intent/down.sql
new file mode 100644
index 0000000000..75494de0ca
--- /dev/null
+++ b/migrations/2025-05-25-185220_add-merchant_return_url-column-to-payment_intent/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_intent DROP COLUMN IF EXISTS extended_return_url;
\ No newline at end of file
diff --git a/migrations/2025-05-25-185220_add-merchant_return_url-column-to-payment_intent/up.sql b/migrations/2025-05-25-185220_add-merchant_return_url-column-to-payment_intent/up.sql
new file mode 100644
index 0000000000..58ca6b1a35
--- /dev/null
+++ b/migrations/2025-05-25-185220_add-merchant_return_url-column-to-payment_intent/up.sql
@@ -0,0 +1 @@
+ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS extended_return_url VARCHAR(2048);
\ No newline at end of file
diff --git a/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql b/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql
index e912b9f9c5..7913af26d6 100644
--- a/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql
+++ b/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql
@@ -64,7 +64,8 @@ ALTER TABLE payment_intent DROP COLUMN payment_id,
DROP COLUMN payment_confirm_source,
DROP COLUMN merchant_order_reference_id,
DROP COLUMN is_payment_processor_token_flow,
- DROP COLUMN charges;
+ DROP COLUMN charges,
+ DROP COLUMN extended_return_url;
-- Run below queries only when V1 is deprecated
ALTER TABLE payment_attempt DROP COLUMN attempt_id,