Skip to content

Commit fdd9580

Browse files
sahkalkashif-mbernard-eugineKashifgithub-actions[bot]
authored
feat(router): Better UI payment link and order details product image 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>
1 parent 3807601 commit fdd9580

File tree

19 files changed

+468
-204
lines changed

19 files changed

+468
-204
lines changed

crates/api_models/src/admin.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ pub struct MerchantAccountCreate {
9595

9696
/// The id of the organization to which the merchant belongs to
9797
pub organization_id: Option<String>,
98+
99+
pub payment_link_config: Option<PaymentLinkConfig>,
98100
}
99101

100102
#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
@@ -184,6 +186,8 @@ pub struct MerchantAccountUpdate {
184186
/// To unset this field, pass an empty string
185187
#[schema(max_length = 64)]
186188
pub default_profile: Option<String>,
189+
190+
pub payment_link_config: Option<serde_json::Value>,
187191
}
188192

189193
#[derive(Clone, Debug, ToSchema, Serialize)]
@@ -277,6 +281,8 @@ pub struct MerchantAccountResponse {
277281
/// A enum value to indicate the status of recon service. By default it is not_requested.
278282
#[schema(value_type = ReconStatus, example = "not_requested")]
279283
pub recon_status: enums::ReconStatus,
284+
285+
pub payment_link_config: Option<serde_json::Value>,
280286
}
281287

282288
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
@@ -497,6 +503,22 @@ pub struct PrimaryBusinessDetails {
497503
pub business: String,
498504
}
499505

506+
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]
507+
#[serde(deny_unknown_fields)]
508+
pub struct PaymentLinkConfig {
509+
pub merchant_logo: Option<String>,
510+
pub color_scheme: Option<PaymentLinkColorSchema>,
511+
}
512+
513+
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]
514+
#[serde(deny_unknown_fields)]
515+
516+
pub struct PaymentLinkColorSchema {
517+
pub primary_color: Option<String>,
518+
pub primary_accent_color: Option<String>,
519+
pub secondary_color: Option<String>,
520+
}
521+
500522
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
501523
#[serde(deny_unknown_fields)]
502524
pub struct WebhookDetails {

crates/api_models/src/payments.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub struct PaymentsRequest {
226226
"product_name": "gillete creme",
227227
"quantity": 15,
228228
"amount" : 900
229+
"product_img_link" : "https://dummy-img-link.com"
229230
}]"#)]
230231
pub order_details: Option<Vec<OrderDetailsWithAmount>>,
231232

@@ -2418,6 +2419,8 @@ pub struct OrderDetailsWithAmount {
24182419
pub quantity: u16,
24192420
/// the amount per quantity of product
24202421
pub amount: i64,
2422+
/// The image URL of the product
2423+
pub product_img_link: Option<String>,
24212424
}
24222425

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

24332438
#[derive(Default, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
@@ -3120,3 +3125,19 @@ pub struct PaymentLinkInitiateRequest {
31203125
pub merchant_id: String,
31213126
pub payment_id: String,
31223127
}
3128+
3129+
#[derive(Debug, serde::Serialize)]
3130+
pub struct PaymentLinkDetails {
3131+
pub amount: i64,
3132+
pub currency: api_enums::Currency,
3133+
pub pub_key: String,
3134+
pub client_secret: String,
3135+
pub payment_id: String,
3136+
#[serde(with = "common_utils::custom_serde::iso8601")]
3137+
pub expiry: PrimitiveDateTime,
3138+
pub merchant_logo: String,
3139+
pub return_url: String,
3140+
pub merchant_name: crypto::OptionalEncryptableName,
3141+
pub order_details: Vec<pii::SecretSerdeValue>,
3142+
pub max_items_visible_after_collapse: i8,
3143+
}

crates/diesel_models/src/merchant_account.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct MerchantAccount {
4040
pub is_recon_enabled: bool,
4141
pub default_profile: Option<String>,
4242
pub recon_status: storage_enums::ReconStatus,
43+
pub payment_link_config: Option<serde_json::Value>,
4344
}
4445

4546
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
@@ -69,6 +70,7 @@ pub struct MerchantAccountNew {
6970
pub is_recon_enabled: bool,
7071
pub default_profile: Option<String>,
7172
pub recon_status: storage_enums::ReconStatus,
73+
pub payment_link_config: Option<serde_json::Value>,
7274
}
7375

7476
#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
@@ -97,4 +99,5 @@ pub struct MerchantAccountUpdateInternal {
9799
pub is_recon_enabled: bool,
98100
pub default_profile: Option<Option<String>>,
99101
pub recon_status: storage_enums::ReconStatus,
102+
pub payment_link_config: Option<serde_json::Value>,
100103
}

crates/diesel_models/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ diesel::table! {
442442
#[max_length = 64]
443443
default_profile -> Nullable<Varchar>,
444444
recon_status -> ReconStatus,
445+
payment_link_config -> Nullable<Jsonb>,
445446
}
446447
}
447448

crates/router/src/core/admin.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ pub async fn create_merchant_account(
136136
.transpose()?
137137
.map(Secret::new);
138138

139+
let payment_link_config = req
140+
.payment_link_config
141+
.as_ref()
142+
.map(|pl_metadata| {
143+
utils::Encode::<admin_types::PaymentLinkConfig>::encode_to_value(pl_metadata)
144+
.change_context(errors::ApiErrorResponse::InvalidDataValue {
145+
field_name: "payment_link_config",
146+
})
147+
})
148+
.transpose()?;
149+
139150
let mut merchant_account = async {
140151
Ok(domain::MerchantAccount {
141152
merchant_id: req.merchant_id,
@@ -171,6 +182,7 @@ pub async fn create_merchant_account(
171182
is_recon_enabled: false,
172183
default_profile: None,
173184
recon_status: diesel_models::enums::ReconStatus::NotRequested,
185+
payment_link_config,
174186
})
175187
}
176188
.await
@@ -458,6 +470,7 @@ pub async fn merchant_account_update(
458470
intent_fulfillment_time: req.intent_fulfillment_time.map(i64::from),
459471
payout_routing_algorithm: req.payout_routing_algorithm,
460472
default_profile: business_profile_id_update,
473+
payment_link_config: req.payment_link_config,
461474
};
462475

463476
let response = db

0 commit comments

Comments
 (0)