Skip to content

Commit

Permalink
feat(pm_auth): pm_auth service migration (#3047)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarthak Soni <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sarthak Soni <[email protected]>
  • Loading branch information
4 people authored Dec 6, 2023
1 parent 294b04b commit 9c1c44a
Show file tree
Hide file tree
Showing 40 changed files with 2,492 additions and 25 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/CI-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ jobs:
else
echo "test_utils_changes_exist=true" >> $GITHUB_ENV
fi
if git diff --submodule=diff --exit-code --quiet origin/$GITHUB_BASE_REF -- crates/pm_auth/; then
echo "pm_auth_changes_exist=false" >> $GITHUB_ENV
else
echo "pm_auth_changes_exist=true" >> $GITHUB_ENV
fi
- name: Cargo hack api_models
if: env.api_models_changes_exist == 'true'
Expand Down Expand Up @@ -249,6 +254,11 @@ jobs:
shell: bash
run: cargo hack check --each-feature --no-dev-deps -p redis_interface

- name: Cargo hack pm_auth
if: env.pm_auth_changes_exist == 'true'
shell: bash
run: cargo hack check --each-feature --no-dev-deps -p pm_auth

- name: Cargo hack router
if: env.router_changes_exist == 'true'
shell: bash
Expand Down Expand Up @@ -456,6 +466,11 @@ jobs:
else
echo "test_utils_changes_exist=true" >> $GITHUB_ENV
fi
if git diff --submodule=diff --exit-code --quiet origin/$GITHUB_BASE_REF -- crates/pm_auth/; then
echo "pm_auth_changes_exist=false" >> $GITHUB_ENV
else
echo "pm_auth_changes_exist=true" >> $GITHUB_ENV
fi
- name: Cargo hack api_models
if: env.api_models_changes_exist == 'true'
Expand Down Expand Up @@ -502,6 +517,11 @@ jobs:
shell: bash
run: cargo hack check --each-feature --no-dev-deps -p redis_interface

- name: Cargo hack pm_auth
if: env.pm_auth_changes_exist == 'true'
shell: bash
run: cargo hack check --each-feature --no-dev-deps -p pm_auth

- name: Cargo hack router
if: env.router_changes_exist == 'true'
shell: bash
Expand Down
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ kms_encrypted_recon_admin_api_key = "" # Base64-encoded (KMS encrypted) cipher
# like card details
[locker]
host = "" # Locker host
host_rs = "" # Rust Locker host
host_rs = "" # Rust Locker host
mock_locker = true # Emulate a locker locally using Postgres
basilisk_host = "" # Basilisk host
locker_signing_key_id = "1" # Key_id to sign basilisk hs locker
Expand Down Expand Up @@ -461,6 +461,10 @@ apple_pay_merchant_cert_key = "APPLE_PAY_MERCHNAT_CERTIFICATE_KEY" #Private key
[payment_link]
sdk_url = "http://localhost:9090/dist/HyperLoader.js"

[payment_method_auth]
redis_expiry = 900
pm_auth_key = "Some_pm_auth_key"

# Analytics configuration.
[analytics]
source = "sqlx" # The Analytics source/strategy to be used
Expand Down
4 changes: 4 additions & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ apple_pay_merchant_cert_key = "APPLE_PAY_MERCHNAT_CERTIFICATE_KEY"
[payment_link]
sdk_url = "http://localhost:9090/dist/HyperLoader.js"

[payment_method_auth]
redis_expiry = 900
pm_auth_key = "Some_pm_auth_key"

[lock_settings]
redis_lock_expiry_seconds = 180 # 3 * 60 seconds
delay_between_retries_in_milliseconds = 500
Expand Down
4 changes: 4 additions & 0 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ payout_connector_list = "wise"
[multiple_api_version_supported_connectors]
supported_connectors = "braintree"

[payment_method_auth]
redis_expiry = 900
pm_auth_key = "Some_pm_auth_key"

[lock_settings]
redis_lock_expiry_seconds = 180 # 3 * 60 seconds
delay_between_retries_in_milliseconds = 500
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ strum = { version = "0.25", features = ["derive"] }
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }
url = { version = "2.4.0", features = ["serde"] }
utoipa = { version = "3.3.0", features = ["preserve_order"] }
frunk = "0.4.1"
frunk_core = "0.4.1"

