mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(payment_methods_v2): Added Ephemeral auth for v2 (#6813)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
use common_utils::id_type;
|
||||
#[cfg(feature = "v2")]
|
||||
use masking::Secret;
|
||||
use serde;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
/// Information required to create an ephemeral key.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct EphemeralKeyCreateRequest {
|
||||
@ -15,12 +18,52 @@ pub struct EphemeralKeyCreateRequest {
|
||||
pub customer_id: id_type::CustomerId,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
/// Information required to create an ephemeral key.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct EphemeralKeyCreateRequest {
|
||||
/// Customer ID for which an ephemeral key must be created
|
||||
#[schema(
|
||||
min_length = 32,
|
||||
max_length = 64,
|
||||
value_type = String,
|
||||
example = "12345_cus_01926c58bc6e77c09e809964e72af8c8"
|
||||
)]
|
||||
pub customer_id: id_type::GlobalCustomerId,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
/// ephemeral_key for the customer_id mentioned
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq, ToSchema)]
|
||||
pub struct EphemeralKeyResponse {
|
||||
/// Ephemeral key id
|
||||
#[schema(value_type = String, max_length = 32, min_length = 1)]
|
||||
pub id: id_type::EphemeralKeyId,
|
||||
/// customer_id to which this ephemeral key belongs to
|
||||
#[schema(value_type = String, max_length = 64, min_length = 32, example = "12345_cus_01926c58bc6e77c09e809964e72af8c8")]
|
||||
pub customer_id: id_type::GlobalCustomerId,
|
||||
/// time at which this ephemeral key was created
|
||||
pub created_at: time::PrimitiveDateTime,
|
||||
/// time at which this ephemeral key would expire
|
||||
pub expires: time::PrimitiveDateTime,
|
||||
#[schema(value_type=String)]
|
||||
/// ephemeral key
|
||||
pub secret: Secret<String>,
|
||||
}
|
||||
|
||||
impl common_utils::events::ApiEventMetric for EphemeralKeyCreateRequest {
|
||||
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
|
||||
Some(common_utils::events::ApiEventsType::Miscellaneous)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl common_utils::events::ApiEventMetric for EphemeralKeyResponse {
|
||||
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
|
||||
Some(common_utils::events::ApiEventsType::Miscellaneous)
|
||||
}
|
||||
}
|
||||
|
||||
/// ephemeral_key for the customer_id mentioned
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq, ToSchema)]
|
||||
pub struct EphemeralKeyCreateResponse {
|
||||
|
||||
@ -163,9 +163,6 @@ pub struct PaymentMethodIntentCreate {
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct PaymentMethodIntentConfirm {
|
||||
/// For SDK based calls, client_secret would be required
|
||||
pub client_secret: String,
|
||||
|
||||
/// The unique identifier of the customer.
|
||||
#[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
|
||||
pub customer_id: Option<id_type::CustomerId>,
|
||||
@ -211,9 +208,6 @@ pub struct PaymentMethodIntentConfirmInternal {
|
||||
#[schema(value_type = PaymentMethodType,example = "credit")]
|
||||
pub payment_method_subtype: api_enums::PaymentMethodType,
|
||||
|
||||
/// For SDK based calls, client_secret would be required
|
||||
pub client_secret: String,
|
||||
|
||||
/// The unique identifier of the customer.
|
||||
#[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
|
||||
pub customer_id: Option<id_type::CustomerId>,
|
||||
@ -226,7 +220,6 @@ pub struct PaymentMethodIntentConfirmInternal {
|
||||
impl From<PaymentMethodIntentConfirmInternal> for PaymentMethodIntentConfirm {
|
||||
fn from(item: PaymentMethodIntentConfirmInternal) -> Self {
|
||||
Self {
|
||||
client_secret: item.client_secret,
|
||||
payment_method_type: item.payment_method_type,
|
||||
payment_method_subtype: item.payment_method_subtype,
|
||||
customer_id: item.customer_id,
|
||||
@ -408,10 +401,6 @@ pub struct PaymentMethodUpdate {
|
||||
pub struct PaymentMethodUpdate {
|
||||
/// payment method data to be passed
|
||||
pub payment_method_data: PaymentMethodUpdateData,
|
||||
|
||||
/// This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK
|
||||
#[schema(max_length = 30, min_length = 30, example = "secret_k2uj3he2893eiu2d")]
|
||||
pub client_secret: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
@ -826,7 +815,8 @@ pub struct PaymentMethodResponse {
|
||||
pub last_used_at: Option<time::PrimitiveDateTime>,
|
||||
|
||||
/// For Client based calls
|
||||
pub client_secret: Option<String>,
|
||||
#[schema(value_type=Option<String>)]
|
||||
pub ephemeral_key: Option<masking::Secret<String>>,
|
||||
|
||||
pub payment_method_data: Option<PaymentMethodResponseData>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user