Skip to content

Commit

Permalink
fix(router): Payment link api contract change (#2975)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Kashif <[email protected]>
Co-authored-by: Kashif <[email protected]>
Co-authored-by: hrithikeshvm <[email protected]>
Co-authored-by: hrithikeshvm <[email protected]>
  • Loading branch information
6 people authored Jan 8, 2024
1 parent bfd8a5a commit 3cd7496
Show file tree
Hide file tree
Showing 44 changed files with 1,651 additions and 812 deletions.
86 changes: 51 additions & 35 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,8 @@ pub struct MerchantAccountCreate {
#[schema(value_type = Option<Object>,example = json!({"type": "single", "data": "signifyd"}))]
pub frm_routing_algorithm: Option<serde_json::Value>,

///Will be used to expire client secret after certain amount of time to be supplied in seconds
///(900) for 15 mins
#[schema(example = 900)]
pub intent_fulfillment_time: Option<u32>,

/// The id of the organization to which the merchant belongs to
pub organization_id: Option<String>,

pub payment_link_config: Option<PaymentLinkConfig>,
}

#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
Expand Down Expand Up @@ -185,16 +178,10 @@ pub struct MerchantAccountUpdate {
#[schema(value_type = Option<Object>,example = json!({"type": "single", "data": "signifyd"}))]
pub frm_routing_algorithm: Option<serde_json::Value>,

///Will be used to expire client secret after certain amount of time to be supplied in seconds
///(900) for 15 mins
pub intent_fulfillment_time: Option<u32>,

/// The default business profile that must be used for creating merchant accounts and payments
/// To unset this field, pass an empty string
#[schema(max_length = 64)]
pub default_profile: Option<String>,

pub payment_link_config: Option<serde_json::Value>,
}

#[derive(Clone, Debug, ToSchema, Serialize)]
Expand Down Expand Up @@ -288,8 +275,6 @@ pub struct MerchantAccountResponse {
/// A enum value to indicate the status of recon service. By default it is not_requested.
#[schema(value_type = ReconStatus, example = "not_requested")]
pub recon_status: enums::ReconStatus,

pub payment_link_config: Option<serde_json::Value>,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
Expand Down Expand Up @@ -460,26 +445,6 @@ pub struct PrimaryBusinessDetails {
pub business: String,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct PaymentLinkConfig {
#[schema(
max_length = 255,
max_length = 255,
example = "https://i.imgur.com/RfxPFQo.png"
)]
pub merchant_logo: Option<String>,
pub color_scheme: Option<PaymentLinkColorSchema>,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]

pub struct PaymentLinkColorSchema {
pub background_primary_color: Option<String>,
pub sdk_theme: Option<String>,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
#[serde(deny_unknown_fields)]
pub struct WebhookDetails {
Expand Down Expand Up @@ -1048,6 +1013,13 @@ pub struct BusinessProfileCreate {

/// Verified applepay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,

/// Client Secret Default expiry for all payments created under this business profile
#[schema(example = 900)]
pub session_expiry: Option<u32>,

/// Default Payment Link config for all payment links created under this business profile
pub payment_link_config: Option<BusinessPaymentLinkConfig>,
}

#[derive(Clone, Debug, ToSchema, Serialize)]
Expand Down Expand Up @@ -1112,6 +1084,13 @@ pub struct BusinessProfileResponse {

/// Verified applepay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,

/// Client Secret Default expiry for all payments created under this business profile
#[schema(example = 900)]
pub session_expiry: Option<i64>,

/// Default Payment Link config for all payment links created under this business profile
pub payment_link_config: Option<serde_json::Value>,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
Expand Down Expand Up @@ -1169,4 +1148,41 @@ pub struct BusinessProfileUpdate {

/// Verified applepay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,

/// Client Secret Default expiry for all payments created under this business profile
#[schema(example = 900)]
pub session_expiry: Option<u32>,

/// Default Payment Link config for all payment links created under this business profile
pub payment_link_config: Option<BusinessPaymentLinkConfig>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct BusinessPaymentLinkConfig {
pub domain_name: Option<String>,
#[serde(flatten)]
pub config: PaymentLinkConfigRequest,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct PaymentLinkConfigRequest {
/// custom theme for the payment link
#[schema(value_type = Option<String>, max_length = 255, example = "#4E6ADD")]
pub theme: Option<String>,
/// merchant display logo
#[schema(value_type = Option<String>, max_length = 255, example = "https://i.pinimg.com/736x/4d/83/5c/4d835ca8aafbbb15f84d07d926fda473.jpg")]
pub logo: Option<String>,
/// Custom merchant name for payment link
#[schema(value_type = Option<String>, max_length = 255, example = "hyperswitch")]
pub seller_name: Option<String>,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]
pub struct PaymentLinkConfig {
/// custom theme for the payment link
pub theme: String,
/// merchant display logo
pub logo: String,
/// Custom merchant name for payment link
pub seller_name: String,
}
52 changes: 33 additions & 19 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,14 @@ pub struct PaymentsRequest {

/// additional data that might be required by hyperswitch
pub feature_metadata: Option<FeatureMetadata>,
/// payment link object required for generating the payment_link
pub payment_link_object: Option<PaymentLinkObject>,

/// Whether to get the payment link (if applicable)
#[schema(default = false, example = true)]
pub payment_link: Option<bool>,

/// custom payment link config for the particular payment
#[schema(value_type = Option<PaymentCreatePaymentLinkConfig>)]
pub payment_link_config: Option<PaymentCreatePaymentLinkConfig>,

/// The business profile to use for this payment, if not passed the default business profile
/// associated with the merchant account will be used.
Expand All @@ -314,6 +320,11 @@ pub struct PaymentsRequest {
///Request for an incremental authorization
pub request_incremental_authorization: Option<bool>,

///Will be used to expire client secret after certain amount of time to be supplied in seconds
///(900) for 15 mins
#[schema(example = 900)]
pub session_expiry: Option<u32>,

/// additional data related to some frm connectors
pub frm_metadata: Option<serde_json::Value>,
}
Expand Down Expand Up @@ -3309,17 +3320,6 @@ mod tests {
}
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct PaymentLinkObject {
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub link_expiry: Option<PrimitiveDateTime>,
pub merchant_custom_domain_name: Option<String>,
#[schema(value_type = PaymentLinkConfig)]
pub payment_link_config: Option<admin::PaymentLinkConfig>,
/// Custom merchant name for payment link
pub custom_merchant_name: Option<String>,
}

#[derive(Default, Debug, serde::Deserialize, Clone, ToSchema, serde::Serialize)]
pub struct RetrievePaymentLinkRequest {
pub client_secret: Option<String>,
Expand All @@ -3339,10 +3339,10 @@ pub struct RetrievePaymentLinkResponse {
pub amount: i64,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub created_at: PrimitiveDateTime,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub link_expiry: Option<PrimitiveDateTime>,
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub expiry: Option<PrimitiveDateTime>,
pub description: Option<String>,
pub status: String,
pub status: PaymentLinkStatus,
#[schema(value_type = Option<Currency>)]
pub currency: Option<api_enums::Currency>,
}
Expand All @@ -3360,14 +3360,15 @@ pub struct PaymentLinkDetails {
pub pub_key: String,
pub client_secret: String,
pub payment_id: String,
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub expiry: Option<PrimitiveDateTime>,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub session_expiry: PrimitiveDateTime,
pub merchant_logo: String,
pub return_url: String,
pub merchant_name: String,
pub order_details: Option<Vec<OrderDetailsWithStringAmount>>,
pub max_items_visible_after_collapse: i8,
pub sdk_theme: Option<String>,
pub theme: String,
pub merchant_description: Option<String>,
}

#[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)]
Expand Down Expand Up @@ -3424,6 +3425,13 @@ pub struct PaymentLinkListResponse {
pub data: Vec<PaymentLinkResponse>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct PaymentCreatePaymentLinkConfig {
#[serde(flatten)]
#[schema(value_type = Option<PaymentLinkConfigRequest>)]
pub config: admin::PaymentLinkConfigRequest,
}

#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct OrderDetailsWithStringAmount {
/// Name of the product that is being purchased
Expand All @@ -3437,3 +3445,9 @@ pub struct OrderDetailsWithStringAmount {
/// Product Image link
pub product_img_link: Option<String>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub enum PaymentLinkStatus {
Active,
Expired,
}
11 changes: 7 additions & 4 deletions crates/common_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ pub const SURCHARGE_PERCENTAGE_PRECISION_LENGTH: u8 = 2;
/// Header Key for application overhead of a request
pub const X_HS_LATENCY: &str = "x-hs-latency";

/// SDK Default Theme const
pub const DEFAULT_SDK_THEME: &str = "#7EA8F6";

/// Default Payment Link Background color
pub const DEFAULT_BACKGROUND_COLOR: &str = "#E5E5E5";
pub const DEFAULT_BACKGROUND_COLOR: &str = "#212E46";

/// Default product Img Link
pub const DEFAULT_PRODUCT_IMG: &str = "https://i.imgur.com/On3VtKF.png";
Expand All @@ -50,3 +47,9 @@ pub const PROPHETPAY_REDIRECT_URL: &str = "https://ccm-thirdparty.cps.golf/hp/to

/// Variable which store the card token for Prophetpay
pub const PROPHETPAY_TOKEN: &str = "cctoken";

/// Payment intent fulfillment default timeout (in seconds)
pub const DEFAULT_FULFILLMENT_TIME: i64 = 15 * 60;

/// Payment intent default client secret expiry (in seconds)
pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;
1 change: 1 addition & 0 deletions crates/data_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ pub struct PaymentIntent {
pub request_incremental_authorization: Option<storage_enums::RequestIncrementalAuthorization>,
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub session_expiry: Option<PrimitiveDateTime>,
}
5 changes: 5 additions & 0 deletions crates/data_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct PaymentIntentNew {
pub request_incremental_authorization: Option<storage_enums::RequestIncrementalAuthorization>,
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub session_expiry: Option<PrimitiveDateTime>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -162,6 +163,7 @@ pub enum PaymentIntentUpdate {
metadata: Option<pii::SecretSerdeValue>,
payment_confirm_source: Option<storage_enums::PaymentSource>,
updated_by: String,
session_expiry: Option<PrimitiveDateTime>,
},
PaymentAttemptAndAttemptCountUpdate {
active_attempt_id: String,
Expand Down Expand Up @@ -226,6 +228,7 @@ pub struct PaymentIntentUpdateInternal {
pub surcharge_applicable: Option<bool>,
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub session_expiry: Option<PrimitiveDateTime>,
}

impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
Expand All @@ -249,6 +252,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
metadata,
payment_confirm_source,
updated_by,
session_expiry,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand All @@ -268,6 +272,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
metadata,
payment_confirm_source,
updated_by,
session_expiry,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate {
Expand Down
12 changes: 12 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct BusinessProfile {
pub is_recon_enabled: bool,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub payment_link_config: Option<serde_json::Value>,
pub session_expiry: Option<i64>,
}

#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
Expand All @@ -55,6 +57,8 @@ pub struct BusinessProfileNew {
pub is_recon_enabled: bool,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub payment_link_config: Option<serde_json::Value>,
pub session_expiry: Option<i64>,
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
Expand All @@ -75,6 +79,8 @@ pub struct BusinessProfileUpdateInternal {
pub is_recon_enabled: Option<bool>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub payment_link_config: Option<serde_json::Value>,
pub session_expiry: Option<i64>,
}

impl From<BusinessProfileNew> for BusinessProfile {
Expand All @@ -97,6 +103,8 @@ impl From<BusinessProfileNew> for BusinessProfile {
payout_routing_algorithm: new.payout_routing_algorithm,
is_recon_enabled: new.is_recon_enabled,
applepay_verified_domains: new.applepay_verified_domains,
payment_link_config: new.payment_link_config,
session_expiry: new.session_expiry,
}
}
}
Expand All @@ -118,6 +126,8 @@ impl BusinessProfileUpdateInternal {
payout_routing_algorithm,
is_recon_enabled,
applepay_verified_domains,
payment_link_config,
session_expiry,
} = self;
BusinessProfile {
profile_name: profile_name.unwrap_or(source.profile_name),
Expand All @@ -136,6 +146,8 @@ impl BusinessProfileUpdateInternal {
payout_routing_algorithm,
is_recon_enabled: is_recon_enabled.unwrap_or(source.is_recon_enabled),
applepay_verified_domains,
payment_link_config,
session_expiry,
..source
}
}
Expand Down
Loading

0 comments on commit 3cd7496

Please sign in to comment.