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

chore: v2 api changes for session token endpoint (#6032)

Hrithikesh6e355f34a8ce
diff --git a/api-reference-v2/api-reference/payments/payments--session-token.mdx b/api-reference-v2/api-reference/payments/payments--session-token.mdx
new file mode 100644
index 0000000000..2b4f6b0bec
--- /dev/null
+++ b/api-reference-v2/api-reference/payments/payments--session-token.mdx
@@ -0,0 +1,3 @@
+---
+openapi: post /v2/payments/{payment_id}/create_external_sdk_tokens
+---
\ No newline at end of file
diff --git a/api-reference-v2/mint.json b/api-reference-v2/mint.json
index 64047f5b56..4d990aa5d4 100644
--- a/api-reference-v2/mint.json
+++ b/api-reference-v2/mint.json
@@ -37,7 +37,8 @@
{
"group": "Payments",
"pages": [
- "api-reference/payments/payments--create-intent"
+ "api-reference/payments/payments--create-intent",
+ "api-reference/payments/payments--session-token"
]
},
{
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json
index 0d3959ce0c..388ccb79a6 100644
--- a/api-reference-v2/openapi_spec.json
+++ b/api-reference-v2/openapi_spec.json
@@ -663,6 +663,46 @@
]
}
},
+ "/v2/payments/{payment_id}/create_external_sdk_tokens": {
+ "post": {
+ "tags": [
+ "Payments"
+ ],
+ "summary": "Payments - Session token",
+ "description": "Creates a session object or a session token for wallets like Apple Pay, Google Pay, etc. These tokens are used by Hyperswitch's SDK to initiate these wallets' SDK.",
+ "operationId": "Create Session tokens for a Payment",
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PaymentsSessionRequest"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "200": {
+ "description": "Payment session object created or session token was retrieved from wallets",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PaymentsSessionResponse"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "Missing mandatory fields"
+ }
+ },
+ "security": [
+ {
+ "publishable_key": []
+ }
+ ]
+ }
+ },
"/v2/profiles": {
"post": {
"tags": [
@@ -15602,37 +15642,7 @@
}
},
"PaymentsSessionRequest": {
- "type": "object",
- "required": [
- "payment_id",
- "client_secret",
- "wallets"
- ],
- "properties": {
- "payment_id": {
- "type": "string",
- "description": "The identifier for the payment"
- },
- "client_secret": {
- "type": "string",
- "description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK"
- },
- "wallets": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/PaymentMethodType"
- },
- "description": "The list of the supported wallets"
- },
- "merchant_connector_details": {
- "allOf": [
- {
- "$ref": "#/components/schemas/MerchantConnectorDetailsWrap"
- }
- ],
- "nullable": true
- }
- }
+ "type": "object"
},
"PaymentsSessionResponse": {
"type": "object",
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 584f81992b..9cafc37af5 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -4505,6 +4505,19 @@ impl From<&VerifyRequest> for MandateValidationFields {
}
}
+// #[cfg(all(feature = "v2", feature = "payment_v2"))]
+// impl From<PaymentsSessionRequest> for PaymentsSessionResponse {
+// fn from(item: PaymentsSessionRequest) -> Self {
+// let client_secret: Secret<String, pii::ClientSecret> = Secret::new(item.client_secret);
+// Self {
+// session_token: vec![],
+// payment_id: item.payment_id,
+// client_secret,
+// }
+// }
+// }
+
+#[cfg(feature = "v1")]
impl From<PaymentsSessionRequest> for PaymentsSessionResponse {
fn from(item: PaymentsSessionRequest) -> Self {
let client_secret: Secret<String, pii::ClientSecret> = Secret::new(item.client_secret);
@@ -4752,6 +4765,11 @@ pub struct RedirectResponse {
pub json_payload: Option<pii::SecretSerdeValue>,
}
+#[cfg(feature = "v2")]
+#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
+pub struct PaymentsSessionRequest {}
+
+#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct PaymentsSessionRequest {
/// The identifier for the payment
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index 715af43def..05a2c72ba9 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -87,6 +87,9 @@ Never share your secret api keys. Keep them guarded and secure.
routes::merchant_account::merchant_account_update,
routes::merchant_account::profiles_list,
+ // Routes for payments
+ routes::payments::payments_connector_session,
+
// Routes for profile
routes::profile::profile_create,
routes::profile::profile_retrieve,
diff --git a/crates/openapi/src/routes/payments.rs b/crates/openapi/src/routes/payments.rs
index 4cf8ec7cad..aa82dafbe4 100644
--- a/crates/openapi/src/routes/payments.rs
+++ b/crates/openapi/src/routes/payments.rs
@@ -381,12 +381,31 @@ pub fn payments_confirm() {}
)]
pub fn payments_capture() {}
+#[cfg(feature = "v1")]
+/// Payments - Session token
+///
+/// Creates a session object or a session token for wallets like Apple Pay, Google Pay, etc. These tokens are used by Hyperswitch's SDK to initiate these wallets' SDK.
+#[utoipa::path(
+ post,
+ path = "/payments/session_tokens",
+ request_body=PaymentsSessionRequest,
+ responses(
+ (status = 200, description = "Payment session object created or session token was retrieved from wallets", body = PaymentsSessionResponse),
+ (status = 400, description = "Missing mandatory fields")
+ ),
+ tag = "Payments",
+ operation_id = "Create Session tokens for a Payment",
+ security(("publishable_key" = []))
+)]
+pub fn payments_connector_session() {}
+
+#[cfg(feature = "v2")]
/// Payments - Session token
///
/// Creates a session object or a session token for wallets like Apple Pay, Google Pay, etc. These tokens are used by Hyperswitch's SDK to initiate these wallets' SDK.
#[utoipa::path(
post,
- path = "/payments/session_tokens",
+ path = "/v2/payments/{payment_id}/create_external_sdk_tokens",
request_body=PaymentsSessionRequest,
responses(
(status = 200, description = "Payment session object created or session token was retrieved from wallets", body = PaymentsSessionResponse),
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index d7899e8b9a..9f90411617 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -145,7 +145,7 @@ where
.validate_request(&req, &merchant_account)?;
tracing::Span::current().record("payment_id", format!("{}", validate_result.payment_id));
-
+ // get profile from headers
let operations::GetTrackerResponse {
operation,
customer_details,
@@ -171,6 +171,7 @@ where
let (operation, customer) = operation
.to_domain()?
+ // get_customer_details
.get_or_create_customer_details(
state,
&mut payment_data,
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index 0293706505..54e4471b05 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -517,10 +517,15 @@ pub struct Payments;
impl Payments {
pub fn server(state: AppState) -> Scope {
let mut route = web::scope("/v2/payments").app_data(web::Data::new(state));
- route = route.service(
- web::resource("/{payment_id}/saved_payment_methods")
- .route(web::get().to(list_customer_payment_method_for_payment)),
- );
+ route = route
+ .service(
+ web::resource("/{payment_id}/saved_payment_methods")
+ .route(web::get().to(list_customer_payment_method_for_payment)),
+ )
+ .service(
+ web::resource("/{payment_id}/create_external_sdk_tokens")
+ .route(web::post().to(payments_connector_session)),
+ );
route
}
diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs
index c8f4f5e4dd..5e0c19e3da 100644
--- a/crates/router/src/routes/payments.rs
+++ b/crates/router/src/routes/payments.rs
@@ -529,6 +529,16 @@ pub async fn payments_dynamic_tax_calculation(
.await
}
+#[cfg(feature = "v2")]
+#[instrument(skip_all, fields(flow = ?Flow::PaymentsSessionToken, payment_id))]
+pub async fn payments_connector_session(
+ state: web::Data<app::AppState>,
+ req: actix_web::HttpRequest,
+ json_payload: web::Json<payment_types::PaymentsSessionRequest>,
+) -> impl Responder {
+ "Session Response"
+}
+
#[cfg(feature = "v1")]
#[instrument(skip_all, fields(flow = ?Flow::PaymentsSessionToken, payment_id))]
pub async fn payments_connector_session(
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index 197c1e4c52..b53a582637 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -1237,6 +1237,7 @@ impl Authenticate for api_models::payment_methods::PaymentMethodListRequest {
}
}
+#[cfg(feature = "v1")]
impl Authenticate for api_models::payments::PaymentsSessionRequest {
fn get_client_secret(&self) -> Option<&String> {
Some(&self.client_secret)