Skip to content

Commit 0a9a740

Browse files
refactor(core): introduce new field in payment_intent to handle longer return_url (#8135)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 0804158 commit 0a9a740

File tree

10 files changed

+62
-24
lines changed

10 files changed

+62
-24
lines changed

api-reference/openapi_spec.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19380,7 +19380,8 @@
1938019380
"type": "string",
1938119381
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
1938219382
"example": "https://hyperswitch.io",
19383-
"nullable": true
19383+
"nullable": true,
19384+
"maxLength": 2048
1938419385
},
1938519386
"setup_future_usage": {
1938619387
"allOf": [
@@ -19789,7 +19790,8 @@
1978919790
"type": "string",
1979019791
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
1979119792
"example": "https://hyperswitch.io",
19792-
"nullable": true
19793+
"nullable": true,
19794+
"maxLength": 2048
1979319795
},
1979419796
"setup_future_usage": {
1979519797
"allOf": [
@@ -21056,7 +21058,8 @@
2105621058
"type": "string",
2105721059
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
2105821060
"example": "https://hyperswitch.io",
21059-
"nullable": true
21061+
"nullable": true,
21062+
"maxLength": 2048
2106021063
},
2106121064
"setup_future_usage": {
2106221065
"allOf": [
@@ -22276,7 +22279,8 @@
2227622279
"type": "string",
2227722280
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
2227822281
"example": "https://hyperswitch.io",
22279-
"nullable": true
22282+
"nullable": true,
22283+
"maxLength": 2048
2228022284
},
2228122285
"setup_future_usage": {
2228222286
"allOf": [

crates/api_models/src/payments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ pub struct PaymentsRequest {
964964
pub description: Option<String>,
965965

966966
/// The URL to which you want the user to be redirected after the completion of the payment operation
967-
#[schema(value_type = Option<String>, example = "https://hyperswitch.io")]
967+
#[schema(value_type = Option<String>, example = "https://hyperswitch.io", max_length = 2048)]
968968
pub return_url: Option<Url>,
969969

970970
#[schema(value_type = Option<FutureUsage>, example = "off_session")]

crates/diesel_models/src/payment_intent.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub struct PaymentIntent {
154154
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
155155
pub created_by: Option<String>,
156156
pub is_iframe_redirection_enabled: Option<bool>,
157+
pub extended_return_url: Option<String>,
157158
}
158159

159160
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression, PartialEq)]
@@ -422,6 +423,7 @@ pub struct PaymentIntentNew {
422423
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
423424
pub created_by: Option<String>,
424425
pub is_iframe_redirection_enabled: Option<bool>,
426+
pub extended_return_url: Option<String>,
425427
}
426428

427429
#[cfg(feature = "v2")]
@@ -670,6 +672,7 @@ pub struct PaymentIntentUpdateInternal {
670672
pub tax_details: Option<TaxDetails>,
671673
pub force_3ds_challenge: Option<bool>,
672674
pub is_iframe_redirection_enabled: Option<bool>,
675+
pub extended_return_url: Option<String>,
673676
}
674677

675678
#[cfg(feature = "v1")]
@@ -714,6 +717,7 @@ impl PaymentIntentUpdate {
714717
tax_details,
715718
force_3ds_challenge,
716719
is_iframe_redirection_enabled,
720+
extended_return_url,
717721
} = self.into();
718722
PaymentIntent {
719723
amount: amount.unwrap_or(source.amount),
@@ -762,6 +766,7 @@ impl PaymentIntentUpdate {
762766
force_3ds_challenge: force_3ds_challenge.or(source.force_3ds_challenge),
763767
is_iframe_redirection_enabled: is_iframe_redirection_enabled
764768
.or(source.is_iframe_redirection_enabled),
769+
extended_return_url: extended_return_url.or(source.extended_return_url),
765770
..source
766771
}
767772
}
@@ -813,6 +818,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
813818
tax_details: None,
814819
force_3ds_challenge: None,
815820
is_iframe_redirection_enabled: None,
821+
extended_return_url: None,
816822
},
817823
PaymentIntentUpdate::Update(value) => Self {
818824
amount: Some(value.amount),
@@ -822,7 +828,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
822828
customer_id: value.customer_id,
823829
shipping_address_id: value.shipping_address_id,
824830
billing_address_id: value.billing_address_id,
825-
return_url: value.return_url,
831+
return_url: None, // deprecated
826832
business_country: value.business_country,
827833
business_label: value.business_label,
828834
description: value.description,
@@ -854,6 +860,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
854860
tax_details: None,
855861
force_3ds_challenge: value.force_3ds_challenge,
856862
is_iframe_redirection_enabled: value.is_iframe_redirection_enabled,
863+
extended_return_url: value.return_url,
857864
},
858865
PaymentIntentUpdate::PaymentCreateUpdate {
859866
return_url,
@@ -864,7 +871,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
864871
customer_details,
865872
updated_by,
866873
} => Self {
867-
return_url,
874+
return_url: None, // deprecated
868875
status,
869876
customer_id,
870877
shipping_address_id,
@@ -902,6 +909,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
902909
tax_details: None,
903910
force_3ds_challenge: None,
904911
is_iframe_redirection_enabled: None,
912+
extended_return_url: return_url,
905913
},
906914
PaymentIntentUpdate::PGStatusUpdate {
907915
status,
@@ -946,6 +954,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
946954
tax_details: None,
947955
force_3ds_challenge: None,
948956
is_iframe_redirection_enabled: None,
957+
extended_return_url: None,
949958
},
950959
PaymentIntentUpdate::MerchantStatusUpdate {
951960
status,
@@ -991,6 +1000,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
9911000
tax_details: None,
9921001
force_3ds_challenge: None,
9931002
is_iframe_redirection_enabled: None,
1003+
extended_return_url: None,
9941004
},
9951005
PaymentIntentUpdate::ResponseUpdate {
9961006
// amount,
@@ -1043,6 +1053,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
10431053
tax_details: None,
10441054
force_3ds_challenge: None,
10451055
is_iframe_redirection_enabled: None,
1056+
extended_return_url: None,
10461057
},
10471058
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
10481059
active_attempt_id,
@@ -1087,6 +1098,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
10871098
tax_details: None,
10881099
force_3ds_challenge: None,
10891100
is_iframe_redirection_enabled: None,
1101+
extended_return_url: None,
10901102
},
10911103
PaymentIntentUpdate::StatusAndAttemptUpdate {
10921104
status,
@@ -1132,6 +1144,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
11321144
tax_details: None,
11331145
force_3ds_challenge: None,
11341146
is_iframe_redirection_enabled: None,
1147+
extended_return_url: None,
11351148
},
11361149
PaymentIntentUpdate::ApproveUpdate {
11371150
status,
@@ -1176,6 +1189,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
11761189
tax_details: None,
11771190
force_3ds_challenge: None,
11781191
is_iframe_redirection_enabled: None,
1192+
extended_return_url: None,
11791193
},
11801194
PaymentIntentUpdate::RejectUpdate {
11811195
status,
@@ -1220,6 +1234,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
12201234
tax_details: None,
12211235
force_3ds_challenge: None,
12221236
is_iframe_redirection_enabled: None,
1237+
extended_return_url: None,
12231238
},
12241239
PaymentIntentUpdate::SurchargeApplicableUpdate {
12251240
surcharge_applicable,
@@ -1263,6 +1278,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
12631278
tax_details: None,
12641279
force_3ds_challenge: None,
12651280
is_iframe_redirection_enabled: None,
1281+
extended_return_url: None,
12661282
},
12671283
PaymentIntentUpdate::IncrementalAuthorizationAmountUpdate { amount } => Self {
12681284
amount: Some(amount),
@@ -1303,6 +1319,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
13031319
tax_details: None,
13041320
force_3ds_challenge: None,
13051321
is_iframe_redirection_enabled: None,
1322+
extended_return_url: None,
13061323
},
13071324
PaymentIntentUpdate::AuthorizationCountUpdate {
13081325
authorization_count,
@@ -1345,6 +1362,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
13451362
tax_details: None,
13461363
force_3ds_challenge: None,
13471364
is_iframe_redirection_enabled: None,
1365+
extended_return_url: None,
13481366
},
13491367
PaymentIntentUpdate::CompleteAuthorizeUpdate {
13501368
shipping_address_id,
@@ -1387,6 +1405,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
13871405
tax_details: None,
13881406
force_3ds_challenge: None,
13891407
is_iframe_redirection_enabled: None,
1408+
extended_return_url: None,
13901409
},
13911410
PaymentIntentUpdate::ManualUpdate { status, updated_by } => Self {
13921411
status,
@@ -1427,6 +1446,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
14271446
tax_details: None,
14281447
force_3ds_challenge: None,
14291448
is_iframe_redirection_enabled: None,
1449+
extended_return_url: None,
14301450
},
14311451
PaymentIntentUpdate::SessionResponseUpdate {
14321452
tax_details,
@@ -1472,6 +1492,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
14721492
is_payment_processor_token_flow: None,
14731493
force_3ds_challenge: None,
14741494
is_iframe_redirection_enabled: None,
1495+
extended_return_url: None,
14751496
},
14761497
}
14771498
}

