Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): added merchant custom name support for payment link #2685

Merged
merged 7 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,8 @@ pub struct PaymentLinkObject {
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub link_expiry: Option<PrimitiveDateTime>,
pub merchant_custom_domain_name: Option<String>,
/// Custom merchant name for payment link
pub custom_merchant_name: Option<String>,
}

#[derive(Default, Debug, serde::Deserialize, Clone, ToSchema, serde::Serialize)]
Expand Down Expand Up @@ -3141,11 +3143,11 @@ pub struct PaymentLinkDetails {
pub pub_key: String,
pub client_secret: String,
pub payment_id: String,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub expiry: PrimitiveDateTime,
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub expiry: Option<PrimitiveDateTime>,
pub merchant_logo: String,
pub return_url: String,
pub merchant_name: crypto::OptionalEncryptableName,
pub merchant_name: String,
sahkal marked this conversation as resolved.
Show resolved Hide resolved
pub order_details: Vec<pii::SecretSerdeValue>,
pub max_items_visible_after_collapse: i8,
}
3 changes: 2 additions & 1 deletion crates/diesel_models/src/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct PaymentLink {
pub last_modified_at: PrimitiveDateTime,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub fulfilment_time: Option<PrimitiveDateTime>,
pub custom_merchant_name: Option<String>,
}

#[derive(
Clone,
Debug,
Expand All @@ -47,4 +47,5 @@ pub struct PaymentLinkNew {
pub last_modified_at: Option<PrimitiveDateTime>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub fulfilment_time: Option<PrimitiveDateTime>,
pub custom_merchant_name: Option<String>,
}
2 changes: 2 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ diesel::table! {
created_at -> Timestamp,
last_modified_at -> Timestamp,
fulfilment_time -> Nullable<Timestamp>,
#[max_length = 64]
custom_merchant_name -> Nullable<Varchar>,
}
}

Expand Down
32 changes: 16 additions & 16 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use api_models::admin as admin_types;
use common_utils::ext_traits::AsyncExt;
use error_stack::{IntoReport, ResultExt};
use masking::PeekInterface;

use super::errors::{self, RouterResult, StorageErrorExt};
use crate::{
Expand Down Expand Up @@ -43,6 +43,11 @@ pub async fn intiate_payment_link_flow(
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

let payment_link_id = payment_intent
.payment_link_id
.get_required_value("payment_link_id")
.change_context(errors::ApiErrorResponse::PaymentLinkNotFound)?;

helpers::validate_payment_status_against_not_allowed_statuses(
&payment_intent.status,
&[
Expand All @@ -55,20 +60,10 @@ pub async fn intiate_payment_link_flow(
"create payment link",
)?;

let fulfillment_time = payment_intent
.payment_link_id
.as_ref()
.async_and_then(|pli| async move {
db.find_payment_link_by_payment_link_id(pli)
.await
.ok()?
.fulfilment_time
.ok_or(errors::ApiErrorResponse::PaymentNotFound)
.ok()
})
let payment_link = db
.find_payment_link_by_payment_link_id(&payment_link_id)
.await
.get_required_value("fulfillment_time")
.change_context(errors::ApiErrorResponse::PaymentNotFound)?;
.to_not_found_response(errors::ApiErrorResponse::PaymentLinkNotFound)?;

let payment_link_config = merchant_account
.payment_link_config
Expand Down Expand Up @@ -108,10 +103,15 @@ pub async fn intiate_payment_link_flow(
amount: payment_intent.amount,
currency,
payment_id: payment_intent.payment_id,
merchant_name: merchant_account.merchant_name,
merchant_name: payment_link.custom_merchant_name.unwrap_or(
merchant_account
.merchant_name
.map(|merchant_name| merchant_name.into_inner().peek().to_owned())
.unwrap_or_default(),
),
order_details,
return_url,
expiry: fulfillment_time,
expiry: payment_link.fulfilment_time,
pub_key,
client_secret,
merchant_logo: payment_link_config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ async fn create_payment_link(
created_at,
last_modified_at,
fulfilment_time: payment_link_object.link_expiry,
custom_merchant_name: payment_link_object.custom_merchant_name,
};
let payment_link_db = db
.insert_payment_link(payment_link_req)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE payment_link DROP COLUMN custom_merchant_name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE payment_link ADD COLUMN custom_merchant_name VARCHAR(64);
5 changes: 5 additions & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -7866,6 +7866,11 @@
"merchant_custom_domain_name": {
"type": "string",
"nullable": true
},
"custom_merchant_name": {
"type": "string",
"description": "Custom merchant name for payment link",
"nullable": true
}
}
},
Expand Down
Loading