mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
feat(router): add payments create-intent flow for v2 (#6193)
Co-authored-by: hrithikesh026 <hrithikesh.vm@juspay.in> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9576ee37a6
commit
afa803e0f9
@ -54,3 +54,109 @@ impl<T: ForeignIDRef> RemoteStorageObject<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub trait ApiModelToDieselModelConvertor<F> {
|
||||
/// Convert from a foreign type to the current type
|
||||
fn convert_from(from: F) -> Self;
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
|
||||
for diesel_models::payment_intent::PaymentLinkConfigRequestForPayments
|
||||
{
|
||||
fn convert_from(item: api_models::admin::PaymentLinkConfigRequest) -> Self {
|
||||
Self {
|
||||
theme: item.theme,
|
||||
logo: item.logo,
|
||||
seller_name: item.seller_name,
|
||||
sdk_layout: item.sdk_layout,
|
||||
display_sdk_only: item.display_sdk_only,
|
||||
enabled_saved_payment_method: item.enabled_saved_payment_method,
|
||||
transaction_details: item.transaction_details.map(|transaction_details| {
|
||||
transaction_details
|
||||
.into_iter()
|
||||
.map(|transaction_detail| {
|
||||
diesel_models::PaymentLinkTransactionDetails::convert_from(
|
||||
transaction_detail,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkTransactionDetails>
|
||||
for diesel_models::PaymentLinkTransactionDetails
|
||||
{
|
||||
fn convert_from(from: api_models::admin::PaymentLinkTransactionDetails) -> Self {
|
||||
Self {
|
||||
key: from.key,
|
||||
value: from.value,
|
||||
ui_configuration: from
|
||||
.ui_configuration
|
||||
.map(diesel_models::TransactionDetailsUiConfiguration::convert_from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl ApiModelToDieselModelConvertor<api_models::admin::TransactionDetailsUiConfiguration>
|
||||
for diesel_models::TransactionDetailsUiConfiguration
|
||||
{
|
||||
fn convert_from(from: api_models::admin::TransactionDetailsUiConfiguration) -> Self {
|
||||
Self {
|
||||
position: from.position,
|
||||
is_key_bold: from.is_key_bold,
|
||||
is_value_bold: from.is_value_bold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl From<api_models::payments::AmountDetails> for payments::AmountDetails {
|
||||
fn from(amount_details: api_models::payments::AmountDetails) -> Self {
|
||||
Self {
|
||||
order_amount: amount_details.order_amount().into(),
|
||||
currency: amount_details.currency(),
|
||||
shipping_cost: amount_details.shipping_cost(),
|
||||
tax_details: Some(diesel_models::TaxDetails {
|
||||
default: amount_details
|
||||
.order_tax_amount()
|
||||
.map(|order_tax_amount| diesel_models::DefaultTax { order_tax_amount }),
|
||||
payment_method_type: None,
|
||||
}),
|
||||
skip_external_tax_calculation: payments::TaxCalculationOverride::from(
|
||||
amount_details.skip_external_tax_calculation(),
|
||||
),
|
||||
skip_surcharge_calculation: payments::SurchargeCalculationOverride::from(
|
||||
amount_details.skip_surcharge_calculation(),
|
||||
),
|
||||
surcharge_amount: amount_details.surcharge_amount(),
|
||||
tax_on_surcharge: amount_details.tax_on_surcharge(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl From<common_enums::SurchargeCalculationOverride> for payments::SurchargeCalculationOverride {
|
||||
fn from(surcharge_calculation_override: common_enums::SurchargeCalculationOverride) -> Self {
|
||||
match surcharge_calculation_override {
|
||||
common_enums::SurchargeCalculationOverride::Calculate => Self::Calculate,
|
||||
common_enums::SurchargeCalculationOverride::Skip => Self::Skip,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl From<common_enums::TaxCalculationOverride> for payments::TaxCalculationOverride {
|
||||
fn from(tax_calculation_override: common_enums::TaxCalculationOverride) -> Self {
|
||||
match tax_calculation_override {
|
||||
common_enums::TaxCalculationOverride::Calculate => Self::Calculate,
|
||||
common_enums::TaxCalculationOverride::Skip => Self::Skip,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user