Skip to content

Commit

Permalink
feat(core): implemented platform merchant account (#6882)
Browse files Browse the repository at this point in the history
Co-authored-by: Narayanbhat166 <narayan.bhat@juspay.in>
  • Loading branch information
racnan and Narayanbhat166 authored Dec 23, 2024
1 parent d4b3dbc commit 95fcf2a
Show file tree
Hide file tree
Showing 64 changed files with 595 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/postman-collection-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
CONNECTORS: stripe
RUST_BACKTRACE: short
RUSTUP_MAX_RETRIES: 10
RUST_MIN_STACK: 8388608
RUST_MIN_STACK: 10485760

jobs:
runner:
Expand Down
3 changes: 3 additions & 0 deletions config/deployments/integration_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,6 @@ card_networks = "Visa, AmericanExpress, Mastercard"

[network_tokenization_supported_connectors]
connector_list = "cybersource"

[platform]
enabled = true
3 changes: 3 additions & 0 deletions config/deployments/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,6 @@ card_networks = "Visa, AmericanExpress, Mastercard"

[network_tokenization_supported_connectors]
connector_list = "cybersource"

[platform]
enabled = false
3 changes: 3 additions & 0 deletions config/deployments/sandbox.toml
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,6 @@ card_networks = "Visa, AmericanExpress, Mastercard"

[network_tokenization_supported_connectors]
connector_list = "cybersource"

[platform]
enabled = false
3 changes: 3 additions & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,6 @@ entity_logo_url = "https://example.com/logo.svg" # Logo URL of the entity to be
foreground_color = "#000000" # Foreground color of email text
primary_color = "#006DF9" # Primary color of email body
background_color = "#FFFFFF" # Background color of email body

[platform]
enabled = true
3 changes: 3 additions & 0 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,6 @@ entity_logo_url = "https://example.com/logo.svg" # Logo URL of the entity to be
foreground_color = "#000000" # Foreground color of email text
primary_color = "#006DF9" # Primary color of email body
background_color = "#FFFFFF" # Background color of email body

[platform]
enabled = true
14 changes: 14 additions & 0 deletions crates/diesel_models/src/merchant_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct MerchantAccount {
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
pub version: common_enums::ApiVersion,
pub is_platform_account: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -83,6 +84,7 @@ pub struct MerchantAccountSetter {
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
pub version: common_enums::ApiVersion,
pub is_platform_account: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -117,6 +119,7 @@ impl From<MerchantAccountSetter> for MerchantAccount {
payment_link_config: item.payment_link_config,
pm_collect_link_config: item.pm_collect_link_config,
version: item.version,
is_platform_account: item.is_platform_account,
}
}
}
Expand Down Expand Up @@ -148,6 +151,7 @@ pub struct MerchantAccount {
pub recon_status: storage_enums::ReconStatus,
pub version: common_enums::ApiVersion,
pub id: common_utils::id_type::MerchantId,
pub is_platform_account: bool,
}

#[cfg(feature = "v2")]
Expand All @@ -165,6 +169,7 @@ impl From<MerchantAccountSetter> for MerchantAccount {
organization_id: item.organization_id,
recon_status: item.recon_status,
version: item.version,
is_platform_account: item.is_platform_account,
}
}
}
Expand All @@ -182,6 +187,7 @@ pub struct MerchantAccountSetter {
pub organization_id: common_utils::id_type::OrganizationId,
pub recon_status: storage_enums::ReconStatus,
pub version: common_enums::ApiVersion,
pub is_platform_account: bool,
}

