Skip to content

Commit a88eebd

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 e407d50 commit a88eebd

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
@@ -19838,7 +19838,8 @@
1983819838
"type": "string",
1983919839
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
1984019840
"example": "https://hyperswitch.io",
19841-
"nullable": true
19841+
"nullable": true,
19842+
"maxLength": 2048
1984219843
},
1984319844
"setup_future_usage": {
1984419845
"allOf": [
@@ -20247,7 +20248,8 @@
2024720248
"type": "string",
2024820249
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
2024920250
"example": "https://hyperswitch.io",
20250-
"nullable": true
20251+
"nullable": true,
20252+
"maxLength": 2048
2025120253
},
2025220254
"setup_future_usage": {
2025320255
"allOf": [
@@ -21514,7 +21516,8 @@
2151421516
"type": "string",
2151521517
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
2151621518
"example": "https://hyperswitch.io",
21517-
"nullable": true
21519+
"nullable": true,
21520+
"maxLength": 2048
2151821521
},
2151921522
"setup_future_usage": {
2152021523
"allOf": [
@@ -22734,7 +22737,8 @@
2273422737
"type": "string",
2273522738
"description": "The URL to which you want the user to be redirected after the completion of the payment operation",
2273622739
"example": "https://hyperswitch.io",
22737-
"nullable": true
22740+
"nullable": true,
22741+
"maxLength": 2048
2273822742
},
2273922743
"setup_future_usage": {
2274022744
"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)]
@@ -423,6 +424,7 @@ pub struct PaymentIntentNew {
423424
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
424425
pub created_by: Option<String>,
425426
pub is_iframe_redirection_enabled: Option<bool>,
427+
pub extended_return_url: Option<String>,
426428
}
427429

428430
#[cfg(feature = "v2")]
@@ -671,6 +673,7 @@ pub struct PaymentIntentUpdateInternal {
671673
pub tax_details: Option<TaxDetails>,
672674
pub force_3ds_challenge: Option<bool>,
673675
pub is_iframe_redirection_enabled: Option<bool>,
676+
pub extended_return_url: Option<String>,
674677
}
675678

676679
#[cfg(feature = "v1")]
@@ -715,6 +718,7 @@ impl PaymentIntentUpdate {
715718
tax_details,
716719
force_3ds_challenge,
717720
is_iframe_redirection_enabled,
721+
extended_return_url,
718722
} = self.into();
719723
PaymentIntent {
720724
amount: amount.unwrap_or(source.amount),
@@ -763,6 +767,7 @@ impl PaymentIntentUpdate {
763767
force_3ds_challenge: force_3ds_challenge.or(source.force_3ds_challenge),
764768
is_iframe_redirection_enabled: is_iframe_redirection_enabled
765769
.or(source.is_iframe_redirection_enabled),
770+
extended_return_url: extended_return_url.or(source.extended_return_url),
766771
..source
767772
}
768773
}
@@ -814,6 +819,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
814819
tax_details: None,
815820
force_3ds_challenge: None,
816821
is_iframe_redirection_enabled: None,
822+
extended_return_url: None,
817823
},
818824
PaymentIntentUpdate::Update(value) => Self {
819825
amount: Some(value.amount),
@@ -823,7 +829,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
823829
customer_id: value.customer_id,
824830
shipping_address_id: value.shipping_address_id,
825831
billing_address_id: value.billing_address_id,
826-
return_url: value.return_url,
832+
return_url: None, // deprecated
827833
business_country: value.business_country,
828834
business_label: value.business_label,
829835
description: value.description,
@@ -855,6 +861,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
855861
tax_details: None,
856862
force_3ds_challenge: value.force_3ds_challenge,
857863
is_iframe_redirection_enabled: value.is_iframe_redirection_enabled,
864+
extended_return_url: value.return_url,
858865
},
859866
PaymentIntentUpdate::PaymentCreateUpdate {
860867
return_url,
@@ -865,7 +872,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
865872
customer_details,
866873
updated_by,
867874
} => Self {
868-
return_url,
875+
return_url: None, // deprecated
869876
status,
870877
customer_id,
871878
shipping_address_id,
@@ -903,6 +910,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
903910
tax_details: None,
904911
force_3ds_challenge: None,
905912
is_iframe_redirection_enabled: None,
913+
extended_return_url: return_url,
906914
},
907915
PaymentIntentUpdate::PGStatusUpdate {
908916
status,
@@ -947,6 +955,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
947955
tax_details: None,
948956
force_3ds_challenge: None,
949957
is_iframe_redirection_enabled: None,
958+
extended_return_url: None,
950959
},
951960
PaymentIntentUpdate::MerchantStatusUpdate {
952961
status,
@@ -992,6 +1001,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
9921001
tax_details: None,
9931002
force_3ds_challenge: None,
9941003
is_iframe_redirection_enabled: None,
1004+
extended_return_url: None,
9951005
},
9961006
PaymentIntentUpdate::ResponseUpdate {
9971007
// amount,
@@ -1044,6 +1054,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
10441054
tax_details: None,
10451055
force_3ds_challenge: None,
10461056
is_iframe_redirection_enabled: None,
1057+
extended_return_url: None,
10471058
},
10481059
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
10491060
active_attempt_id,
@@ -1088,6 +1099,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
10881099
tax_details: None,
10891100
force_3ds_challenge: None,
10901101
is_iframe_redirection_enabled: None,
1102+
extended_return_url: None,
10911103
},
10921104
PaymentIntentUpdate::StatusAndAttemptUpdate {
10931105
status,
@@ -1133,6 +1145,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
11331145
tax_details: None,
11341146
force_3ds_challenge: None,
11351147
is_iframe_redirection_enabled: None,
1148+
extended_return_url: None,
11361149
},
11371150
PaymentIntentUpdate::ApproveUpdate {
11381151
status,
@@ -1177,6 +1190,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
11771190
tax_details: None,
11781191
force_3ds_challenge: None,
11791192
is_iframe_redirection_enabled: None,
1193+
extended_return_url: None,
11801194
},
11811195
PaymentIntentUpdate::RejectUpdate {
11821196
status,
@@ -1221,6 +1235,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
12211235
tax_details: None,
12221236
force_3ds_challenge: None,
12231237
is_iframe_redirection_enabled: None,
1238+
extended_return_url: None,
12241239
},
12251240
PaymentIntentUpdate::SurchargeApplicableUpdate {
12261241
surcharge_applicable,
@@ -1264,6 +1279,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
12641279
tax_details: None,
12651280
force_3ds_challenge: None,
12661281
is_iframe_redirection_enabled: None,
1282+
extended_return_url: None,
12671283
},
12681284
PaymentIntentUpdate::IncrementalAuthorizationAmountUpdate { amount } => Self {
12691285
amount: Some(amount),
@@ -1304,6 +1320,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
13041320
tax_details: None,
13051321
force_3ds_challenge: None,
13061322
is_iframe_redirection_enabled: None,
1323+
extended_return_url: None,
13071324
},
13081325
PaymentIntentUpdate::AuthorizationCountUpdate {
13091326
authorization_count,
@@ -1346,6 +1363,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
13461363
tax_details: None,
13471364
force_3ds_challenge: None,
13481365
is_iframe_redirection_enabled: None,
1366+
extended_return_url: None,
13491367
},
13501368
PaymentIntentUpdate::CompleteAuthorizeUpdate {
13511369
shipping_address_id,
@@ -1388,6 +1406,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
13881406
tax_details: None,
13891407
force_3ds_challenge: None,
13901408
is_iframe_redirection_enabled: None,
1409+
extended_return_url: None,
13911410
},
13921411
PaymentIntentUpdate::ManualUpdate { status, updated_by } => Self {
13931412
status,
@@ -1428,6 +1447,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
14281447
tax_details: None,
14291448
force_3ds_challenge: None,
14301449
is_iframe_redirection_enabled: None,
1450+
extended_return_url: None,
14311451
},
14321452
PaymentIntentUpdate::SessionResponseUpdate {
14331453
tax_details,
@@ -1473,6 +1493,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
14731493
is_payment_processor_token_flow: None,
14741494
force_3ds_challenge: None,
14751495
is_iframe_redirection_enabled: None,
1496+
extended_return_url: None,
14761497
},
14771498
}
14781499
}

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
}
@@ -1957,7 +1958,7 @@ impl behaviour::Conversion for PaymentIntent {
19571958
amount_captured: self.amount_captured,
19581959
customer_id: self.customer_id,
19591960
description: self.description,
1960-
return_url: self.return_url,
1961+
return_url: None, // deprecated
19611962
metadata: self.metadata,
19621963
connector_id: self.connector_id,
19631964
shipping_address_id: self.shipping_address_id,
@@ -2010,6 +2011,7 @@ impl behaviour::Conversion for PaymentIntent {
20102011
force_3ds_challenge: self.force_3ds_challenge,
20112012
force_3ds_challenge_trigger: self.force_3ds_challenge_trigger,
20122013
is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,
2014+
extended_return_url: self.return_url,
20132015
})
20142016
}
20152017

