Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(merchant_account_v2): add merchant_account_v2 domain and diesel models (#5365)

Narayan Bhat5861c5a63b3a
diff --git a/.github/scripts/install-jq.sh b/.github/scripts/install-jq.sh
new file mode 100755
index 0000000000..cab7e78195
--- /dev/null
+++ b/.github/scripts/install-jq.sh
@@ -0,0 +1,33 @@
+#! /usr/bin/env bash
+
+set -euo pipefail
+
+if [[ "${CI:-false}" != "true" && "${GITHUB_ACTIONS:-false}" != "true" ]]; then
+ echo "This script is to be run in a GitHub Actions runner only. Exiting."
+ exit 1
+fi
+
+mkdir -p ~/.local/bin
+
+if [[ "${RUNNER_OS}" == 'Linux' && "${RUNNER_ARCH}" == 'X64' ]]; then
+ JQ_ARCH='amd64'
+elif [[ "${RUNNER_OS}" == 'Linux' && "${RUNNER_ARCH}" == 'ARM64' ]]; then
+ JQ_ARCH='arm64'
+else
+ echo "::error::Unsupported runner OS or architecture"
+ exit 1
+fi
+
+# Download latest `jq` binary
+curl \
+ --fail \
+ --silent \
+ --show-error \
+ --location \
+ --output ~/.local/bin/jq \
+ "https://github.com/jqlang/jq/releases/latest/download/jq-linux-${JQ_ARCH}"
+
+chmod +x ~/.local/bin/jq
+
+# Update PATH
+echo "$HOME/.local/bin" >> "${GITHUB_PATH}"
diff --git a/.github/workflows/CI-pr.yml b/.github/workflows/CI-pr.yml
index 7c77d7d44d..4bd50710ce 100644
--- a/.github/workflows/CI-pr.yml
+++ b/.github/workflows/CI-pr.yml
@@ -134,61 +134,23 @@ jobs:
tool: cargo-hack
checksum: true
+ - name: Install just
+ uses: taiki-e/[email protected]
+ with:
+ tool: just
+ checksum: true
+
+ - name: Install jq
+ shell: bash
+ run: .github/scripts/install-jq.sh
+
- name: Deny warnings
shell: bash
run: sed -i 's/rustflags = \[/rustflags = \[\n "-Dwarnings",/' .cargo/config.toml
- - name: Check modified crates
+ - name: Cargo hack
shell: bash
- run: |
- # Obtain a list of workspace members
- workspace_members="$(
- cargo metadata --format-version 1 --no-deps \
- | jq \
- --compact-output \
- --monochrome-output \
- --raw-output \
- '(.workspace_members | sort) as $package_ids | .packages[] | select(IN(.id; $package_ids[])) | .name'
- )"
-
- PACKAGES_CHECKED=()
- PACKAGES_SKIPPED=()
-
- while IFS= read -r package_name; do
- # Obtain comma-separated list of transitive workspace dependencies for each workspace member
- change_paths="$(cargo tree --all-features --no-dedupe --prefix none --package "${package_name}" \
- | grep 'crates/' \
- | sort --unique \
- | awk --field-separator ' ' '{ printf "crates/%s\n", $1 }' | paste -d ',' -s -)"
-
- # Store change paths in an array by splitting `change_paths` by comma
- IFS=',' read -ra change_paths <<< "${change_paths}"
-
- # A package must be checked if any of its transitive dependencies (or itself) has been modified
- if git diff --exit-code --quiet "origin/${GITHUB_BASE_REF}" -- "${change_paths[@]}"; then
- printf '::debug::Skipping `%s` since none of these paths were modified: %s\n' "${package_name}" "${change_paths[*]}"
- PACKAGES_SKIPPED+=("${package_name}")
- else
- printf '::debug::Checking `%s` since at least one of these paths was modified: %s\n' "${package_name}" "${change_paths[*]}"
- PACKAGES_CHECKED+=("${package_name}")
- fi
- done <<< "${workspace_members}"
-
- printf '::notice::Packages checked: %s; Packages skipped: %s\n' "${PACKAGES_CHECKED[*]}" "${PACKAGES_SKIPPED[*]}"
- echo "PACKAGES_CHECKED=${PACKAGES_CHECKED[*]}" >> ${GITHUB_ENV}
- echo "PACKAGES_SKIPPED=${PACKAGES_SKIPPED[*]}" >> ${GITHUB_ENV}
-
- - name: Run `cargo hack` on modified crates
- shell: bash
- run: |
- # Store packages to check in an array by splitting `PACKAGES_CHECKED` by space
- IFS=' ' read -ra PACKAGES_CHECKED <<< "${PACKAGES_CHECKED}"
-
- for package in "${PACKAGES_CHECKED[@]}"; do
- printf '::group::Running `cargo hack` on package `%s`\n' "${package}"
- cargo hack check --each-feature --all-targets --package "${package}"
- echo '::endgroup::'
- done
+ run: just ci_hack
# cargo-deny:
# name: Run cargo-deny
@@ -271,6 +233,16 @@ jobs:
tool: cargo-hack
checksum: true
+ - name: Install just
+ uses: taiki-e/[email protected]
+ with:
+ tool: just
+ checksum: true
+
+ - name: Install jq
+ shell: bash
+ run: .github/scripts/install-jq.sh
+
# - name: Install cargo-nextest
# uses: taiki-e/[email protected]
# with:
@@ -289,7 +261,7 @@ jobs:
- name: Run clippy
shell: bash
- run: cargo clippy --all-features --all-targets
+ run: just clippy
- name: Check Cargo.lock changed
if: ${{ (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) }}
@@ -303,57 +275,9 @@ jobs:
git push
fi
- - name: Check modified crates
- shell: bash
- run: |
- # Obtain a list of workspace members
- workspace_members="$(
- cargo metadata --format-version 1 --no-deps \
- | jq \
- --compact-output \
- --monochrome-output \
- --raw-output \
- '(.workspace_members | sort) as $package_ids | .packages[] | select(IN(.id; $package_ids[])) | .name'
- )"
-
- PACKAGES_CHECKED=()
- PACKAGES_SKIPPED=()
-
- while IFS= read -r package_name; do
- # Obtain comma-separated list of transitive workspace dependencies for each workspace member
- change_paths="$(cargo tree --all-features --no-dedupe --prefix none --package "${package_name}" \
- | grep 'crates/' \
- | sort --unique \
- | awk --field-separator ' ' '{ printf "crates/%s\n", $1 }' | paste -d ',' -s -)"
-
- # Store change paths in an array by splitting `change_paths` by comma
- IFS=',' read -ra change_paths <<< "${change_paths}"
-
- # A package must be checked if any of its transitive dependencies (or itself) has been modified
- if git diff --exit-code --quiet "origin/${GITHUB_BASE_REF}" -- "${change_paths[@]}"; then
- printf '::debug::Skipping `%s` since none of these paths were modified: %s\n' "${package_name}" "${change_paths[*]}"
- PACKAGES_SKIPPED+=("${package_name}")
- else
- printf '::debug::Checking `%s` since at least one of these paths was modified: %s\n' "${package_name}" "${change_paths[*]}"
- PACKAGES_CHECKED+=("${package_name}")
- fi
- done <<< "${workspace_members}"
-
- printf '::notice::Packages checked: %s; Packages skipped: %s\n' "${PACKAGES_CHECKED[*]}" "${PACKAGES_SKIPPED[*]}"
- echo "PACKAGES_CHECKED=${PACKAGES_CHECKED[*]}" >> ${GITHUB_ENV}
- echo "PACKAGES_SKIPPED=${PACKAGES_SKIPPED[*]}" >> ${GITHUB_ENV}
-
- - name: Run `cargo hack` on modified crates
+ - name: Run cargo check
shell: bash
- run: |
- # Store packages to check in an array by splitting `PACKAGES_CHECKED` by space
- IFS=' ' read -ra PACKAGES_CHECKED <<< "${PACKAGES_CHECKED}"
-
- for package in "${PACKAGES_CHECKED[@]}"; do
- printf '::group::Running `cargo hack` on package `%s`\n' "${package}"
- cargo hack check --each-feature --all-targets --package "${package}"
- echo '::endgroup::'
- done
+ run: just ci_hack
typos:
name: Spell check
diff --git a/.github/workflows/CI-push.yml b/.github/workflows/CI-push.yml
index debfdd31a4..a25667fc28 100644
--- a/.github/workflows/CI-push.yml
+++ b/.github/workflows/CI-push.yml
@@ -77,6 +77,16 @@ jobs:
with:
crate: cargo-hack
+ - name: Install just
+ uses: taiki-e/[email protected]
+ with:
+ tool: just
+ checksum: true
+
+ - name: Install jq
+ shell: bash
+ run: .github/scripts/install-jq.sh
+
- name: Deny warnings
shell: bash
run: sed -i 's/rustflags = \[/rustflags = \[\n "-Dwarnings",/' .cargo/config.toml
@@ -84,7 +94,7 @@ jobs:
- name: Cargo hack
if: ${{ github.event_name == 'push' }}
shell: bash
- run: cargo hack check --workspace --each-feature --all-targets
+ run: just ci_hack
- name: Cargo build release
if: ${{ github.event_name == 'merge_group' }}
@@ -143,6 +153,16 @@ jobs:
with:
crate: cargo-hack
+ - name: Install just
+ uses: taiki-e/[email protected]
+ with:
+ tool: just
+ checksum: true
+
+ - name: Install jq
+ shell: bash
+ run: .github/scripts/install-jq.sh
+
# - name: Install cargo-nextest
# uses: baptiste0928/[email protected]
# with:
@@ -164,12 +184,12 @@ jobs:
- name: Run clippy
shell: bash
- run: cargo clippy --all-features --all-targets
+ run: just clippy
- name: Cargo hack
if: ${{ github.event_name == 'push' }}
shell: bash
- run: cargo hack check --workspace --each-feature --all-targets
+ run: just ci_hack
- name: Cargo build release
if: ${{ github.event_name == 'merge_group' }}
diff --git a/Makefile b/Makefile
index 4d12fdafb5..3f8dc2e601 100644
--- a/Makefile
+++ b/Makefile
@@ -112,4 +112,4 @@ precommit : fmt clippy test
hack:
- cargo hack check --workspace --each-feature --all-targets
+ cargo hack check --workspace --each-feature --all-targets --exclude-features 'v2 merchant_account_v2 payment_v2'
diff --git a/crates/analytics/Cargo.toml b/crates/analytics/Cargo.toml
index 9ef0e624fc..a43071b5a1 100644
--- a/crates/analytics/Cargo.toml
+++ b/crates/analytics/Cargo.toml
@@ -6,6 +6,11 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
+[features]
+default = ["v1"]
+v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1"]
+v2 = ["api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2"]
+
[dependencies]
# First party crates
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
diff --git a/crates/api_models/Cargo.toml b/crates/api_models/Cargo.toml
index 9c9e1b8501..aced6a293a 100644
--- a/crates/api_models/Cargo.toml
+++ b/crates/api_models/Cargo.toml
@@ -8,7 +8,7 @@ readme = "README.md"
license.workspace = true
[features]
-default = []
+default = ["v1"]
errors = ["dep:actix-web", "dep:reqwest"]
dummy_connector = ["euclid/dummy_connector", "common_enums/dummy_connector"]
detailed_errors = []
@@ -18,6 +18,9 @@ olap = []
openapi = ["common_enums/openapi", "olap", "recon", "dummy_connector", "olap"]
recon = []
v2 = []
+v1 = []
+merchant_account_v2 = []
+payment_v2 = []
[dependencies]
actix-web = { version = "4.5.1", optional = true }
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index b22e028639..853f4308b1 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -1,7 +1,5 @@
use std::collections::{HashMap, HashSet};
-#[cfg(feature = "v2")]
-use common_utils::new_type;
use common_utils::{
consts,
crypto::Encryptable,
@@ -9,9 +7,12 @@ use common_utils::{
ext_traits::Encode,
id_type, link_utils, pii,
};
-#[cfg(not(feature = "v2"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
use common_utils::{crypto::OptionalEncryptableName, ext_traits::ValueExt};
-#[cfg(feature = "v2")]
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
use masking::ExposeInterface;
use masking::Secret;
use serde::{Deserialize, Serialize};
@@ -19,7 +20,10 @@ use url;
use utoipa::ToSchema;
use super::payments::AddressDetails;
-#[cfg(not(feature = "v2"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
use crate::routing;
use crate::{enums as api_enums, payment_methods};
@@ -28,7 +32,10 @@ pub struct MerchantAccountListRequest {
pub organization_id: String,
}
-#[cfg(not(feature = "v2"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
#[serde(deny_unknown_fields)]
pub struct MerchantAccountCreate {
@@ -108,7 +115,10 @@ pub struct MerchantAccountCreate {
pub pm_collect_link_config: Option<BusinessCollectLinkConfig>,
}
-#[cfg(not(feature = "v2"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
impl MerchantAccountCreate {
pub fn get_merchant_reference_id(&self) -> id_type::MerchantId {
self.merchant_id.clone()
@@ -182,13 +192,13 @@ impl MerchantAccountCreate {
}
}
-#[cfg(feature = "v2")]
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
#[serde(deny_unknown_fields)]
pub struct MerchantAccountCreate {
/// Name of the Merchant Account, This will be used as a prefix to generate the id
#[schema(value_type= String, max_length = 64, example = "NewAge Retailer")]
- pub merchant_name: Secret<new_type::MerchantName>,
+ pub merchant_name: Secret<common_utils::new_type::MerchantName>,
/// Details about the merchant, contains phone and emails of primary and secondary contact person.
pub merchant_details: Option<MerchantDetails>,
@@ -201,7 +211,7 @@ pub struct MerchantAccountCreate {
pub organization_id: String,
}
-#[cfg(feature = "v2")]
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
impl MerchantAccountCreate {
pub fn get_merchant_reference_id(&self) -> id_type::MerchantId {
id_type::MerchantId::from_merchant_name(self.merchant_name.clone().expose())
@@ -327,7 +337,10 @@ pub struct MerchantAccountUpdate {
pub pm_collect_link_config: Option<BusinessCollectLinkConfig>,
}
-#[cfg(not(feature = "v2"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
#[derive(Clone, Debug, ToSchema, Serialize)]
pub struct MerchantAccountResponse {
/// The identifier for the Merchant Account
@@ -419,7 +432,7 @@ pub struct MerchantAccountResponse {
pub pm_collect_link_config: Option<BusinessCollectLinkConfig>,
}
-#[cfg(feature = "v2")]
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
#[derive(Clone, Debug, ToSchema, Serialize)]
pub struct MerchantAccountResponse {
/// The identifier for the Merchant Account
diff --git a/crates/diesel_models/Cargo.toml b/crates/diesel_models/Cargo.toml
index 10890ef0cf..df410a1d5f 100644
--- a/crates/diesel_models/Cargo.toml
+++ b/crates/diesel_models/Cargo.toml
@@ -8,8 +8,12 @@ readme = "README.md"
license.workspace = true
[features]
-default = ["kv_store"]
+default = ["kv_store", "v1"]
kv_store = []
+v1 = []
+v2 = []
+merchant_account_v2 = []
+payment_v2 = []
[dependencies]
async-bb8-diesel = { git = "https://github.com/jarnura/async-bb8-diesel", rev = "53b4ab901aab7635c8215fd1c2d542c8db443094" }
diff --git a/crates/diesel_models/src/lib.rs b/crates/diesel_models/src/lib.rs
index 6af1e0e520..37b0ee4d16 100644
--- a/crates/diesel_models/src/lib.rs
+++ b/crates/diesel_models/src/lib.rs
@@ -41,8 +41,12 @@ pub mod refund;
pub mod reverse_lookup;
pub mod role;
pub mod routing_algorithm;
+
#[allow(unused_qualifications)]
pub mod schema;
+#[allow(unused_qualifications)]
+pub mod schema_v2;
+
pub mod user;
pub mod user_authentication_method;
pub mod user_key_store;
diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs
index 5c48ade55c..a8a2e7ce19 100644
--- a/crates/diesel_models/src/merchant_account.rs
+++ b/crates/diesel_models/src/merchant_account.rs
@@ -1,19 +1,30 @@
use common_utils::{encryption::Encryption, pii};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
-use crate::{enums as storage_enums, schema::merchant_account};
+use crate::enums as storage_enums;
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
+use crate::schema::merchant_account;
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
+use crate::schema_v2::merchant_account;
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
#[derive(
Clone,
Debug,
serde::Deserialize,
- serde::Serialize,
Identifiable,
+ serde::Serialize,
Queryable,
Selectable,
router_derive::DebugAsDisplay,
)]
-#[diesel(table_name = merchant_account, check_for_backend(diesel::pg::Pg))]
+#[diesel(table_name = merchant_account, primary_key(merchant_id), check_for_backend(diesel::pg::Pg))]
pub struct MerchantAccount {
pub id: i32,
pub merchant_id: String,
@@ -45,6 +56,48 @@ pub struct MerchantAccount {
pub pm_collect_link_config: Option<serde_json::Value>,
}
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
+#[derive(
+ Clone,
+ Debug,
+ serde::Deserialize,
+ Identifiable,
+ serde::Serialize,
+ Queryable,
+ router_derive::DebugAsDisplay,
+ Selectable,
+)]
+#[diesel(table_name = merchant_account, primary_key(merchant_id), check_for_backend(diesel::pg::Pg))]
+pub struct MerchantAccount {
+ pub merchant_id: String,
+ pub return_url: Option<String>,
+ pub enable_payment_response_hash: bool,
+ pub payment_response_hash_key: Option<String>,
+ pub redirect_to_merchant_with_http_post: bool,
+ pub merchant_name: Option<Encryption>,
+ pub merchant_details: Option<Encryption>,
+ pub webhook_details: Option<serde_json::Value>,
+ pub sub_merchants_enabled: Option<bool>,
+ pub parent_merchant_id: Option<String>,
+ pub publishable_key: Option<String>,
+ pub storage_scheme: storage_enums::MerchantStorageScheme,
+ pub locker_id: Option<String>,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub routing_algorithm: Option<serde_json::Value>,
+ pub primary_business_details: serde_json::Value,
+ pub intent_fulfillment_time: Option<i64>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub frm_routing_algorithm: Option<serde_json::Value>,
+ pub payout_routing_algorithm: Option<serde_json::Value>,
+ pub organization_id: String,
+ pub is_recon_enabled: bool,
+ pub default_profile: Option<String>,
+ pub recon_status: storage_enums::ReconStatus,
+ pub payment_link_config: Option<serde_json::Value>,
+ pub pm_collect_link_config: Option<serde_json::Value>,
+}
+
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_account)]
pub struct MerchantAccountNew {
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 40899ffcb8..880bf99b3c 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -3,13 +3,86 @@ use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
-use crate::{
- enums::{self as storage_enums},
- schema::payment_attempt,
-};
+use crate::enums::{self as storage_enums};
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+use crate::schema::payment_attempt;
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+use crate::schema_v2::payment_attempt;
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
#[derive(
- Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize,
+ Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable,
+)]
+#[diesel(table_name = payment_attempt, primary_key(attempt_id, merchant_id), check_for_backend(diesel::pg::Pg))]
+pub struct PaymentAttempt {
+ pub payment_id: String,
+ pub merchant_id: String,
+ pub attempt_id: String,
+ pub status: storage_enums::AttemptStatus,
+ pub amount: i64,
+ pub currency: Option<storage_enums::Currency>,
+ pub save_to_locker: Option<bool>,
+ pub connector: Option<String>,
+ pub error_message: Option<String>,
+ pub offer_amount: Option<i64>,
+ pub surcharge_amount: Option<i64>,
+ pub tax_amount: Option<i64>,
+ pub payment_method_id: Option<String>,
+ pub payment_method: Option<storage_enums::PaymentMethod>,
+ pub connector_transaction_id: Option<String>,
+ pub capture_method: Option<storage_enums::CaptureMethod>,
+ #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
+ pub capture_on: Option<PrimitiveDateTime>,
+ pub confirm: bool,
+ pub authentication_type: Option<storage_enums::AuthenticationType>,
+ #[serde(with = "common_utils::custom_serde::iso8601")]
+ pub created_at: PrimitiveDateTime,
+ #[serde(with = "common_utils::custom_serde::iso8601")]
+ pub modified_at: PrimitiveDateTime,
+ #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
+ pub last_synced: Option<PrimitiveDateTime>,
+ pub cancellation_reason: Option<String>,
+ pub amount_to_capture: Option<i64>,
+ pub mandate_id: Option<String>,
+ pub browser_info: Option<serde_json::Value>,
+ pub error_code: Option<String>,
+ pub payment_token: Option<String>,
+ pub connector_metadata: Option<serde_json::Value>,
+ pub payment_experience: Option<storage_enums::PaymentExperience>,
+ pub payment_method_type: Option<storage_enums::PaymentMethodType>,
+ pub payment_method_data: Option<serde_json::Value>,
+ pub business_sub_label: Option<String>,
+ pub straight_through_algorithm: Option<serde_json::Value>,
+ pub preprocessing_step_id: Option<String>,
+ // providing a location to store mandate details intermediately for transaction
+ pub mandate_details: Option<storage_enums::MandateDataType>,
+ pub error_reason: Option<String>,
+ pub multiple_capture_count: Option<i16>,
+ // reference to the payment at connector side
+ pub connector_response_reference_id: Option<String>,
+ pub amount_capturable: i64,
+ pub updated_by: String,
+ pub merchant_connector_id: Option<String>,
+ pub authentication_data: Option<serde_json::Value>,
+ pub encoded_data: Option<String>,
+ pub unified_code: Option<String>,
+ pub unified_message: Option<String>,
+ pub net_amount: Option<i64>,
+ pub external_three_ds_authentication_attempted: Option<bool>,
+ pub authentication_connector: Option<String>,
+ pub authentication_id: Option<String>,
+ pub mandate_data: Option<storage_enums::MandateDetails>,
+ pub fingerprint_id: Option<String>,
+ pub payment_method_billing_address_id: Option<String>,
+ pub charge_id: Option<String>,
+ pub client_source: Option<String>,
+ pub client_version: Option<String>,
+ pub customer_acceptance: Option<pii::SecretSerdeValue>,
+}
+
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+#[derive(
+ Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable,
)]
#[diesel(table_name = payment_attempt, primary_key(attempt_id, merchant_id), check_for_backend(diesel::pg::Pg))]
pub struct PaymentAttempt {
diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs
index e4d8dcc315..f7ec26e120 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -4,9 +4,74 @@ use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
-use crate::{enums as storage_enums, schema::payment_intent};
+use crate::enums as storage_enums;
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+use crate::schema::payment_intent;
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+use crate::schema_v2::payment_intent;
-#[derive(Clone, Debug, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize)]
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+#[derive(Clone, Debug, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable)]
+#[diesel(table_name = payment_intent, primary_key(payment_id, merchant_id), check_for_backend(diesel::pg::Pg))]
+pub struct PaymentIntent {
+ pub payment_id: String,
+ pub merchant_id: String,
+ pub status: storage_enums::IntentStatus,
+ pub amount: MinorUnit,
+ pub currency: Option<storage_enums::Currency>,
+ pub amount_captured: Option<MinorUnit>,
+ pub customer_id: Option<id_type::CustomerId>,
+ pub description: Option<String>,
+ pub return_url: Option<String>,
+ pub metadata: Option<serde_json::Value>,
+ pub connector_id: Option<String>,
+ pub shipping_address_id: Option<String>,
+ pub billing_address_id: Option<String>,
+ pub statement_descriptor_name: Option<String>,
+ pub statement_descriptor_suffix: Option<String>,
+ #[serde(with = "common_utils::custom_serde::iso8601")]
+ pub created_at: PrimitiveDateTime,
+ #[serde(with = "common_utils::custom_serde::iso8601")]
+ pub modified_at: PrimitiveDateTime,
+ #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
+ pub last_synced: Option<PrimitiveDateTime>,
+ pub setup_future_usage: Option<storage_enums::FutureUsage>,
+ pub off_session: Option<bool>,
+ pub client_secret: Option<String>,
+ pub active_attempt_id: String,
+ pub business_country: Option<storage_enums::CountryAlpha2>,
+ pub business_label: Option<String>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
+ pub order_details: Option<Vec<pii::SecretSerdeValue>>,
+ pub allowed_payment_method_types: Option<serde_json::Value>,
+ pub connector_metadata: Option<serde_json::Value>,
+ pub feature_metadata: Option<serde_json::Value>,
+ pub attempt_count: i16,
+ pub profile_id: Option<String>,
+ // Denotes the action(approve or reject) taken by merchant in case of manual review.
+ // Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
+ pub merchant_decision: Option<String>,
+ pub payment_link_id: Option<String>,
+ pub payment_confirm_source: Option<storage_enums::PaymentSource>,
+
+ pub updated_by: String,
+ pub surcharge_applicable: Option<bool>,
+ pub request_incremental_authorization: Option<RequestIncrementalAuthorization>,
+ pub incremental_authorization_allowed: Option<bool>,
+ pub authorization_count: Option<i32>,
+ pub session_expiry: Option<PrimitiveDateTime>,
+ pub fingerprint_id: Option<String>,
+ pub request_external_three_ds_authentication: Option<bool>,
+ pub charges: Option<pii::SecretSerdeValue>,
+ pub frm_metadata: Option<pii::SecretSerdeValue>,
+ pub customer_details: Option<Encryption>,
+ pub billing_details: Option<Encryption>,
+ pub merchant_order_reference_id: Option<String>,
+ pub shipping_details: Option<Encryption>,
+}
+
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+#[derive(Clone, Debug, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable)]
#[diesel(table_name = payment_intent, primary_key(payment_id, merchant_id), check_for_backend(diesel::pg::Pg))]
pub struct PaymentIntent {
pub id: Option<i32>,
diff --git a/crates/diesel_models/src/query/merchant_account.rs b/crates/diesel_models/src/query/merchant_account.rs
index 66526e11cb..5c0857fc07 100644
--- a/crates/diesel_models/src/query/merchant_account.rs
+++ b/crates/diesel_models/src/query/merchant_account.rs
@@ -1,10 +1,16 @@
use diesel::{associations::HasTable, ExpressionMethods, Table};
use super::generics;
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
+use crate::schema::merchant_account::dsl;
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
+use crate::schema_v2::merchant_account::dsl;
use crate::{
errors,
merchant_account::{MerchantAccount, MerchantAccountNew, MerchantAccountUpdateInternal},
- schema::merchant_account::dsl,
PgPooledConn, StorageResult,
};
diff --git a/crates/diesel_models/src/query/payment_attempt.rs b/crates/diesel_models/src/query/payment_attempt.rs
index 4e5773800a..8145b5b11f 100644
--- a/crates/diesel_models/src/query/payment_attempt.rs
+++ b/crates/diesel_models/src/query/payment_attempt.rs
@@ -8,6 +8,10 @@ use diesel::{
use error_stack::{report, ResultExt};
use super::generics;
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+use crate::schema::payment_attempt::dsl;
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+use crate::schema_v2::payment_attempt::dsl;
use crate::{
enums::{self, IntentStatus},
errors::DatabaseError,
@@ -15,7 +19,6 @@ use crate::{
PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate, PaymentAttemptUpdateInternal,
},
query::generics::db_metrics,
- schema::payment_attempt::dsl,
PaymentIntent, PgPooledConn, StorageResult,
};
diff --git a/crates/diesel_models/src/query/payment_intent.rs b/crates/diesel_models/src/query/payment_intent.rs
index 82904e5a56..b658f8d9c9 100644
--- a/crates/diesel_models/src/query/payment_intent.rs
+++ b/crates/diesel_models/src/query/payment_intent.rs
@@ -1,12 +1,15 @@
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods};
use super::generics;
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+use crate::schema::payment_intent::dsl;
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+use crate::schema_v2::payment_intent::dsl;
use crate::{
errors,
payment_intent::{
PaymentIntent, PaymentIntentNew, PaymentIntentUpdate, PaymentIntentUpdateInternal,
},
- schema::payment_intent::dsl,
PgPooledConn, StorageResult,
};
diff --git a/crates/diesel_models/src/query/user/sample_data.rs b/crates/diesel_models/src/query/user/sample_data.rs
index 3a26b2cda8..00fcdbe7ee 100644
--- a/crates/diesel_models/src/query/user/sample_data.rs
+++ b/crates/diesel_models/src/query/user/sample_data.rs
@@ -3,13 +3,16 @@ use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpress
use error_stack::ResultExt;
use router_env::logger;
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+use crate::schema::{
+ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl,
+};
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+use crate::schema_v2::{
+ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl,
+};
use crate::{
- errors,
- schema::{
- payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl,
- refund::dsl as refund_dsl,
- },
- user::sample_data::PaymentAttemptBatchNew,
+ errors, schema::refund::dsl as refund_dsl, user::sample_data::PaymentAttemptBatchNew,
PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew,
StorageResult,
};
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index c831bbfa70..164600c88a 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -634,7 +634,6 @@ diesel::table! {
use crate::enums::diesel_exports::*;
merchant_account (merchant_id) {
- id -> Int4,
#[max_length = 64]
merchant_id -> Varchar,
#[max_length = 255]
diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs
index 7a0f00acf8..c1ccdfa450 100644
--- a/crates/diesel_models/src/user/sample_data.rs
+++ b/crates/diesel_models/src/user/sample_data.rs
@@ -5,9 +5,12 @@ use common_enums::{
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
+use crate::schema::payment_attempt;
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+use crate::schema_v2::payment_attempt;
use crate::{
enums::{MandateDataType, MandateDetails},
- schema::payment_attempt,
PaymentAttemptNew,
};
diff --git a/crates/drainer/Cargo.toml b/crates/drainer/Cargo.toml
index c3e6b42135..93e5512222 100644
--- a/crates/drainer/Cargo.toml
+++ b/crates/drainer/Cargo.toml
@@ -10,6 +10,7 @@ license.workspace = true
[features]
release = ["vergen", "external_services/aws_kms"]
vergen = ["router_env/vergen"]
+v1 = ["diesel_models/v1"]
[dependencies]
actix-web = "4.5.1"
diff --git a/crates/hyperswitch_domain_models/Cargo.toml b/crates/hyperswitch_domain_models/Cargo.toml
index 310c2731b4..65348fd493 100644
--- a/crates/hyperswitch_domain_models/Cargo.toml
+++ b/crates/hyperswitch_domain_models/Cargo.toml
@@ -8,18 +8,22 @@ readme = "README.md"
license.workspace = true
[features]
-default = ["olap", "payouts", "frm"]
-encryption_service =[]
+default = ["olap", "payouts", "frm", "v1"]
+encryption_service = []
olap = []
payouts = ["api_models/payouts"]
frm = ["api_models/frm"]
+v2 = ["api_models/v2", "diesel_models/v2"]
+v1 = ["api_models/v1", "diesel_models/v1"]
+merchant_account_v2 = ["api_models/merchant_account_v2", "diesel_models/merchant_account_v2"]
+payment_v2 = ["api_models/payment_v2", "diesel_models/payment_v2"]
[dependencies]
# First party deps
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
cards = { version = "0.1.0", path = "../cards" }
common_enums = { version = "0.1.0", path = "../common_enums" }
-common_utils = { version = "0.1.0", path = "../common_utils", features = ["async_ext", "metrics", "encryption_service", "keymanager"] }
+common_utils = { version = "0.1.0", path = "../common_utils", features = ["async_ext", "metrics", "encryption_service", "keymanager"] }
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] }
masking = { version = "0.1.0", path = "../masking" }
router_derive = { version = "0.1.0", path = "../router_derive" }
diff --git a/crates/hyperswitch_domain_models/src/merchant_account.rs b/crates/hyperswitch_domain_models/src/merchant_account.rs
index a430673c59..ecabea752c 100644
--- a/crates/hyperswitch_domain_models/src/merchant_account.rs
+++ b/crates/hyperswitch_domain_models/src/merchant_account.rs
@@ -5,7 +5,7 @@ use common_utils::{
errors::{CustomResult, ValidationError},
ext_traits::ValueExt,
pii,
- types::keymanager,
+ types::keymanager::{self},
};
use diesel_models::{
enums::MerchantStorageScheme, merchant_account::MerchantAccountUpdateInternal,
@@ -16,6 +16,10 @@ use router_env::logger;
use crate::type_encryption::{decrypt, AsyncLift};
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
#[derive(Clone, Debug, serde::Serialize)]
pub struct MerchantAccount {
pub id: Option<i32>,
@@ -48,6 +52,38 @@ pub struct MerchantAccount {
pub pm_collect_link_config: Option<serde_json::Value>,
}
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
+#[derive(Clone, Debug, serde::Serialize)]
+pub struct MerchantAccount {
+ pub merchant_id: String,
+ pub return_url: Option<String>,
+ pub enable_payment_response_hash: bool,
+ pub payment_response_hash_key: Option<String>,
+ pub redirect_to_merchant_with_http_post: bool,
+ pub merchant_name: OptionalEncryptableName,
+ pub merchant_details: OptionalEncryptableValue,
+ pub webhook_details: Option<serde_json::Value>,
+ pub sub_merchants_enabled: Option<bool>,
+ pub parent_merchant_id: Option<String>,
+ pub publishable_key: String,
+ pub storage_scheme: MerchantStorageScheme,
+ pub locker_id: Option<String>,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub routing_algorithm: Option<serde_json::Value>,
+ pub primary_business_details: serde_json::Value,
+ pub frm_routing_algorithm: Option<serde_json::Value>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub intent_fulfillment_time: Option<i64>,
+ pub payout_routing_algorithm: Option<serde_json::Value>,
+ pub organization_id: String,
+ pub is_recon_enabled: bool,
+ pub default_profile: Option<String>,
+ pub recon_status: diesel_models::enums::ReconStatus,
+ pub payment_link_config: Option<serde_json::Value>,
+ pub pm_collect_link_config: Option<serde_json::Value>,
+}
+
#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
pub enum MerchantAccountUpdate {
@@ -156,6 +192,140 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
}
}
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
+#[async_trait::async_trait]
+impl super::behaviour::Conversion for MerchantAccount {
+ type DstType = diesel_models::merchant_account::MerchantAccount;
+ type NewDstType = diesel_models::merchant_account::MerchantAccountNew;
+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
+ Ok(diesel_models::merchant_account::MerchantAccount {
+ merchant_id: self.merchant_id,
+ return_url: self.return_url,
+ enable_payment_response_hash: self.enable_payment_response_hash,
+ payment_response_hash_key: self.payment_response_hash_key,
+ redirect_to_merchant_with_http_post: self.redirect_to_merchant_with_http_post,
+ merchant_name: self.merchant_name.map(|name| name.into()),
+ merchant_details: self.merchant_details.map(|details| details.into()),
+ webhook_details: self.webhook_details,
+ sub_merchants_enabled: self.sub_merchants_enabled,
+ parent_merchant_id: self.parent_merchant_id,
+ publishable_key: Some(self.publishable_key),
+ storage_scheme: self.storage_scheme,
+ locker_id: self.locker_id,
+ metadata: self.metadata,
+ routing_algorithm: self.routing_algorithm,
+ primary_business_details: self.primary_business_details,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ intent_fulfillment_time: self.intent_fulfillment_time,
+ frm_routing_algorithm: self.frm_routing_algorithm,
+ payout_routing_algorithm: self.payout_routing_algorithm,
+ organization_id: self.organization_id,
+ is_recon_enabled: self.is_recon_enabled,
+ default_profile: self.default_profile,
+ recon_status: self.recon_status,
+ payment_link_config: self.payment_link_config,
+ pm_collect_link_config: self.pm_collect_link_config,
+ })
+ }
+
+ async fn convert_back(
+ state: &keymanager::KeyManagerState,
+ item: Self::DstType,
+ key: &Secret<Vec<u8>>,
+ key_store_ref_id: String,
+ ) -> CustomResult<Self, ValidationError>
+ where
+ Self: Sized,
+ {
+ let publishable_key =
+ item.publishable_key
+ .ok_or(ValidationError::MissingRequiredField {
+ field_name: "publishable_key".to_string(),
+ })?;
+
+ let identifier = keymanager::Identifier::Merchant(key_store_ref_id.clone());
+
+ async {
+ Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
+ merchant_id: item.merchant_id,
+ return_url: item.return_url,
+ enable_payment_response_hash: item.enable_payment_response_hash,
+ payment_response_hash_key: item.payment_response_hash_key,
+ redirect_to_merchant_with_http_post: item.redirect_to_merchant_with_http_post,
+ merchant_name: item
+ .merchant_name
+ .async_lift(|inner| decrypt(state, inner, identifier.clone(), key.peek()))
+ .await?,
+ merchant_details: item
+ .merchant_details
+ .async_lift(|inner| decrypt(state, inner, identifier.clone(), key.peek()))
+ .await?,
+ webhook_details: item.webhook_details,
+ sub_merchants_enabled: item.sub_merchants_enabled,
+ parent_merchant_id: item.parent_merchant_id,
+ publishable_key,
+ storage_scheme: item.storage_scheme,
+ locker_id: item.locker_id,
+ metadata: item.metadata,
+ routing_algorithm: item.routing_algorithm,
+ frm_routing_algorithm: item.frm_routing_algorithm,
+ primary_business_details: item.primary_business_details,
+ created_at: item.created_at,
+ modified_at: item.modified_at,
+ intent_fulfillment_time: item.intent_fulfillment_time,
+ payout_routing_algorithm: item.payout_routing_algorithm,
+ organization_id: item.organization_id,
+ is_recon_enabled: item.is_recon_enabled,
+ default_profile: item.default_profile,
+ recon_status: item.recon_status,
+ payment_link_config: item.payment_link_config,
+ pm_collect_link_config: item.pm_collect_link_config,
+ })
+ }
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting merchant data".to_string(),
+ })
+ }
+
+ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
+ let now = date_time::now();
+ Ok(diesel_models::merchant_account::MerchantAccountNew {
+ merchant_id: self.merchant_id,
+ merchant_name: self.merchant_name.map(Encryption::from),
+ merchant_details: self.merchant_details.map(Encryption::from),
+ return_url: self.return_url,
+ webhook_details: self.webhook_details,
+ sub_merchants_enabled: self.sub_merchants_enabled,
+ parent_merchant_id: self.parent_merchant_id,
+ enable_payment_response_hash: Some(self.enable_payment_response_hash),
+ payment_response_hash_key: self.payment_response_hash_key,
+ redirect_to_merchant_with_http_post: Some(self.redirect_to_merchant_with_http_post),
+ publishable_key: Some(self.publishable_key),
+ locker_id: self.locker_id,
+ metadata: self.metadata,
+ routing_algorithm: self.routing_algorithm,
+ primary_business_details: self.primary_business_details,
+ created_at: now,
+ modified_at: now,
+ intent_fulfillment_time: self.intent_fulfillment_time,
+ frm_routing_algorithm: self.frm_routing_algorithm,
+ payout_routing_algorithm: self.payout_routing_algorithm,
+ organization_id: self.organization_id,
+ is_recon_enabled: self.is_recon_enabled,
+ default_profile: self.default_profile,
+ recon_status: self.recon_status,
+ payment_link_config: self.payment_link_config,
+ pm_collect_link_config: self.pm_collect_link_config,
+ })
+ }
+}
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
#[async_trait::async_trait]
impl super::behaviour::Conversion for MerchantAccount {
type DstType = diesel_models::merchant_account::MerchantAccount;
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 5f8dd3934a..fb37e4fac4 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -483,6 +483,193 @@ use diesel_models::{
PaymentIntent as DieselPaymentIntent, PaymentIntentNew as DieselPaymentIntentNew,
};
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+#[async_trait::async_trait]
+impl behaviour::Conversion for PaymentIntent {
+ type DstType = DieselPaymentIntent;
+ type NewDstType = DieselPaymentIntentNew;
+
+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
+ Ok(DieselPaymentIntent {
+ payment_id: self.payment_id,
+ merchant_id: self.merchant_id,
+ status: self.status,
+ amount: self.amount,
+ currency: self.currency,
+ amount_captured: self.amount_captured,
+ customer_id: self.customer_id,
+ description: self.description,
+ return_url: self.return_url,
+ metadata: self.metadata,
+ connector_id: self.connector_id,
+ shipping_address_id: self.shipping_address_id,
+ billing_address_id: self.billing_address_id,
+ statement_descriptor_name: self.statement_descriptor_name,
+ statement_descriptor_suffix: self.statement_descriptor_suffix,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ last_synced: self.last_synced,
+ setup_future_usage: self.setup_future_usage,
+ off_session: self.off_session,
+ client_secret: self.client_secret,
+ active_attempt_id: self.active_attempt.get_id(),
+ business_country: self.business_country,
+ business_label: self.business_label,
+ order_details: self.order_details,
+ allowed_payment_method_types: self.allowed_payment_method_types,
+ connector_metadata: self.connector_metadata,
+ feature_metadata: self.feature_metadata,
+ attempt_count: self.attempt_count,
+ profile_id: self.profile_id,
+ merchant_decision: self.merchant_decision,
+ payment_link_id: self.payment_link_id,
+ payment_confirm_source: self.payment_confirm_source,
+ updated_by: self.updated_by,
+ surcharge_applicable: self.surcharge_applicable,
+ request_incremental_authorization: self.request_incremental_authorization,
+ incremental_authorization_allowed: self.incremental_authorization_allowed,
+ authorization_count: self.authorization_count,
+ fingerprint_id: self.fingerprint_id,
+ session_expiry: self.session_expiry,
+ request_external_three_ds_authentication: self.request_external_three_ds_authentication,
+ charges: self.charges,
+ frm_metadata: self.frm_metadata,
+ customer_details: self.customer_details.map(Encryption::from),
+ billing_details: self.billing_details.map(Encryption::from),
+ merchant_order_reference_id: self.merchant_order_reference_id,
+ shipping_details: self.shipping_details.map(Encryption::from),
+ })
+ }
+
+ async fn convert_back(
+ storage_model: Self::DstType,
+ key: &masking::Secret<Vec<u8>>,
+ ) -> CustomResult<Self, ValidationError>
+ where
+ Self: Sized,
+ {
+ async {
+ let inner_decrypt = |inner| decrypt(inner, key.peek());
+ Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
+ payment_id: storage_model.payment_id,
+ merchant_id: storage_model.merchant_id,
+ status: storage_model.status,
+ amount: storage_model.amount,
+ currency: storage_model.currency,
+ amount_captured: storage_model.amount_captured,
+ customer_id: storage_model.customer_id,
+ description: storage_model.description,
+ return_url: storage_model.return_url,
+ metadata: storage_model.metadata,
+ connector_id: storage_model.connector_id,
+ shipping_address_id: storage_model.shipping_address_id,
+ billing_address_id: storage_model.billing_address_id,
+ statement_descriptor_name: storage_model.statement_descriptor_name,
+ statement_descriptor_suffix: storage_model.statement_descriptor_suffix,
+ created_at: storage_model.created_at,
+ modified_at: storage_model.modified_at,
+ last_synced: storage_model.last_synced,
+ setup_future_usage: storage_model.setup_future_usage,
+ off_session: storage_model.off_session,
+ client_secret: storage_model.client_secret,
+ active_attempt: RemoteStorageObject::ForeignID(storage_model.active_attempt_id),
+ business_country: storage_model.business_country,
+ business_label: storage_model.business_label,
+ order_details: storage_model.order_details,
+ allowed_payment_method_types: storage_model.allowed_payment_method_types,
+ connector_metadata: storage_model.connector_metadata,
+ feature_metadata: storage_model.feature_metadata,
+ attempt_count: storage_model.attempt_count,
+ profile_id: storage_model.profile_id,
+ merchant_decision: storage_model.merchant_decision,
+ payment_link_id: storage_model.payment_link_id,
+ payment_confirm_source: storage_model.payment_confirm_source,
+ updated_by: storage_model.updated_by,
+ surcharge_applicable: storage_model.surcharge_applicable,
+ request_incremental_authorization: storage_model.request_incremental_authorization,
+ incremental_authorization_allowed: storage_model.incremental_authorization_allowed,
+ authorization_count: storage_model.authorization_count,
+ fingerprint_id: storage_model.fingerprint_id,
+ session_expiry: storage_model.session_expiry,
+ request_external_three_ds_authentication: storage_model
+ .request_external_three_ds_authentication,
+ charges: storage_model.charges,
+ frm_metadata: storage_model.frm_metadata,
+ customer_details: storage_model
+ .customer_details
+ .async_lift(inner_decrypt)
+ .await?,
+ billing_details: storage_model
+ .billing_details
+ .async_lift(inner_decrypt)
+ .await?,
+ merchant_order_reference_id: storage_model.merchant_order_reference_id,
+ shipping_details: storage_model
+ .shipping_details
+ .async_lift(inner_decrypt)
+ .await?,
+ })
+ }
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting payment intent".to_string(),
+ })
+ }
+
+ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
+ Ok(DieselPaymentIntentNew {
+ payment_id: self.payment_id,
+ merchant_id: self.merchant_id,
+ status: self.status,
+ amount: self.amount,
+ currency: self.currency,
+ amount_captured: self.amount_captured,
+ customer_id: self.customer_id,
+ description: self.description,
+ return_url: self.return_url,
+ metadata: self.metadata,
+ connector_id: self.connector_id,
+ shipping_address_id: self.shipping_address_id,
+ billing_address_id: self.billing_address_id,
+ statement_descriptor_name: self.statement_descriptor_name,
+ statement_descriptor_suffix: self.statement_descriptor_suffix,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ last_synced: self.last_synced,
+ setup_future_usage: self.setup_future_usage,
+ off_session: self.off_session,
+ client_secret: self.client_secret,
+ active_attempt_id: self.active_attempt.get_id(),
+ business_country: self.business_country,
+ business_label: self.business_label,
+ order_details: self.order_details,
+ allowed_payment_method_types: self.allowed_payment_method_types,
+ connector_metadata: self.connector_metadata,
+ feature_metadata: self.feature_metadata,
+ attempt_count: self.attempt_count,
+ profile_id: self.profile_id,
+ merchant_decision: self.merchant_decision,
+ payment_link_id: self.payment_link_id,
+ payment_confirm_source: self.payment_confirm_source,
+ updated_by: self.updated_by,
+ surcharge_applicable: self.surcharge_applicable,
+ request_incremental_authorization: self.request_incremental_authorization,
+ incremental_authorization_allowed: self.incremental_authorization_allowed,
+ authorization_count: self.authorization_count,
+ fingerprint_id: self.fingerprint_id,
+ session_expiry: self.session_expiry,
+ request_external_three_ds_authentication: self.request_external_three_ds_authentication,
+ charges: self.charges,
+ frm_metadata: self.frm_metadata,
+ customer_details: self.customer_details.map(Encryption::from),
+ billing_details: self.billing_details.map(Encryption::from),
+ merchant_order_reference_id: self.merchant_order_reference_id,
+ shipping_details: self.shipping_details.map(Encryption::from),
+ })
+ }
+}
+
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
#[async_trait::async_trait]
impl behaviour::Conversion for PaymentIntent {
type DstType = DieselPaymentIntent;
diff --git a/crates/hyperswitch_interfaces/Cargo.toml b/crates/hyperswitch_interfaces/Cargo.toml
index db61a05436..05d5987aba 100644
--- a/crates/hyperswitch_interfaces/Cargo.toml
+++ b/crates/hyperswitch_interfaces/Cargo.toml
@@ -27,10 +27,10 @@ thiserror = "1.0.58"
time = "0.3.35"
# First party crates
+masking = { version = "0.1.0", path = "../masking" }
api_models = { version = "0.1.0", path = "../api_models" }
+hyperswitch_domain_models = { version = "0.1.0", path = "../hyperswitch_domain_models", default-features = false, features = ["v1"] }
common_enums = { version = "0.1.0", path = "../common_enums" }
common_utils = { version = "0.1.0", path = "../common_utils" }
-hyperswitch_domain_models = { version = "0.1.0", path = "../hyperswitch_domain_models", default-features = false }
-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" }
diff --git a/crates/openapi/Cargo.toml b/crates/openapi/Cargo.toml
index e3e3bcc4a8..d75714fd2e 100644
--- a/crates/openapi/Cargo.toml
+++ b/crates/openapi/Cargo.toml
@@ -16,5 +16,6 @@ common_utils = { version = "0.1.0", path = "../common_utils" }
router_env = { version = "0.1.0", path = "../router_env" }
[features]
+default = ["v1"]
v2 = ["api_models/v2"]
-default = []
+v1 = ["api_models/v1"]
diff --git a/crates/openapi/src/main.rs b/crates/openapi/src/main.rs
index f957e0cdd9..3d69a6495c 100644
--- a/crates/openapi/src/main.rs
+++ b/crates/openapi/src/main.rs
@@ -2,12 +2,8 @@ mod openapi;
mod routes;
fn main() {
- #[cfg(not(feature = "v2"))]
let relative_file_path = "api-reference/openapi_spec.json";
- #[cfg(feature = "v2")]
- let relative_file_path = "api-reference/v2/openapi_spec.json";
-
let mut file_path = router_env::workspace_path();
file_path.push(relative_file_path);
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index b9488a0804..743a94c942 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -9,16 +9,16 @@ readme = "README.md"
license.workspace = true
[features]
-default = ["kv_store", "stripe", "oltp", "olap", "accounts_cache", "dummy_connector", "payouts", "payout_retry", "retry", "frm", "tls"]
+default = ["kv_store", "stripe", "oltp", "olap", "accounts_cache", "dummy_connector", "payouts", "payout_retry", "retry", "frm", "tls", "v1"]
+olap = ["hyperswitch_domain_models/olap", "storage_impl/olap", "scheduler/olap", "api_models/olap", "dep:analytics"]
tls = ["actix-web/rustls-0_22"]
-keymanager_mtls = ["reqwest/rustls-tls","common_utils/keymanager_mtls"]
+keymanager_mtls = ["reqwest/rustls-tls", "common_utils/keymanager_mtls"]
encryption_service = ["hyperswitch_domain_models/encryption_service", "common_utils/encryption_service"]
email = ["external_services/email", "scheduler/email", "olap"]
keymanager_create = []
frm = ["api_models/frm", "hyperswitch_domain_models/frm"]
stripe = ["dep:serde_qs"]
release = ["stripe", "email", "accounts_cache", "kv_store", "vergen", "recon", "external_services/aws_kms", "external_services/aws_s3", "keymanager_mtls", "keymanager_create", "encryption_service"]
-olap = ["hyperswitch_domain_models/olap", "storage_impl/olap", "scheduler/olap", "api_models/olap", "dep:analytics"]
oltp = ["storage_impl/oltp"]
kv_store = ["scheduler/kv_store"]
accounts_cache = []
@@ -30,7 +30,10 @@ payouts = ["api_models/payouts", "common_enums/payouts", "hyperswitch_domain_mod
payout_retry = ["payouts"]
recon = ["email", "api_models/recon"]
retry = []
-v2 = ["api_models/v2"]
+v2 = ["api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2"]
+v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1"]
+merchant_account_v2 = ["api_models/merchant_account_v2", "diesel_models/merchant_account_v2", "hyperswitch_domain_models/merchant_account_v2"]
+payment_v2 = ["api_models/payment_v2", "diesel_models/payment_v2", "hyperswitch_domain_models/payment_v2"]
[dependencies]
actix-cors = "0.6.5"
@@ -72,7 +75,7 @@ mime = "0.3.17"
nanoid = "0.4.0"
num_cpus = "1.16.0"
once_cell = "1.19.0"
-openidconnect = "3.5.0" # TODO: remove reqwest
+openidconnect = "3.5.0" # TODO: remove reqwest
openssl = "0.10.64"
qrcode = "0.14.0"
quick-xml = { version = "0.31.0", features = ["serialize"] }
@@ -111,6 +114,7 @@ validator = "0.17.0"
x509-parser = "0.16.0"
# First party crates
+
analytics = { version = "0.1.0", path = "../analytics", optional = true }
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
cards = { version = "0.1.0", path = "../cards" }
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index bfefe89397..59c7c29cc6 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -190,7 +190,11 @@ trait MerchantAccountCreateBridge {
) -> RouterResult<domain::MerchantAccount>;
}
-#[cfg(all(not(feature = "v2"), feature = "olap"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ feature = "olap",
+ not(feature = "merchant_account_v2")
+))]
#[async_trait::async_trait]
impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
async fn create_domain_model_from_request(
@@ -260,6 +264,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
let mut merchant_account = async {
Ok::<_, error_stack::Report<common_utils::errors::CryptoError>>(
domain::MerchantAccount {
+ id: None,
merchant_id: self.merchant_id.get_string_repr().to_owned(),
merchant_name: self
.merchant_name
@@ -308,7 +313,6 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
payout_routing_algorithm: self.payout_routing_algorithm,
#[cfg(not(feature = "payouts"))]
payout_routing_algorithm: None,
- id: None,
organization_id,
is_recon_enabled: false,
default_profile: None,
@@ -332,7 +336,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
#[cfg(feature = "olap")]
enum CreateOrValidateOrganization {
/// Creates a new organization
- #[cfg(not(feature = "v2"))]
+ #[cfg(any(feature = "v1", feature = "v2"))]
Create,
/// Validates if this organization exists in the records
Validate { organization_id: String },
@@ -340,7 +344,11 @@ enum CreateOrValidateOrganization {
#[cfg(feature = "olap")]
impl CreateOrValidateOrganization {
- #[cfg(all(not(feature = "v2"), feature = "olap"))]
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2"),
+ feature = "olap"
+ ))]
/// Create an action to either create or validate the given organization_id
/// If organization_id is passed, then validate if this organization exists
/// If not passed, create a new organization
@@ -352,7 +360,7 @@ impl CreateOrValidateOrganization {
}
}
- #[cfg(all(feature = "v2", feature = "olap"))]
+ #[cfg(all(feature = "v2", feature = "merchant_account_v2", feature = "olap"))]
/// Create an action to validate the provided organization_id
fn new(organization_id: String) -> Self {
Self::Validate { organization_id }
@@ -362,7 +370,7 @@ impl CreateOrValidateOrganization {
/// Apply the action, whether to create the organization or validate the given organization_id
async fn create_or_validate(&self, db: &dyn StorageInterface) -> RouterResult<String> {
Ok(match self {
- #[cfg(not(feature = "v2"))]
+ #[cfg(any(feature = "v1", feature = "v2"))]
Self::Create => {
let new_organization = api_models::organization::OrganizationNew::new(None);
let db_organization = ForeignFrom::foreign_from(new_organization);
@@ -385,7 +393,11 @@ impl CreateOrValidateOrganization {
}
}
-#[cfg(all(not(feature = "v2"), feature = "olap"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ feature = "olap",
+ not(feature = "merchant_account_v2")
+))]
enum CreateBusinessProfile {
/// Create business profiles from primary business details
/// If there is only one business profile created, then set this profile as default
@@ -396,7 +408,11 @@ enum CreateBusinessProfile {
CreateDefaultBusinessProfile,
}
-#[cfg(all(not(feature = "v2"), feature = "olap"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ feature = "olap",
+ not(feature = "merchant_account_v2")
+))]
impl CreateBusinessProfile {
/// Create a new business profile action from the given information
/// If primary business details exist, then create business profiles from them
@@ -510,7 +526,7 @@ impl CreateBusinessProfile {
}
}
-#[cfg(all(feature = "v2", feature = "olap"))]
+#[cfg(all(feature = "v2", feature = "merchant_account_v2", feature = "olap"))]
#[async_trait::async_trait]
impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
async fn create_domain_model_from_request(
@@ -596,7 +612,6 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
intent_fulfillment_time: None,
frm_routing_algorithm: None,
payout_routing_algorithm: None,
- id: None,
organization_id: self.organization_id,
is_recon_enabled: false,
default_profile: None,
@@ -664,6 +679,7 @@ pub async fn get_merchant_account(
))
}
+#[cfg(any(feature = "v1", feature = "v2"))]
/// For backwards compatibility, whenever new business labels are passed in
/// primary_business_details, create a business profile
pub async fn create_business_profile_from_business_labels(
@@ -864,6 +880,7 @@ pub async fn merchant_account_update(
})
.transpose()?;
+ #[cfg(any(feature = "v1", feature = "v2"))]
// In order to support backwards compatibility, if a business_labels are passed in the update
// call, then create new business_profiles with the profile_name as business_label
req.primary_business_details
@@ -1939,6 +1956,7 @@ pub fn get_frm_config_as_secret(
}
}
+#[cfg(any(feature = "v1", feature = "v2"))]
pub async fn create_and_insert_business_profile(
state: &SessionState,
request: api::BusinessProfileCreate,
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 431826fbdb..9dcc6b16ff 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -3194,7 +3194,9 @@ pub async fn list_payment_methods(
.and_then(|bp| bp.collect_billing_details_from_wallet_connector);
Ok(services::ApplicationResponse::Json(
api::PaymentMethodListResponse {
- redirect_url: merchant_account.return_url,
+ redirect_url: business_profile
+ .as_ref()
+ .and_then(|business_profile| business_profile.return_url.clone()),
merchant_name: merchant_account.merchant_name,
payment_type,
payment_methods: payment_method_responses,
diff --git a/crates/router/src/db/merchant_account.rs b/crates/router/src/db/merchant_account.rs
index eadf00c872..ae5ca36017 100644
--- a/crates/router/src/db/merchant_account.rs
+++ b/crates/router/src/db/merchant_account.rs
@@ -449,13 +449,10 @@ impl MerchantAccountInterface for MockDb {
async fn insert_merchant(
&self,
state: &KeyManagerState,
- mut merchant_account: domain::MerchantAccount,
+ merchant_account: domain::MerchantAccount,
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let mut accounts = self.merchant_accounts.lock().await;
- merchant_account.id.get_or_insert(
- i32::try_from(accounts.len()).change_context(errors::StorageError::MockDbError)?,
- );
let account = Conversion::convert(merchant_account)
.await
.change_context(errors::StorageError::EncryptionError)?;
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index b733e76289..f6380d3f9c 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -1000,7 +1000,7 @@ impl Blocklist {
pub struct MerchantAccount;
-#[cfg(all(feature = "v2", feature = "olap"))]
+#[cfg(all(feature = "v2", feature = "olap", feature = "merchant_account_v2"))]
impl MerchantAccount {
pub fn server(state: AppState) -> Scope {
web::scope("/v2/accounts")
@@ -1009,7 +1009,11 @@ impl MerchantAccount {
}
}
-#[cfg(all(feature = "olap", not(feature = "v2")))]
+#[cfg(all(
+ feature = "olap",
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
impl MerchantAccount {
pub fn server(state: AppState) -> Scope {
web::scope("/accounts")
diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs
index 054888d1df..89166c3c94 100644
--- a/crates/router/src/types/api/admin.rs
+++ b/crates/router/src/types/api/admin.rs
@@ -22,7 +22,10 @@ use crate::{
types::{domain, storage, transformers::ForeignTryFrom},
};
-#[cfg(not(feature = "v2"))]
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+))]
impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {
type Error = error_stack::Report<errors::ParsingError>;
fn foreign_try_from(item: domain::MerchantAccount) -> Result<Self, Self::Error> {
@@ -63,7 +66,7 @@ impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {
}
}
-#[cfg(feature = "v2")]
+#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {
type Error = error_stack::Report<errors::ValidationError>;
fn foreign_try_from(item: domain::MerchantAccount) -> Result<Self, Self::Error> {
@@ -153,6 +156,7 @@ pub async fn business_profile_response(
})
}
+#[cfg(any(feature = "v1", feature = "v2"))]
pub async fn create_business_profile(
state: &SessionState,
merchant_account: domain::MerchantAccount,
diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rs
index ec44103a8f..93014de4b4 100644
--- a/crates/router/src/types/domain/user.rs
+++ b/crates/router/src/types/domain/user.rs
@@ -4,7 +4,7 @@ use api_models::{
admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api,
};
use common_enums::TokenPurpose;
-#[cfg(not(feature = "v2"))]
+#[cfg(any(feature = "v1", feature = "v2"))]
use common_utils::id_type;
#[cfg(feature = "keymanager_create")]
use common_utils::types::keymanager::EncryptionCreateRequest;
@@ -387,7 +387,7 @@ impl NewUserMerchant {
Ok(())
}
- #[cfg(feature = "v2")]
+ #[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
fn create_merchant_account_request(&self) -> UserResult<admin_api::MerchantAccountCreate> {
let merchant_name = if let Some(company_name) = self.company_name.clone() {
MerchantName::try_from(company_name)
@@ -406,7 +406,10 @@ impl NewUserMerchant {
})
}
- #[cfg(not(feature = "v2"))]
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_account_v2")
+ ))]
fn create_merchant_account_request(&self) -> UserResult<admin_api::MerchantAccountCreate> {
Ok(admin_api::MerchantAccountCreate {
merchant_id: id_type::MerchantId::from(self.get_merchant_id().into())
diff --git a/crates/scheduler/Cargo.toml b/crates/scheduler/Cargo.toml
index 14a0c8884e..25a297a8bc 100644
--- a/crates/scheduler/Cargo.toml
+++ b/crates/scheduler/Cargo.toml
@@ -6,10 +6,11 @@ rust-version.workspace = true
license.workspace = true
[features]
-default = ["kv_store", "olap"]
+default = ["kv_store", "olap", "v1"]
olap = ["storage_impl/olap", "hyperswitch_domain_models/olap"]
kv_store = []
email = ["external_services/email"]
+v1 = ["diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1"]
[dependencies]
# Third party crates
diff --git a/crates/storage_impl/Cargo.toml b/crates/storage_impl/Cargo.toml
index 54374643f4..d42f64931f 100644
--- a/crates/storage_impl/Cargo.toml
+++ b/crates/storage_impl/Cargo.toml
@@ -8,10 +8,13 @@ readme = "README.md"
license.workspace = true
[features]
-default = ["olap", "oltp"]
+default = ["olap", "oltp", "v1"]
oltp = []
olap = ["hyperswitch_domain_models/olap"]
payouts = ["hyperswitch_domain_models/payouts"]
+v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1"]
+v2 = ["api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2"]
+payment_v2 = ["hyperswitch_domain_models/payment_v2", "diesel_models/payment_v2"]
[dependencies]
# First Party dependencies
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index 1524f99477..b536ba4552 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -1135,6 +1135,148 @@ impl DataModelExt for MandateDataType {
}
}
+#[cfg(all(feature = "v2", feature = "payment_v2"))]
+impl DataModelExt for PaymentAttempt {
+ type StorageModel = DieselPaymentAttempt;
+
+ fn to_storage_model(self) -> Self::StorageModel {
+ DieselPaymentAttempt {
+ payment_id: self.payment_id,
+ merchant_id: self.merchant_id,
+ attempt_id: self.attempt_id,
+ status: self.status,
+ amount: self.amount.get_amount_as_i64(),
+ net_amount: Some(self.net_amount.get_amount_as_i64()),
+ currency: self.currency,
+ save_to_locker: self.save_to_locker,
+ connector: self.connector,
+ error_message: self.error_message,
+ offer_amount: self
+ .offer_amount
+ .map(|offer_amt| offer_amt.get_amount_as_i64()),
+ surcharge_amount: self
+ .surcharge_amount
+ .map(|surcharge_amt| surcharge_amt.get_amount_as_i64()),
+ tax_amount: self.tax_amount.map(|tax_amt| tax_amt.get_amount_as_i64()),
+ payment_method_id: self.payment_method_id,
+ payment_method: self.payment_method,
+ connector_transaction_id: self.connector_transaction_id,
+ capture_method: self.capture_method,
+ capture_on: self.capture_on,
+ confirm: self.confirm,
+ authentication_type: self.authentication_type,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ last_synced: self.last_synced,
+ cancellation_reason: self.cancellation_reason,
+ amount_to_capture: self
+ .amount_to_capture
+ .map(|capture_amt| capture_amt.get_amount_as_i64()),
+ mandate_id: self.mandate_id,
+ browser_info: self.browser_info,
+ error_code: self.error_code,
+ payment_token: self.payment_token,
+ connector_metadata: self.connector_metadata,
+ payment_experience: self.payment_experience,
+ payment_method_type: self.payment_method_type,
+ payment_method_data: self.payment_method_data,
+ business_sub_label: self.business_sub_label,
+ straight_through_algorithm: self.straight_through_algorithm,
+ preprocessing_step_id: self.preprocessing_step_id,
+ mandate_details: self.mandate_details.map(|d| d.to_storage_model()),
+ error_reason: self.error_reason,
+ multiple_capture_count: self.multiple_capture_count,
+ connector_response_reference_id: self.connector_response_reference_id,
+ amount_capturable: self.amount_capturable.get_amount_as_i64(),
+ updated_by: self.updated_by,
+ authentication_data: self.authentication_data,
+ encoded_data: self.encoded_data,
+ merchant_connector_id: self.merchant_connector_id,
+ unified_code: self.unified_code,
+ unified_message: self.unified_message,
+ external_three_ds_authentication_attempted: self
+ .external_three_ds_authentication_attempted,
+ authentication_connector: self.authentication_connector,
+ authentication_id: self.authentication_id,
+ mandate_data: self.mandate_data.map(|d| d.to_storage_model()),
+ payment_method_billing_address_id: self.payment_method_billing_address_id,
+ fingerprint_id: self.fingerprint_id,
+ charge_id: self.charge_id,
+ client_source: self.client_source,
+ client_version: self.client_version,
+ customer_acceptance: self.customer_acceptance,
+ }
+ }
+
+ fn from_storage_model(storage_model: Self::StorageModel) -> Self {
+ Self {
+ net_amount: MinorUnit::new(storage_model.get_or_calculate_net_amount()),
+ payment_id: storage_model.payment_id,
+ merchant_id: storage_model.merchant_id,
+ attempt_id: storage_model.attempt_id,
+ status: storage_model.status,
+ amount: MinorUnit::new(storage_model.amount),
+ currency: storage_model.currency,
+ save_to_locker: storage_model.save_to_locker,
+ connector: storage_model.connector,
+ error_message: storage_model.error_message,
+ offer_amount: storage_model.offer_amount.map(MinorUnit::new),
+ surcharge_amount: storage_model.surcharge_amount.map(MinorUnit::new),
+ tax_amount: storage_model.tax_amount.map(MinorUnit::new),
+ payment_method_id: storage_model.payment_method_id,
+ payment_method: storage_model.payment_method,
+ connector_transaction_id: storage_model.connector_transaction_id,
+ capture_method: storage_model.capture_method,
+ capture_on: storage_model.capture_on,
+ confirm: storage_model.confirm,
+ authentication_type: storage_model.authentication_type,
+ created_at: storage_model.created_at,
+ modified_at: storage_model.modified_at,
+ last_synced: storage_model.last_synced,
+ cancellation_reason: storage_model.cancellation_reason,
+ amount_to_capture: storage_model.amount_to_capture.map(MinorUnit::new),
+ mandate_id: storage_model.mandate_id,
+ browser_info: storage_model.browser_info,
+ error_code: storage_model.error_code,
+ payment_token: storage_model.payment_token,
+ connector_metadata: storage_model.connector_metadata,
+ payment_experience: storage_model.payment_experience,
+ payment_method_type: storage_model.payment_method_type,
+ payment_method_data: storage_model.payment_method_data,
+ business_sub_label: storage_model.business_sub_label,
+ straight_through_algorithm: storage_model.straight_through_algorithm,
+ preprocessing_step_id: storage_model.preprocessing_step_id,
+ mandate_details: storage_model
+ .mandate_details
+ .map(MandateDataType::from_storage_model),
+ error_reason: storage_model.error_reason,
+ multiple_capture_count: storage_model.multiple_capture_count,
+ connector_response_reference_id: storage_model.connector_response_reference_id,
+ amount_capturable: MinorUnit::new(storage_model.amount_capturable),
+ updated_by: storage_model.updated_by,
+ authentication_data: storage_model.authentication_data,
+ encoded_data: storage_model.encoded_data,
+ merchant_connector_id: storage_model.merchant_connector_id,
+ unified_code: storage_model.unified_code,
+ unified_message: storage_model.unified_message,
+ external_three_ds_authentication_attempted: storage_model
+ .external_three_ds_authentication_attempted,
+ authentication_connector: storage_model.authentication_connector,
+ authentication_id: storage_model.authentication_id,
+ mandate_data: storage_model
+ .mandate_data
+ .map(MandateDetails::from_storage_model),
+ payment_method_billing_address_id: storage_model.payment_method_billing_address_id,
+ fingerprint_id: storage_model.fingerprint_id,
+ charge_id: storage_model.charge_id,
+ client_source: storage_model.client_source,
+ client_version: storage_model.client_version,
+ customer_acceptance: storage_model.customer_acceptance,
+ }
+ }
+}
+
+#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
impl DataModelExt for PaymentAttempt {
type StorageModel = DieselPaymentAttempt;
diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs
index ced94b5717..a982d0ffdc 100644
--- a/crates/storage_impl/src/payments/payment_intent.rs
+++ b/crates/storage_impl/src/payments/payment_intent.rs
@@ -10,6 +10,22 @@ use common_utils::{
};
#[cfg(feature = "olap")]
use diesel::{associations::HasTable, ExpressionMethods, JoinOnDsl, QueryDsl};
+#[cfg(feature = "olap")]
+use diesel_models::query::generics::db_metrics;
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "payment_v2"),
+ feature = "olap"
+))]
+use diesel_models::schema::{
+ payment_attempt::{self as payment_attempt_schema, dsl as pa_dsl},
+ payment_intent::dsl as pi_dsl,
+};
+#[cfg(all(feature = "v2", feature = "payment_v2", feature = "olap"))]
+use diesel_models::schema_v2::{
+ payment_attempt::{self as payment_attempt_schema, dsl as pa_dsl},
+ payment_intent::dsl as pi_dsl,
+};
use diesel_models::{
enums::MerchantStorageScheme,
kv,
@@ -18,11 +34,6 @@ use diesel_models::{
PaymentIntent as DieselPaymentIntent, PaymentIntentUpdate as DieselPaymentIntentUpdate,
},
};
-#[cfg(feature = "olap")]
-use diesel_models::{
- query::generics::db_metrics,
- schema::{payment_attempt::dsl as pa_dsl, payment_intent::dsl as pi_dsl},
-};
use error_stack::ResultExt;
#[cfg(feature = "olap")]
use hyperswitch_domain_models::payments::payment_intent::PaymentIntentFetchConstraints;
@@ -660,8 +671,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
let conn = async_bb8_diesel::Connection::as_async_conn(&conn);
let mut query = DieselPaymentIntent::table()
.inner_join(
- diesel_models::schema::payment_attempt::table
- .on(pa_dsl::attempt_id.eq(pi_dsl::active_attempt_id)),
+ payment_attempt_schema::table.on(pa_dsl::attempt_id.eq(pi_dsl::active_attempt_id)),
)
.filter(pi_dsl::merchant_id.eq(merchant_id.to_owned()))
.order(pi_dsl::created_at.desc())
diff --git a/justfile b/justfile
index 40d4820495..b5f282dc9a 100644
--- a/justfile
+++ b/justfile
@@ -8,7 +8,7 @@ fmt_flags := '--all'
fmt *FLAGS:
cargo +nightly fmt {{ fmt_flags }} {{ FLAGS }}
-check_flags := '--all-features --all-targets'
+check_flags := '--all-targets'
# Check compilation of Rust code
check *FLAGS:
@@ -17,8 +17,55 @@ check *FLAGS:
alias c := check
# Check compilation of Rust code and catch common mistakes
+# We cannot run --all-features because v1 and v2 are mutually exclusive features
+# Create a list of features by excluding certain features
clippy *FLAGS:
- cargo clippy {{ check_flags }} {{ FLAGS }}
+ #! /usr/bin/env bash
+ set -euo pipefail
+
+ FEATURES="$(cargo metadata --all-features --format-version 1 | \
+ jq -r '
+ [ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array
+ | .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates
+ | del( .[] | select( any( . ; . == ("v2", "merchant_account_v2", "payment_v2") ) ) ) # Exclude some features from features list
+ | join(",") # Construct a comma-separated string of features for passing to `cargo`
+ ')"
+
+ set -x
+ cargo clippy {{ check_flags }} --features "${FEATURES}" {{ FLAGS }}
+ set +x
+
+clippy_v2 *FLAGS:
+ #! /usr/bin/env bash
+ set -euo pipefail
+
+ FEATURES="$(cargo metadata --all-features --format-version 1 | \
+ jq -r '
+ [ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array
+ | .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates
+ | del( .[] | select( any( . ; . == ("v1") ) ) ) # Exclude some features from features list
+ | join(",") # Construct a comma-separated string of features for passing to `cargo`
+ ')"
+
+ set -x
+ cargo clippy {{ check_flags }} --features "${FEATURES}" {{ FLAGS }}
+ set +x
+
+check_v2 *FLAGS:
+ #! /usr/bin/env bash
+ set -euo pipefail
+
+ FEATURES="$(cargo metadata --all-features --format-version 1 | \
+ jq -r '
+ [ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array
+ | .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates
+ | del( .[] | select( any( . ; . == ("v1", "merchant_account_v2", "payment_v2") ) ) ) # Exclude some features from features list
+ | join(",") # Construct a comma-separated string of features for passing to `cargo`
+ ')"
+
+ set -x
+ cargo clippy {{ check_flags }} --features "${FEATURES}" {{ FLAGS }}
+ set +x
alias cl := clippy
@@ -40,7 +87,7 @@ run *FLAGS:
alias r := run
-doc_flags := '--all-features --all-targets'
+doc_flags := '--all-features --all-targets --exclude-features "v2 merchant_account_v2 payment_v2"'
# Generate documentation
doc *FLAGS:
@@ -60,11 +107,11 @@ euclid-wasm features='dummy_connector':
# Run pre-commit checks
precommit: fmt clippy
-hack_flags := '--workspace --each-feature --all-targets'
-
-# Check compilation of each cargo feature
-hack:
- cargo hack check {{ hack_flags }}
+# Check compilation of v2 feature on base dependencies
+v2_intermediate_features := "merchant_account_v2,payment_v2"
+hack_v2:
+ cargo hack check --feature-powerset --ignore-unknown-features --at-least-one-of "v2 " --include-features "v2" --include-features {{ v2_intermediate_features }} --package "hyperswitch_domain_models" --package "diesel_models" --package "api_models"
+ cargo hack check --features "v2,payment_v2" -p storage_impl
# Use the env variables if present, or fallback to default values
@@ -124,3 +171,8 @@ migrate_v2 operation=default_operation *args='':
resurrect:
psql -U postgres -c 'DROP DATABASE IF EXISTS hyperswitch_db';
psql -U postgres -c 'CREATE DATABASE hyperswitch_db';
+
+ci_hack:
+ scripts/ci-checks.sh
+
+
diff --git a/scripts/ci-checks.sh b/scripts/ci-checks.sh
new file mode 100755
index 0000000000..7f2cecf840
--- /dev/null
+++ b/scripts/ci-checks.sh
@@ -0,0 +1,110 @@
+#! /usr/bin/env bash
+set -euo pipefail
+
+# The below script is run on the github actions CI
+# Obtain a list of workspace members
+workspace_members="$(
+ cargo metadata --format-version 1 --no-deps \
+ | jq \
+ --compact-output \
+ --monochrome-output \
+ --raw-output \
+ '(.workspace_members | sort) as $package_ids | .packages[] | select(IN(.id; $package_ids[])) | .name'
+)"
+
+PACKAGES_CHECKED=()
+PACKAGES_SKIPPED=()
+
+# If we are running this on a pull request, then only check for packages that are modified
+if [[ -n "${GITHUB_BASE_REF:-}" ]]; then
+ while IFS= read -r package_name; do
+ # Obtain comma-separated list of transitive workspace dependencies for each workspace member
+ change_paths="$(cargo tree --all-features --no-dedupe --prefix none --package "${package_name}" \
+ | grep 'crates/' \
+ | sort --unique \
+ | awk --field-separator ' ' '{ printf "crates/%s\n", $1 }' | paste -d ',' -s -)"
+
+ # Store change paths in an array by splitting `change_paths` by comma
+ IFS=',' read -ra change_paths <<< "${change_paths}"
+
+ # A package must be checked if any of its transitive dependencies (or itself) has been modified
+ if git diff --exit-code --quiet "origin/${GITHUB_BASE_REF}" -- "${change_paths[@]}"; then
+ printf '::debug::Skipping `%s` since none of these paths were modified: %s\n' "${package_name}" "${change_paths[*]}"
+ PACKAGES_SKIPPED+=("${package_name}")
+ else
+ printf '::debug::Checking `%s` since at least one of these paths was modified: %s\n' "${package_name}" "${change_paths[*]}"
+ PACKAGES_CHECKED+=("${package_name}")
+ fi
+ done <<< "${workspace_members}"
+ printf '::notice::Packages checked: %s; Packages skipped: %s\n' "${PACKAGES_CHECKED[*]}" "${PACKAGES_SKIPPED[*]}"
+
+ packages_checked=$(printf '%s\n' "${PACKAGES_CHECKED[@]}" | jq -R . | jq -s .)
+
+ crates_with_features="$(cargo metadata --format-version 1 --no-deps \
+ | jq \
+ --compact-output \
+ --monochrome-output \
+ --raw-output \
+ --argjson packages_checked "${packages_checked}" \
+ '[ ( .workspace_members | sort ) as $package_ids | .packages[] | select( IN( .name; $packages_checked[] ) ) | { name: .name, features: ( .features | keys ) } ]')"
+else
+ # If we are doing this locally or on merge queue, then check for all the crates
+ crates_with_features="$(cargo metadata --format-version 1 --no-deps \
+ | jq \
+ --compact-output \
+ --monochrome-output \
+ --raw-output \
+ '[ ( .workspace_members | sort ) as $package_ids | .packages[] | select( IN( .id; $package_ids[] ) ) | { name: .name, features: ( .features | keys ) } ]')"
+fi
+
+# List of cargo commands that will be executed
+all_commands=()
+
+# Process the metadata to generate the cargo check commands for crates which have v1 features
+# We need to always have the v1 feature with each feature
+# This is because, no crate should be run without any features
+crates_with_v1_feature="$(
+ jq --monochrome-output --raw-output \
+ --argjson crates_with_features "${crates_with_features}" \
+ --null-input \
+ '$crates_with_features[]
+ | select( IN("v1"; .features[])) # Select crates with `v1` feature
+ | { name, features: (.features - ["v1", "v2", "default", "payment_v2", "merchant_account_v2"]) } # Remove specific features to generate feature combinations
+ | { name, features: ( .features | map([., "v1"] | join(",")) ) } # Add `v1` to remaining features and join them by comma
+ | .name as $name | .features[] | { $name, features: . } # Expand nested features object to have package - features combinations
+ | "\(.name) \(.features)" # Print out package name and features separated by space'
+)"
+while IFS=' ' read -r crate features; do
+ command="cargo check --all-targets --package \"${crate}\" --no-default-features --features \"${features}\""
+ all_commands+=("$command")
+done <<< "${crates_with_v1_feature}"
+
+# For crates which do not have v1 feature, we can run the usual cargo hack command
+crates_without_v1_feature="$(
+ jq --monochrome-output --raw-output \
+ --argjson crates_with_features "${crates_with_features}" \
+ --null-input \
+ '$crates_with_features[] | select(IN("v1"; .features[]) | not ) # Select crates without `v1` feature
+ | "\(.name)" # Print out package name'
+)"
+while IFS= read -r crate; do
+ command="cargo hack check --all-targets --each-feature --package \"${crate}\""
+ all_commands+=("$command")
+done <<< "${crates_without_v1_feature}"
+
+echo "The list of commands that will be executed:"
+printf "%s\n" "${all_commands[@]}"
+echo
+
+# Execute the commands
+for command in "${all_commands[@]}"; do
+ if [[ "${CI:-false}" == "true" && "${GITHUB_ACTIONS:-false}" == "true" ]]; then
+ printf '::group::Running `%s`\n' "${command}"
+ fi
+
+ bash -c -x "${command}"
+
+ if [[ "${CI:-false}" == "true" && "${GITHUB_ACTIONS:-false}" == "true" ]]; then
+ echo '::endgroup::'
+ fi
+done
diff --git a/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/down.sql b/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/down.sql
new file mode 100644
index 0000000000..c222562b9a
--- /dev/null
+++ b/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE merchant_account
+ADD COLUMN IF NOT EXISTS id SERIAL;
diff --git a/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/up.sql b/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/up.sql
new file mode 100644
index 0000000000..556c6721d4
--- /dev/null
+++ b/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/up.sql
@@ -0,0 +1,3 @@
+-- Your SQL goes here
+-- Drop the id column as this will be used later as the primary key with a different type
+ALTER TABLE merchant_account DROP COLUMN IF EXISTS id;