# First party crates
cards = { version = "0.1.0", path = "../cards" }
Expand Down
25 changes: 25 additions & 0 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

pub use common_enums::*;
use utoipa::ToSchema;

Expand Down Expand Up @@ -500,3 +502,26 @@ pub enum LockerChoice {
Basilisk,
Tartarus,
}

#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
frunk::LabelledGeneric,
ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum PmAuthConnectors {
Plaid,
}

pub fn convert_pm_auth_connector(connector_name: &str) -> Option<PmAuthConnectors> {
PmAuthConnectors::from_str(connector_name).ok()
}
1 change: 1 addition & 0 deletions crates/api_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod payment_methods;
pub mod payments;
#[cfg(feature = "payouts")]
pub mod payouts;
pub mod pm_auth;
pub mod refunds;
pub mod routing;
pub mod surcharge_decision_configs;
Expand Down
57 changes: 57 additions & 0 deletions crates/api_models/src/pm_auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use common_enums::{PaymentMethod, PaymentMethodType};
use common_utils::{
events::{ApiEventMetric, ApiEventsType},
impl_misc_api_event_type,
};

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub struct LinkTokenCreateRequest {
pub language: Option<String>, // optional language field to be passed
pub client_secret: Option<String>, // client secret to be passed in req body
pub payment_id: String, // payment_id to be passed in req body for redis pm_auth connector name fetch
pub payment_method: PaymentMethod, // payment_method to be used for filtering pm_auth connector
pub payment_method_type: PaymentMethodType, // payment_method_type to be used for filtering pm_auth connector
}

#[derive(Debug, Clone, serde::Serialize)]
pub struct LinkTokenCreateResponse {
pub link_token: String, // link_token received in response
pub connector: String, // pm_auth connector name in response
}

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]

pub struct ExchangeTokenCreateRequest {
pub public_token: String,
pub client_secret: Option<String>,
pub payment_id: String,
pub payment_method: PaymentMethod,
pub payment_method_type: PaymentMethodType,
}

#[derive(Debug, Clone, serde::Serialize)]
pub struct ExchangeTokenCreateResponse {
pub access_token: String,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaymentMethodAuthConfig {
pub enabled_payment_methods: Vec<PaymentMethodAuthConnectorChoice>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaymentMethodAuthConnectorChoice {
pub payment_method: PaymentMethod,
pub payment_method_type: PaymentMethodType,
pub connector_name: String,
pub mca_id: String,
}

impl_misc_api_event_type!(
LinkTokenCreateRequest,
LinkTokenCreateResponse,
ExchangeTokenCreateRequest,
ExchangeTokenCreateResponse
);
27 changes: 27 additions & 0 deletions crates/pm_auth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "pm_auth"
description = "Open banking services"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
readme = "README.md"

[dependencies]
# First party crates
api_models = { version = "0.1.0", path = "../api_models" }
common_enums = { version = "0.1.0", path = "../common_enums" }
common_utils = { version = "0.1.0", path = "../common_utils" }
masking = { version = "0.1.0", path = "../masking" }
router_derive = { version = "0.1.0", path = "../router_derive" }
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }

# Third party crates
async-trait = "0.1.66"
bytes = "1.4.0"
error-stack = "0.3.1"
http = "0.2.9"
mime = "0.3.17"
serde = "1.0.159"
serde_json = "1.0.91"
strum = { version = "0.24.1", features = ["derive"] }
thiserror = "1.0.43"
3 changes: 3 additions & 0 deletions crates/pm_auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Payment Method Auth Services

An open banking services for payment method auth validation
3 changes: 3 additions & 0 deletions crates/pm_auth/src/connector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod plaid;

pub use self::plaid::Plaid;
Loading

0 comments on commit 9c1c44a

Please sign in to comment.