crates/diesel_models/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,8 @@ diesel::table! {
10391039
#[max_length = 255]
10401040
created_by -> Nullable<Varchar>,
10411041
is_iframe_redirection_enabled -> Nullable<Bool>,
1042+
#[max_length = 2048]
1043+
extended_return_url -> Nullable<Varchar>,
10421044
}
10431045
}
10441046

crates/hyperswitch_domain_models/src/payments/payment_intent.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
12091209
status,
12101210
amount_captured,
12111211
customer_id,
1212-
return_url,
1212+
return_url: None, // deprecated
12131213
setup_future_usage,
12141214
off_session,
12151215
metadata,
@@ -1242,6 +1242,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
12421242
tax_details,
12431243
force_3ds_challenge,
12441244
is_iframe_redirection_enabled,
1245+
extended_return_url: return_url,
12451246
}
12461247
}
12471248
}
@@ -1956,7 +1957,7 @@ impl behaviour::Conversion for PaymentIntent {
19561957
amount_captured: self.amount_captured,
19571958
customer_id: self.customer_id,
19581959
description: self.description,
1959-
return_url: self.return_url,
1960+
return_url: None, // deprecated
19601961
metadata: self.metadata,
19611962
connector_id: self.connector_id,
19621963
shipping_address_id: self.shipping_address_id,
@@ -2009,6 +2010,7 @@ impl behaviour::Conversion for PaymentIntent {
20092010
force_3ds_challenge: self.force_3ds_challenge,
20102011
force_3ds_challenge_trigger: self.force_3ds_challenge_trigger,
20112012
is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,
2013+
extended_return_url: self.return_url,
20122014
})
20132015
}
20142016

