mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
feat(router): add api_models and openapi changes for refunds create api v2 (#6385)
This commit is contained in:
committed by
GitHub
parent
4ef48c39b3
commit
5a10e5867a
@ -6,6 +6,7 @@ use crate::refunds::{
|
||||
RefundUpdateRequest, RefundsRetrieveRequest,
|
||||
};
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl ApiEventMetric for RefundRequest {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
let payment_id = self.payment_id.clone();
|
||||
@ -18,6 +19,7 @@ impl ApiEventMetric for RefundRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl ApiEventMetric for RefundResponse {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Refund {
|
||||
@ -27,6 +29,17 @@ impl ApiEventMetric for RefundResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl ApiEventMetric for RefundResponse {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Refund {
|
||||
payment_id: self.payment_id.clone(),
|
||||
refund_id: self.id.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl ApiEventMetric for RefundsRetrieveRequest {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Refund {
|
||||
@ -36,6 +49,7 @@ impl ApiEventMetric for RefundsRetrieveRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl ApiEventMetric for RefundUpdateRequest {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Refund {
|
||||
@ -45,6 +59,7 @@ impl ApiEventMetric for RefundUpdateRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl ApiEventMetric for RefundManualUpdateRequest {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Refund {
|
||||
|
||||
@ -61,6 +61,45 @@ pub struct RefundRequest {
|
||||
pub charges: Option<ChargeRefunds>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RefundsCreateRequest {
|
||||
/// The payment id against which refund is initiated
|
||||
#[schema(
|
||||
max_length = 30,
|
||||
min_length = 30,
|
||||
example = "pay_mbabizu24mvu3mela5njyhpit4",
|
||||
value_type = String,
|
||||
)]
|
||||
pub payment_id: common_utils::id_type::GlobalPaymentId,
|
||||
|
||||
/// Unique Identifier for the Refund. This is to ensure idempotency for multiple partial refunds initiated against the same payment.
|
||||
#[schema(
|
||||
max_length = 30,
|
||||
min_length = 30,
|
||||
example = "ref_mbabizu24mvu3mela5njyhpit4",
|
||||
value_type = Option<String>,
|
||||
)]
|
||||
pub merchant_reference_id: Option<common_utils::id_type::RefundReferenceId>,
|
||||
|
||||
/// Total amount for which the refund is to be initiated. Amount for the payment in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc., If not provided, this will default to the amount_captured of the payment
|
||||
#[schema(value_type = Option<i64> , minimum = 100, example = 6540)]
|
||||
pub amount: Option<MinorUnit>,
|
||||
|
||||
/// Reason for the refund. Often useful for displaying to users and your customer support executive.
|
||||
#[schema(max_length = 255, example = "Customer returned the product")]
|
||||
pub reason: Option<String>,
|
||||
|
||||
/// To indicate whether to refund needs to be instant or scheduled. Default value is instant
|
||||
#[schema(default = "Instant", example = "Instant")]
|
||||
pub refund_type: Option<RefundType>,
|
||||
|
||||
/// Metadata is useful for storing additional, unstructured information on an object.
|
||||
#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize)]
|
||||
pub struct RefundsRetrieveBody {
|
||||
pub force_sync: Option<bool>,
|
||||
@ -125,6 +164,7 @@ pub enum RefundType {
|
||||
Instant,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
|
||||
pub struct RefundResponse {
|
||||
/// Unique Identifier for the refund
|
||||
@ -168,6 +208,78 @@ pub struct RefundResponse {
|
||||
pub charges: Option<ChargeRefunds>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl RefundResponse {
|
||||
pub fn get_refund_id_as_string(&self) -> String {
|
||||
self.refund_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
|
||||
pub struct RefundResponse {
|
||||
/// Global Refund Id for the refund
|
||||
#[schema(value_type = String)]
|
||||
pub id: common_utils::id_type::GlobalRefundId,
|
||||
/// The payment id against which refund is initiated
|
||||
#[schema(value_type = String)]
|
||||
pub payment_id: common_utils::id_type::GlobalPaymentId,
|
||||
/// Unique Identifier for the Refund. This is to ensure idempotency for multiple partial refunds initiated against the same payment.
|
||||
#[schema(
|
||||
max_length = 30,
|
||||
min_length = 30,
|
||||
example = "ref_mbabizu24mvu3mela5njyhpit4",
|
||||
value_type = Option<String>,
|
||||
)]
|
||||
pub merchant_reference_id: Option<common_utils::id_type::RefundReferenceId>,
|
||||
/// The refund amount
|
||||
#[schema(value_type = i64 , minimum = 100, example = 6540)]
|
||||
pub amount: MinorUnit,
|
||||
/// The three-letter ISO currency code
|
||||
#[schema(value_type = Currency)]
|
||||
pub currency: common_enums::Currency,
|
||||
/// The status for refund
|
||||
pub status: RefundStatus,
|
||||
/// An arbitrary string attached to the object
|
||||
pub reason: Option<String>,
|
||||
/// Metadata is useful for storing additional, unstructured information on an object
|
||||
#[schema(value_type = Option<Object>)]
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
/// The error details for the refund
|
||||
pub error_details: Option<RefundErrorDetails>,
|
||||
/// The timestamp at which refund is created
|
||||
#[serde(with = "common_utils::custom_serde::iso8601")]
|
||||
pub created_at: PrimitiveDateTime,
|
||||
/// The timestamp at which refund is updated
|
||||
#[serde(with = "common_utils::custom_serde::iso8601")]
|
||||
pub updated_at: PrimitiveDateTime,
|
||||
/// The connector used for the refund and the corresponding payment
|
||||
#[schema(example = "stripe", value_type = Connector)]
|
||||
pub connector: enums::Connector,
|
||||
/// The id of business profile for this refund
|
||||
#[schema(value_type = String)]
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
/// The merchant_connector_id of the processor through which this payment went through
|
||||
#[schema(value_type = String)]
|
||||
pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
||||
/// The reference id of the connector for the refund
|
||||
pub connector_refund_reference_id: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl RefundResponse {
|
||||
pub fn get_refund_id_as_string(&self) -> String {
|
||||
self.id.get_string_repr().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
|
||||
pub struct RefundErrorDetails {
|
||||
pub code: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
|
||||
pub struct RefundListRequest {
|
||||
/// The identifier for the payment
|
||||
|
||||
Reference in New Issue
Block a user