Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(core): Move RouterData to crate hyperswitch_domain_models #4524

Merged
merged 24 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
eb0bca7
feat(core): Move RouterData to crate hyperswitch_domain_models
deepanshu-iiitu May 2, 2024
27ce1d5
chore: Resolve Errors Part 1
deepanshu-iiitu May 10, 2024
36e842b
chore: Resolve errors
deepanshu-iiitu May 14, 2024
dbf34c0
Merge branch 'main' into move_routerdata
deepanshu-iiitu May 14, 2024
5e5e133
chore: Resolve errors
deepanshu-iiitu May 14, 2024
f7b0ab3
chore: Resolve errors
deepanshu-iiitu May 14, 2024
4c2429f
chore: run formatter
hyperswitch-bot[bot] May 14, 2024
27f6957
chore: Reolve errors
deepanshu-iiitu May 14, 2024
d31958b
chore: Resolve clippy errors
deepanshu-iiitu May 14, 2024
4ac833a
chore: Resolve clippy errors 2
deepanshu-iiitu May 14, 2024
32cb373
chore:[CONNECTOR] Fix template code generation
deepanshu-iiitu May 14, 2024
ef33878
chore: Discard changes in connector tests
deepanshu-iiitu May 14, 2024
dfb501d
chore: Discard Extra Changes
deepanshu-iiitu May 14, 2024
95db74c
chore: Reuse old code
deepanshu-iiitu May 14, 2024
16fe722
chore: Fix compile time errors
deepanshu-iiitu May 14, 2024
b2dcac2
Merge branch 'main' into move_routerdata
deepanshu-iiitu May 14, 2024
5c134c5
chore: Fix warnings
deepanshu-iiitu May 14, 2024
d826b1b
chore: Resolve PR Comments
deepanshu-iiitu May 14, 2024
f18d818
chore: Resolve Clippy errors from PR Comments
deepanshu-iiitu May 14, 2024
152d3a6
Merge branch 'main' into move_routerdata
deepanshu-iiitu May 14, 2024
f5104ca
chore: Fix compilation errors
deepanshu-iiitu May 14, 2024
5a5faf9
chore: Resolve PR Comments 2
deepanshu-iiitu May 14, 2024
bcdf887
chore: Resolve Cargo Check Warnings
deepanshu-iiitu May 14, 2024
c85492a
chore: Resolve Cargo Check Warnings 2
deepanshu-iiitu May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion connector-template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use masking::ExposeInterface;
use crate::{
events::connector_api_logs::ConnectorEvent,
configs::settings,
utils::{self, BytesExt},
utils::BytesExt,
core::{
errors::{self, CustomResult},
},
Expand Down
4 changes: 2 additions & 2 deletions connector-template/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use masking::Secret;
use crate::{connector::utils::{PaymentsAuthorizeRequestData},core::errors,types::{self,api, storage::enums}};
use crate::{connector::utils::{PaymentsAuthorizeRequestData},core::errors,types::{self, domain, api, storage::enums}};

//TODO: Fill the struct with respective fields
pub struct {{project-name | downcase | pascal_case}}RouterData<T> {
Expand Down Expand Up @@ -53,7 +53,7 @@ impl TryFrom<&{{project-name | downcase | pascal_case}}RouterData<&types::Paymen
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &{{project-name | downcase | pascal_case}}RouterData<&types::PaymentsAuthorizeRouterData>) -> Result<Self,Self::Error> {
match item.router_data.request.payment_method_data.clone() {
api::PaymentMethodData::Card(req_card) => {
domain::PaymentMethodData::Card(req_card) => {
let card = {{project-name | downcase | pascal_case}}Card {
number: req_card.card_number,
expiry_month: req_card.card_exp_month,
Expand Down
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_
# Third party deps
async-trait = "0.1.79"
error-stack = "0.4.1"
http = "0.2.12"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
thiserror = "1.0.58"
Expand Down
2 changes: 2 additions & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub mod errors;
pub mod mandates;
pub mod payment_address;
pub mod payments;
#[cfg(feature = "payouts")]
pub mod payouts;
pub mod router_data;

#[cfg(not(feature = "payouts"))]
pub trait PayoutAttemptInterface {}
Expand Down
82 changes: 82 additions & 0 deletions crates/hyperswitch_domain_models/src/payment_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use api_models::payments::Address;

#[derive(Clone, Default, Debug)]
pub struct PaymentAddress {
shipping: Option<Address>,
billing: Option<Address>,
unified_payment_method_billing: Option<Address>,
payment_method_billing: Option<Address>,
}

impl PaymentAddress {
pub fn new(
shipping: Option<Address>,
billing: Option<Address>,
payment_method_billing: Option<Address>,
should_unify_address: Option<bool>,
) -> Self {
// billing -> .billing, this is the billing details passed in the root of payments request
// payment_method_billing -> .payment_method_data.billing

let unified_payment_method_billing = if should_unify_address.unwrap_or(true) {
// Merge the billing details field from both `payment.billing` and `payment.payment_method_data.billing`
// The unified payment_method_billing will be used as billing address and passed to the connector module
// This unification is required in order to provide backwards compatibility
// so that if `payment.billing` is passed it should be sent to the connector module
// Unify the billing details with `payment_method_data.billing`
payment_method_billing
.as_ref()
.map(|payment_method_billing| {
payment_method_billing
.clone()
.unify_address(billing.as_ref())
})
.or(billing.clone())
} else {
payment_method_billing.clone()
};

Self {
shipping,
billing,
unified_payment_method_billing,
payment_method_billing,
}
}

pub fn get_shipping(&self) -> Option<&Address> {
self.shipping.as_ref()
}

pub fn get_payment_method_billing(&self) -> Option<&Address> {
self.unified_payment_method_billing.as_ref()
}

/// Unify the billing details from `payment_method_data.[payment_method_data].billing details`.
pub fn unify_with_payment_method_data_billing(
self,
payment_method_data_billing: Option<Address>,
) -> Self {
// Unify the billing details with `payment_method_data.billing_details`
let unified_payment_method_billing = payment_method_data_billing
.map(|payment_method_data_billing| {
payment_method_data_billing.unify_address(self.get_payment_method_billing())
})
.or(self.get_payment_method_billing().cloned());

Self {
shipping: self.shipping,
billing: self.billing,
unified_payment_method_billing,
payment_method_billing: self.payment_method_billing,
}
}

pub fn get_request_payment_method_billing(&self) -> Option<&Address> {
self.payment_method_billing.as_ref()
}

pub fn get_payment_billing(&self) -> Option<&Address> {
self.billing.as_ref()
}
}
Loading
Loading