@@ -2052,7 +2054,9 @@ impl behaviour::Conversion for PaymentIntent {
20522054
amount_captured: storage_model.amount_captured,
20532055
customer_id: storage_model.customer_id,
20542056
description: storage_model.description,
2055-
return_url: storage_model.return_url,
2057+
return_url: storage_model
2058+
.extended_return_url
2059+
.or(storage_model.return_url), // fallback to legacy
20562060
metadata: storage_model.metadata,
20572061
connector_id: storage_model.connector_id,
20582062
shipping_address_id: storage_model.shipping_address_id,
@@ -2126,7 +2130,7 @@ impl behaviour::Conversion for PaymentIntent {
21262130
amount_captured: self.amount_captured,
21272131
customer_id: self.customer_id,
21282132
description: self.description,
2129-
return_url: self.return_url,
2133+
return_url: None, // deprecated
21302134
metadata: self.metadata,
21312135
connector_id: self.connector_id,
21322136
shipping_address_id: self.shipping_address_id,
@@ -2179,6 +2183,7 @@ impl behaviour::Conversion for PaymentIntent {
21792183
force_3ds_challenge: self.force_3ds_challenge,
21802184
force_3ds_challenge_trigger: self.force_3ds_challenge_trigger,
21812185
is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,
2186+
extended_return_url: self.return_url,
21822187
})
21832188
}
21842189
}

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)