@@ -2051,7 +2053,9 @@ impl behaviour::Conversion for PaymentIntent {
20512053
amount_captured: storage_model.amount_captured,
20522054
customer_id: storage_model.customer_id,
20532055
description: storage_model.description,
2054-
return_url: storage_model.return_url,
2056+
return_url: storage_model
2057+
.extended_return_url
2058+
.or(storage_model.return_url), // fallback to legacy
20552059
metadata: storage_model.metadata,
20562060
connector_id: storage_model.connector_id,
20572061
shipping_address_id: storage_model.shipping_address_id,
@@ -2125,7 +2129,7 @@ impl behaviour::Conversion for PaymentIntent {
21252129
amount_captured: self.amount_captured,
21262130
customer_id: self.customer_id,
21272131
description: self.description,
2128-
return_url: self.return_url,
2132+
return_url: None, // deprecated
21292133
metadata: self.metadata,
21302134
connector_id: self.connector_id,
21312135
shipping_address_id: self.shipping_address_id,
@@ -2178,6 +2182,7 @@ impl behaviour::Conversion for PaymentIntent {
21782182
force_3ds_challenge: self.force_3ds_challenge,
21792183
force_3ds_challenge_trigger: self.force_3ds_challenge_trigger,
21802184
is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,
2185+
extended_return_url: self.return_url,
21812186
})
21822187
}
21832188
}

cypress-tests/cypress/e2e/configs/Payment/Commons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,14 +1573,14 @@ export const connectorDetails = {
15731573
return_url_too_long: getCustomExchange({
15741574
Request: {
15751575
customer_id: "customer_1234567890",
1576-
return_url: "http://example.com/" + "a".repeat(237),
1576+
return_url: "http://example.com/" + "a".repeat(2031),
15771577
},
15781578
Response: {
15791579
status: 400,
15801580
body: {
15811581
error: {
15821582
message:
1583-
"return_url must be at most 255 characters long. Received 256 characters",
1583+
"return_url must be at most 2048 characters long. Received 2050 characters",
15841584
code: "IR_06",
15851585
type: "invalid_request",
15861586
},

cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,18 @@ describe("Corner cases", () => {
152152
);
153153
});
154154

155-
// it("[Payment] return_url - too long", () => {
156-
// const data = getConnectorDetails(globalState.get("connectorId"))["return_url_variations"]["return_url_too_long"];
157-
// cy.createConfirmPaymentTest(
158-
// paymentCreateConfirmBody,
159-
// data,
160-
// "no_three_ds",
161-
// "automatic",
162-
// globalState
163-
// );
164-
// });
155+
it("[Payment] return_url - too long", () => {
156+
const data = getConnectorDetails(globalState.get("connectorId"))[
157+
"return_url_variations"
158+
]["return_url_too_long"];
159+
cy.createConfirmPaymentTest(
160+
paymentCreateConfirmBody,
161+
data,
162+
"no_three_ds",
163+
"automatic",
164+
globalState
165+
);
166+
});
165167

166168
it("[Payment] return_url - invalid format", () => {
167169
const data = getConnectorDetails(globalState.get("connectorId"))[
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This file should undo anything in `up.sql`
2+
ALTER TABLE payment_intent DROP COLUMN IF EXISTS extended_return_url;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS extended_return_url VARCHAR(2048);

v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ ALTER TABLE payment_intent DROP COLUMN payment_id,
6464
DROP COLUMN payment_confirm_source,
6565
DROP COLUMN merchant_order_reference_id,
6666
DROP COLUMN is_payment_processor_token_flow,
67-
DROP COLUMN charges;
67+
DROP COLUMN charges,
68+
DROP COLUMN extended_return_url;
6869

6970
-- Run below queries only when V1 is deprecated
7071
ALTER TABLE payment_attempt DROP COLUMN attempt_id,

0 commit comments

Comments
 (0)