Skip to content

Commit

Permalink
feat(router): Better UI payment link and order details product image …
Browse files Browse the repository at this point in the history
…and merchant config support (#2583)

Co-authored-by: Sahkal Poddar <[email protected]>
Co-authored-by: Kashif <[email protected]>
Co-authored-by: Kashif <[email protected]>
Co-authored-by: Bernard Eugine <[email protected]>
Co-authored-by: Kashif <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
7 people authored Oct 17, 2023
1 parent 3807601 commit fdd9580
Show file tree
Hide file tree
Showing 19 changed files with 468 additions and 204 deletions.
22 changes: 22 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ pub struct MerchantAccountCreate {

/// 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 @@ -184,6 +186,8 @@ pub struct MerchantAccountUpdate {
/// 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 @@ -277,6 +281,8 @@ 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 @@ -497,6 +503,22 @@ pub struct PrimaryBusinessDetails {
pub business: String,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct PaymentLinkConfig {
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 primary_color: Option<String>,
pub primary_accent_color: Option<String>,
pub secondary_color: Option<String>,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
#[serde(deny_unknown_fields)]
pub struct WebhookDetails {
Expand Down
21 changes: 21 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ pub struct PaymentsRequest {
"product_name": "gillete creme",
"quantity": 15,
"amount" : 900
"product_img_link" : "https://dummy-img-link.com"
}]"#)]
pub order_details: Option<Vec<OrderDetailsWithAmount>>,

Expand Down Expand Up @@ -2418,6 +2419,8 @@ pub struct OrderDetailsWithAmount {
pub quantity: u16,
/// the amount per quantity of product
pub amount: i64,
/// The image URL of the product
pub product_img_link: Option<String>,
}

#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
Expand All @@ -2428,6 +2431,8 @@ pub struct OrderDetails {
/// The quantity of the product to be purchased
#[schema(example = 1)]
pub quantity: u16,
/// The image URL of the product
pub product_img_link: Option<String>,
}

#[derive(Default, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
Expand Down Expand Up @@ -3120,3 +3125,19 @@ pub struct PaymentLinkInitiateRequest {
pub merchant_id: String,
pub payment_id: String,
}

#[derive(Debug, serde::Serialize)]
pub struct PaymentLinkDetails {
pub amount: i64,
pub currency: api_enums::Currency,
pub pub_key: String,
pub client_secret: String,
pub payment_id: String,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub expiry: PrimitiveDateTime,
pub merchant_logo: String,
pub return_url: String,
pub merchant_name: crypto::OptionalEncryptableName,
pub order_details: Vec<pii::SecretSerdeValue>,
pub max_items_visible_after_collapse: i8,
}
3 changes: 3 additions & 0 deletions crates/diesel_models/src/merchant_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct MerchantAccount {
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
}

#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
Expand Down Expand Up @@ -69,6 +70,7 @@ pub struct MerchantAccountNew {
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
Expand Down Expand Up @@ -97,4 +99,5 @@ pub struct MerchantAccountUpdateInternal {
pub is_recon_enabled: bool,
pub default_profile: Option<Option<String>>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
}
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ diesel::table! {
#[max_length = 64]
default_profile -> Nullable<Varchar>,
recon_status -> ReconStatus,
payment_link_config -> Nullable<Jsonb>,
}
}

Expand Down
13 changes: 13 additions & 0 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ pub async fn create_merchant_account(
.transpose()?
.map(Secret::new);

let payment_link_config = req
.payment_link_config
.as_ref()
.map(|pl_metadata| {
utils::Encode::<admin_types::PaymentLinkConfig>::encode_to_value(pl_metadata)
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "payment_link_config",
})
})
.transpose()?;

let mut merchant_account = async {
Ok(domain::MerchantAccount {
merchant_id: req.merchant_id,
Expand Down Expand Up @@ -171,6 +182,7 @@ pub async fn create_merchant_account(
is_recon_enabled: false,
default_profile: None,
recon_status: diesel_models::enums::ReconStatus::NotRequested,
payment_link_config,
})
}
.await
Expand Down Expand Up @@ -458,6 +470,7 @@ pub async fn merchant_account_update(
intent_fulfillment_time: req.intent_fulfillment_time.map(i64::from),
payout_routing_algorithm: req.payout_routing_algorithm,
default_profile: business_profile_id_update,
payment_link_config: req.payment_link_config,
};

let response = db
Expand Down
Loading

0 comments on commit fdd9580

Please sign in to comment.