Skip to content

Commit a6e3d2c

Browse files
feat(payouts): add domain type for PayoutId (#8395)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 18a779f commit a6e3d2c

File tree

58 files changed

+506
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+506
-269
lines changed

api-reference/v1/openapi_spec_v1.json

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24303,6 +24303,13 @@
2430324303
"client_secret"
2430424304
],
2430524305
"properties": {
24306+
"merchant_order_reference_id": {
24307+
"type": "string",
24308+
"description": "Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.",
24309+
"example": "merchant_order_ref_123",
24310+
"nullable": true,
24311+
"maxLength": 255
24312+
},
2430624313
"amount": {
2430724314
"type": "integer",
2430824315
"format": "int64",
@@ -24609,6 +24616,13 @@
2460924616
"example": "merchant_1668273825",
2461024617
"maxLength": 255
2461124618
},
24619+
"merchant_order_reference_id": {
24620+
"type": "string",
24621+
"description": "Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.",
24622+
"example": "merchant_order_ref_123",
24623+
"nullable": true,
24624+
"maxLength": 255
24625+
},
2461224626
"amount": {
2461324627
"type": "integer",
2461424628
"format": "int64",
@@ -24902,13 +24916,13 @@
2490224916
"starting_after": {
2490324917
"type": "string",
2490424918
"description": "A cursor for use in pagination, fetch the next list after some object",
24905-
"example": "pay_fafa124123",
24919+
"example": "payout_fafa124123",
2490624920
"nullable": true
2490724921
},
2490824922
"ending_before": {
2490924923
"type": "string",
2491024924
"description": "A cursor for use in pagination, fetch the previous list before some object",
24911-
"example": "pay_fafa124123",
24925+
"example": "payout_fafa124123",
2491224926
"nullable": true
2491324927
},
2491424928
"limit": {
@@ -24955,6 +24969,13 @@
2495524969
"maxLength": 30,
2495624970
"minLength": 30
2495724971
},
24972+
"merchant_order_reference_id": {
24973+
"type": "string",
24974+
"description": "The merchant order reference ID for payout",
24975+
"example": "merchant_order_ref_123",
24976+
"nullable": true,
24977+
"maxLength": 255
24978+
},
2495824979
"profile_id": {
2495924980
"type": "string",
2496024981
"description": "The identifier for business profile",
@@ -25249,6 +25270,13 @@
2524925270
"PayoutUpdateRequest": {
2525025271
"type": "object",
2525125272
"properties": {
25273+
"merchant_order_reference_id": {
25274+
"type": "string",
25275+
"description": "Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.",
25276+
"example": "merchant_order_ref_123",
25277+
"nullable": true,
25278+
"maxLength": 255
25279+
},
2525225280
"amount": {
2525325281
"type": "integer",
2525425282
"format": "int64",
@@ -25479,6 +25507,13 @@
2547925507
"currency"
2548025508
],
2548125509
"properties": {
25510+
"merchant_order_reference_id": {
25511+
"type": "string",
25512+
"description": "Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.",
25513+
"example": "merchant_order_ref_123",
25514+
"nullable": true,
25515+
"maxLength": 255
25516+
},
2548225517
"amount": {
2548325518
"type": "integer",
2548425519
"format": "int64",

api-reference/v2/openapi_spec_v2.json

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19579,7 +19579,19 @@
1957919579
"additionalProperties": false
1958019580
},
1958119581
"PayoutActionRequest": {
19582-
"type": "object"
19582+
"type": "object",
19583+
"required": [
19584+
"payout_id"
19585+
],
19586+
"properties": {
19587+
"payout_id": {
19588+
"type": "string",
19589+
"description": "Unique identifier for the payout. This ensures idempotency for multiple payouts\nthat have been done by a single merchant. This field is auto generated and is returned in the API response.",
19590+
"example": "187282ab-40ef-47a9-9206-5099ba31e432",
19591+
"maxLength": 30,
19592+
"minLength": 30
19593+
}
19594+
}
1958319595
},
1958419596
"PayoutAttemptResponse": {
1958519597
"type": "object",
@@ -19746,6 +19758,13 @@
1974619758
"nullable": true,
1974719759
"maxLength": 255
1974819760
},
19761+
"merchant_order_reference_id": {
19762+
"type": "string",
19763+
"description": "Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.",
19764+
"example": "merchant_order_ref_123",
19765+
"nullable": true,
19766+
"maxLength": 255
19767+
},
1974919768
"amount": {
1975019769
"type": "integer",
1975119770
"format": "int64",
@@ -20001,6 +20020,13 @@
2000120020
"example": "merchant_1668273825",
2000220021
"maxLength": 255
2000320022
},
20023+
"merchant_order_reference_id": {
20024+
"type": "string",
20025+
"description": "Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.",
20026+
"example": "merchant_order_ref_123",
20027+
"nullable": true,
20028+
"maxLength": 255
20029+
},
2000420030
"amount": {
2000520031
"type": "integer",
2000620032
"format": "int64",
@@ -20279,13 +20305,13 @@
2027920305
"starting_after": {
2028020306
"type": "string",
2028120307
"description": "A cursor for use in pagination, fetch the next list after some object",
20282-
"example": "pay_fafa124123",
20308+
"example": "payout_fafa124123",
2028320309
"nullable": true
2028420310
},
2028520311
"ending_before": {
2028620312
"type": "string",
2028720313
"description": "A cursor for use in pagination, fetch the previous list before some object",
20288-
"example": "pay_fafa124123",
20314+
"example": "payout_fafa124123",
2028920315
"nullable": true
2029020316
},
2029120317
"limit": {
@@ -20332,6 +20358,13 @@
2033220358
"maxLength": 30,
2033320359
"minLength": 30
2033420360
},
20361+
"merchant_order_reference_id": {
20362+
"type": "string",
20363+
"description": "The merchant order reference ID for payout",
20364+
"example": "merchant_order_ref_123",
20365+
"nullable": true,
20366+
"maxLength": 255
20367+
},
2033520368
"profile_id": {
2033620369
"type": "string",
2033720370
"description": "The identifier for business profile",

crates/api_models/src/events/payouts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ use crate::payouts::{
99
impl ApiEventMetric for PayoutRetrieveRequest {
1010
fn get_api_event_type(&self) -> Option<ApiEventsType> {
1111
Some(ApiEventsType::Payout {
12-
payout_id: self.payout_id.clone(),
12+
payout_id: self.payout_id.to_owned(),
1313
})
1414
}
1515
}
1616

1717
impl ApiEventMetric for PayoutCreateRequest {
1818
fn get_api_event_type(&self) -> Option<ApiEventsType> {
1919
self.payout_id.as_ref().map(|id| ApiEventsType::Payout {
20-
payout_id: id.clone(),
20+
payout_id: id.to_owned(),
2121
})
2222
}
2323
}
2424

2525
impl ApiEventMetric for PayoutCreateResponse {
2626
fn get_api_event_type(&self) -> Option<ApiEventsType> {
2727
Some(ApiEventsType::Payout {
28-
payout_id: self.payout_id.clone(),
28+
payout_id: self.payout_id.to_owned(),
2929
})
3030
}
3131
}
3232

3333
impl ApiEventMetric for PayoutActionRequest {
3434
fn get_api_event_type(&self) -> Option<ApiEventsType> {
3535
Some(ApiEventsType::Payout {
36-
payout_id: self.payout_id.clone(),
36+
payout_id: self.payout_id.to_owned(),
3737
})
3838
}
3939
}
@@ -65,7 +65,7 @@ impl ApiEventMetric for PayoutListFilters {
6565
impl ApiEventMetric for PayoutLinkInitiateRequest {
6666
fn get_api_event_type(&self) -> Option<ApiEventsType> {
6767
Some(ApiEventsType::Payout {
68-
payout_id: self.payout_id.clone(),
68+
payout_id: self.payout_id.to_owned(),
6969
})
7070
}
7171
}

crates/api_models/src/payouts.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use utoipa::ToSchema;
1616

1717
use crate::{enums as api_enums, payment_methods::RequiredFieldInfo, payments};
1818

19-
#[derive(Debug, Deserialize, Serialize, Clone, ToSchema)]
19+
#[derive(Debug, Serialize, Clone, ToSchema)]
2020
pub enum PayoutRequest {
2121
PayoutActionRequest(PayoutActionRequest),
2222
PayoutCreateRequest(Box<PayoutCreateRequest>),
@@ -37,13 +37,17 @@ pub struct PayoutCreateRequest {
3737
example = "187282ab-40ef-47a9-9206-5099ba31e432"
3838
)]
3939
#[remove_in(PayoutsCreateRequest, PayoutUpdateRequest, PayoutConfirmRequest)]
40-
pub payout_id: Option<String>, // TODO: #1321 https://github.com/juspay/hyperswitch/issues/1321
40+
pub payout_id: Option<id_type::PayoutId>,
4141

4242
/// This is an identifier for the merchant account. This is inferred from the API key provided during the request, **not required to be included in the Payout Create/Update Request.**
4343
#[schema(max_length = 255, value_type = Option<String>, example = "merchant_1668273825")]
4444
#[remove_in(PayoutsCreateRequest, PayoutUpdateRequest, PayoutConfirmRequest)]
4545
pub merchant_id: Option<id_type::MerchantId>,
4646

47+
/// Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.
48+
#[schema(value_type = Option<String>, max_length = 255, example = "merchant_order_ref_123")]
49+
pub merchant_order_reference_id: Option<String>,
50+
4751
/// The payout amount. Amount for the payout in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc.,
4852
#[schema(value_type = Option<u64>, example = 1000)]
4953
#[mandatory_in(PayoutsCreateRequest = u64)]
@@ -399,13 +403,17 @@ pub struct PayoutCreateResponse {
399403
max_length = 30,
400404
example = "187282ab-40ef-47a9-9206-5099ba31e432"
401405
)]
402-
pub payout_id: String, // TODO: Update this to PayoutIdType similar to PaymentIdType
406+
pub payout_id: id_type::PayoutId,
403407

404408
/// This is an identifier for the merchant account. This is inferred from the API key
405409
/// provided during the request
406410
#[schema(max_length = 255, value_type = String, example = "merchant_1668273825")]
407411
pub merchant_id: id_type::MerchantId,
408412

413+
/// Your unique identifier for this payout or order. This ID helps you reconcile payouts on your system. If provided, it is passed to the connector if supported.
414+
#[schema(value_type = Option<String>, max_length = 255, example = "merchant_order_ref_123")]
415+
pub merchant_order_reference_id: Option<String>,
416+
409417
/// The payout amount. Amount for the payout in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc.,
410418
#[schema(value_type = i64, example = 1000)]
411419
pub amount: common_utils::types::MinorUnit,
@@ -638,7 +646,7 @@ pub struct PayoutRetrieveBody {
638646
pub merchant_id: Option<id_type::MerchantId>,
639647
}
640648

641-
#[derive(Default, Debug, Serialize, ToSchema, Clone, Deserialize)]
649+
#[derive(Debug, Serialize, ToSchema, Clone, Deserialize)]
642650
pub struct PayoutRetrieveRequest {
643651
/// Unique identifier for the payout. This ensures idempotency for multiple payouts
644652
/// that have been done by a single merchant. This field is auto generated and is returned in the API response.
@@ -648,7 +656,7 @@ pub struct PayoutRetrieveRequest {
648656
max_length = 30,
649657
example = "187282ab-40ef-47a9-9206-5099ba31e432"
650658
)]
651-
pub payout_id: String,
659+
pub payout_id: id_type::PayoutId,
652660

653661
/// `force_sync` with the connector to get payout details
654662
/// (defaults to false)
@@ -660,9 +668,7 @@ pub struct PayoutRetrieveRequest {
660668
pub merchant_id: Option<id_type::MerchantId>,
661669
}
662670

663-
#[derive(
664-
Default, Debug, Deserialize, Serialize, Clone, ToSchema, router_derive::PolymorphicSchema,
665-
)]
671+
#[derive(Debug, Serialize, Clone, ToSchema, router_derive::PolymorphicSchema)]
666672
#[generate_schemas(PayoutCancelRequest, PayoutFulfillRequest)]
667673
pub struct PayoutActionRequest {
668674
/// Unique identifier for the payout. This ensures idempotency for multiple payouts
@@ -673,8 +679,7 @@ pub struct PayoutActionRequest {
673679
max_length = 30,
674680
example = "187282ab-40ef-47a9-9206-5099ba31e432"
675681
)]
676-
#[serde(skip_deserializing)]
677-
pub payout_id: String,
682+
pub payout_id: id_type::PayoutId,
678683
}
679684

680685
#[derive(Default, Debug, ToSchema, Clone, Deserialize)]
@@ -722,12 +727,12 @@ pub struct PayoutListConstraints {
722727
pub customer_id: Option<id_type::CustomerId>,
723728

724729
/// A cursor for use in pagination, fetch the next list after some object
725-
#[schema(example = "pay_fafa124123")]
726-
pub starting_after: Option<String>,
730+
#[schema(example = "payout_fafa124123", value_type = Option<String>,)]
731+
pub starting_after: Option<id_type::PayoutId>,
727732

728733
/// A cursor for use in pagination, fetch the previous list before some object
729-
#[schema(example = "pay_fafa124123")]
730-
pub ending_before: Option<String>,
734+
#[schema(example = "payout_fafa124123", value_type = Option<String>,)]
735+
pub ending_before: Option<id_type::PayoutId>,
731736

732737
/// limit on the number of objects to return
733738
#[schema(default = 10, maximum = 100)]
@@ -755,7 +760,10 @@ pub struct PayoutListFilterConstraints {
755760
max_length = 30,
756761
example = "187282ab-40ef-47a9-9206-5099ba31e432"
757762
)]
758-
pub payout_id: Option<String>,
763+
pub payout_id: Option<id_type::PayoutId>,
764+
/// The merchant order reference ID for payout
765+
#[schema(value_type = Option<String>, max_length = 255, example = "merchant_order_ref_123")]
766+
pub merchant_order_reference_id: Option<String>,
759767
/// The identifier for business profile
760768
#[schema(value_type = Option<String>)]
761769
pub profile_id: Option<id_type::ProfileId>,
@@ -826,15 +834,16 @@ pub struct PayoutLinkResponse {
826834
pub struct PayoutLinkInitiateRequest {
827835
#[schema(value_type = String)]
828836
pub merchant_id: id_type::MerchantId,
829-
pub payout_id: String,
837+
#[schema(value_type = String)]
838+
pub payout_id: id_type::PayoutId,
830839
}
831840

832841
#[derive(Clone, Debug, serde::Serialize)]
833842
pub struct PayoutLinkDetails {
834843
pub publishable_key: Secret<String>,
835844
pub client_secret: Secret<String>,
836845
pub payout_link_id: String,
837-
pub payout_id: String,
846+
pub payout_id: id_type::PayoutId,
838847
pub customer_id: id_type::CustomerId,
839848
#[serde(with = "common_utils::custom_serde::iso8601")]
840849
pub session_expiry: PrimitiveDateTime,
@@ -870,7 +879,7 @@ pub struct RequiredFieldsOverrideRequest {
870879
#[derive(Clone, Debug, serde::Serialize)]
871880
pub struct PayoutLinkStatusDetails {
872881
pub payout_link_id: String,
873-
pub payout_id: String,
882+
pub payout_id: id_type::PayoutId,
874883
pub customer_id: id_type::CustomerId,
875884
#[serde(with = "common_utils::custom_serde::iso8601")]
876885
pub session_expiry: PrimitiveDateTime,

crates/api_models/src/webhooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub enum WebhookResponseTracker {
9898
},
9999
#[cfg(feature = "payouts")]
100100
Payout {
101-
payout_id: String,
101+
payout_id: common_utils::id_type::PayoutId,
102102
status: common_enums::PayoutStatus,
103103
},
104104
#[cfg(feature = "v1")]

crates/common_utils/src/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub trait ApiEventMetric {
1212
#[serde(tag = "flow_type", rename_all = "snake_case")]
1313
pub enum ApiEventsType {
1414
Payout {
15-
payout_id: String,
15+
payout_id: id_type::PayoutId,
1616
},
1717
#[cfg(feature = "v1")]
1818
Payment {

crates/common_utils/src/id_type.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod merchant;
1111
mod merchant_connector_account;
1212
mod organization;
1313
mod payment;
14+
mod payout;
1415
mod profile;
1516
mod profile_acquirer;
1617
mod refunds;
@@ -27,6 +28,7 @@ use diesel::{
2728
serialize::{Output, ToSql},
2829
sql_types,
2930
};
31+
pub use payout::PayoutId;
3032
use serde::{Deserialize, Serialize};
3133
use thiserror::Error;
3234

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
crate::id_type!(
2+
PayoutId,
3+
"A domain type for payout_id that can be used for payout ids"
4+
);
5+
crate::impl_id_type_methods!(PayoutId, "payout_id");
6+
crate::impl_debug_id_type!(PayoutId);
7+
crate::impl_try_from_cow_str_id_type!(PayoutId, "payout_id");
8+
crate::impl_generate_id_id_type!(PayoutId, "payout");
9+
crate::impl_queryable_id_type!(PayoutId);
10+
crate::impl_to_sql_from_sql_id_type!(PayoutId);

0 commit comments

Comments
 (0)