impl MerchantAccount {
Expand Down Expand Up @@ -228,6 +234,7 @@ pub struct MerchantAccountNew {
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
pub version: common_enums::ApiVersion,
pub is_platform_account: bool,
}

#[cfg(feature = "v2")]
Expand All @@ -244,6 +251,7 @@ pub struct MerchantAccountNew {
pub recon_status: storage_enums::ReconStatus,
pub id: common_utils::id_type::MerchantId,
pub version: common_enums::ApiVersion,
pub is_platform_account: bool,
}

#[cfg(feature = "v2")]
Expand All @@ -258,6 +266,7 @@ pub struct MerchantAccountUpdateInternal {
pub modified_at: time::PrimitiveDateTime,
pub organization_id: Option<common_utils::id_type::OrganizationId>,
pub recon_status: Option<storage_enums::ReconStatus>,
pub is_platform_account: Option<bool>,
}

#[cfg(feature = "v2")]
Expand All @@ -272,6 +281,7 @@ impl MerchantAccountUpdateInternal {
modified_at,
organization_id,
recon_status,
is_platform_account,
} = self;

MerchantAccount {
Expand All @@ -286,6 +296,7 @@ impl MerchantAccountUpdateInternal {
recon_status: recon_status.unwrap_or(source.recon_status),
version: source.version,
id: source.id,
is_platform_account: is_platform_account.unwrap_or(source.is_platform_account),
}
}
}
Expand Down Expand Up @@ -319,6 +330,7 @@ pub struct MerchantAccountUpdateInternal {
pub recon_status: Option<storage_enums::ReconStatus>,
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
pub is_platform_account: Option<bool>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -350,6 +362,7 @@ impl MerchantAccountUpdateInternal {
recon_status,
payment_link_config,
pm_collect_link_config,
is_platform_account,
} = self;

MerchantAccount {
Expand Down Expand Up @@ -385,6 +398,7 @@ impl MerchantAccountUpdateInternal {
payment_link_config: payment_link_config.or(source.payment_link_config),
pm_collect_link_config: pm_collect_link_config.or(source.pm_collect_link_config),
version: source.version,
is_platform_account: is_platform_account.unwrap_or(source.is_platform_account),
}
}
}
4 changes: 4 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct PaymentIntent {
pub id: common_utils::id_type::GlobalPaymentId,
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
pub split_payments: Option<common_types::payments::SplitPaymentsRequest>,
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -140,6 +141,7 @@ pub struct PaymentIntent {
pub skip_external_tax_calculation: Option<bool>,
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
pub split_payments: Option<common_types::payments::SplitPaymentsRequest>,
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression, PartialEq)]
Expand Down Expand Up @@ -300,6 +302,7 @@ pub struct PaymentIntentNew {
pub enable_payment_link: Option<bool>,
pub apply_mit_exemption: Option<bool>,
pub id: common_utils::id_type::GlobalPaymentId,
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -366,6 +369,7 @@ pub struct PaymentIntentNew {
pub tax_details: Option<TaxDetails>,
pub skip_external_tax_calculation: Option<bool>,
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
pub split_payments: Option<common_types::payments::SplitPaymentsRequest>,
}

Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ diesel::table! {
payment_link_config -> Nullable<Jsonb>,
pm_collect_link_config -> Nullable<Jsonb>,
version -> ApiVersion,
is_platform_account -> Bool,
}
}

Expand Down Expand Up @@ -970,6 +971,8 @@ diesel::table! {
skip_external_tax_calculation -> Nullable<Bool>,
psd2_sca_exemption_type -> Nullable<ScaExemptionType>,
split_payments -> Nullable<Jsonb>,
#[max_length = 64]
platform_merchant_id -> Nullable<Varchar>,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ diesel::table! {
version -> ApiVersion,
#[max_length = 64]
id -> Varchar,
is_platform_account -> Bool,
}
}

Expand Down Expand Up @@ -933,6 +934,8 @@ diesel::table! {
id -> Varchar,
psd2_sca_exemption_type -> Nullable<ScaExemptionType>,
split_payments -> Nullable<Jsonb>,
#[max_length = 64]
platform_merchant_id -> Nullable<Varchar>,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ pub enum ApiErrorResponse {
message = "Cookies are not found in the request"
)]
CookieNotFound,

#[error(error_type = ErrorType::InvalidRequestError, code = "IR_43", message = "API does not support platform account operation")]
PlatformAccountAuthNotSupported,
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_44", message = "Invalid platform account operation")]
InvalidPlatformOperation,
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_01", message = "Failed to authenticate the webhook")]
WebhookAuthenticationFailed,
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_02", message = "Bad request received in webhook")]
Expand Down Expand Up @@ -667,6 +670,12 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
..Default::default()
})
)),
Self::PlatformAccountAuthNotSupported => {
AER::BadRequest(ApiError::new("IR", 43, "API does not support platform operation", None))
}
Self::InvalidPlatformOperation => {
AER::Unauthorized(ApiError::new("IR", 44, "Invalid platform account operation", None))
}
}
}
}
Expand Down
Loading

0 comments on commit 95fcf2a

Please sign in to comment.