mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(router): remove foreign wrapper type (#616)
Co-authored-by: Arun Raj M <jarnura47@gmail.com> Co-authored-by: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Co-authored-by: Abhishek <abhishek.marrivagu@juspay.in> Co-authored-by: dracarys18 <karthikey.hegde@juspay.in> Co-authored-by: Sampras Lopes <lsampras@protonmail.com> Co-authored-by: Jagan <jaganelavarasan@gmail.com> Co-authored-by: rupakrajak <43450369+rupakrajak@users.noreply.github.com> Co-authored-by: Zaid <syed.zaidali@juspay.in> Co-authored-by: Rajak Rupakkumar Asishkumar <rajak.rupakkumar@juspay.in>
This commit is contained in:
@ -9,7 +9,7 @@ use crate::{
|
|||||||
pii::{self, PeekInterface},
|
pii::{self, PeekInterface},
|
||||||
types::{
|
types::{
|
||||||
api::enums as api_enums,
|
api::enums as api_enums,
|
||||||
transformers::{Foreign, ForeignInto},
|
transformers::{ForeignFrom, ForeignInto},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -461,12 +461,12 @@ pub enum Request3DS {
|
|||||||
Any,
|
Any,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Foreign<Option<Request3DS>>> for Foreign<api_models::enums::AuthenticationType> {
|
impl ForeignFrom<Option<Request3DS>> for api_models::enums::AuthenticationType {
|
||||||
fn from(item: Foreign<Option<Request3DS>>) -> Self {
|
fn foreign_from(item: Option<Request3DS>) -> Self {
|
||||||
Self(match item.0.unwrap_or_default() {
|
match item.unwrap_or_default() {
|
||||||
Request3DS::Automatic => api_models::enums::AuthenticationType::NoThreeDs,
|
Request3DS::Automatic => Self::NoThreeDs,
|
||||||
Request3DS::Any => api_models::enums::AuthenticationType::ThreeDs,
|
Request3DS::Any => Self::ThreeDs,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,11 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::{
|
use crate::{
|
||||||
core::errors,
|
core::errors,
|
||||||
pii::{self, Secret},
|
pii::{self, Secret},
|
||||||
types::{
|
types::{self, api, storage::enums, transformers::ForeignTryFrom},
|
||||||
self, api,
|
|
||||||
storage::enums,
|
|
||||||
transformers::{self, ForeignTryFrom},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, PartialEq)]
|
#[derive(Debug, Serialize, PartialEq)]
|
||||||
@ -148,30 +144,24 @@ pub enum BluesnapProcessingStatus {
|
|||||||
PendingMerchantReview,
|
PendingMerchantReview,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<transformers::Foreign<(BluesnapTxnType, BluesnapProcessingStatus)>>
|
impl ForeignTryFrom<(BluesnapTxnType, BluesnapProcessingStatus)> for enums::AttemptStatus {
|
||||||
for transformers::Foreign<enums::AttemptStatus>
|
|
||||||
{
|
|
||||||
type Error = error_stack::Report<errors::ConnectorError>;
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
fn try_from(
|
fn foreign_try_from(
|
||||||
item: transformers::Foreign<(BluesnapTxnType, BluesnapProcessingStatus)>,
|
item: (BluesnapTxnType, BluesnapProcessingStatus),
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let item = item.0;
|
|
||||||
let (item_txn_status, item_processing_status) = item;
|
let (item_txn_status, item_processing_status) = item;
|
||||||
Ok(match item_processing_status {
|
Ok(match item_processing_status {
|
||||||
BluesnapProcessingStatus::Success => match item_txn_status {
|
BluesnapProcessingStatus::Success => match item_txn_status {
|
||||||
BluesnapTxnType::AuthOnly => enums::AttemptStatus::Authorized,
|
BluesnapTxnType::AuthOnly => Self::Authorized,
|
||||||
BluesnapTxnType::AuthReversal => enums::AttemptStatus::Voided,
|
BluesnapTxnType::AuthReversal => Self::Voided,
|
||||||
BluesnapTxnType::AuthCapture | BluesnapTxnType::Capture => {
|
BluesnapTxnType::AuthCapture | BluesnapTxnType::Capture => Self::Charged,
|
||||||
enums::AttemptStatus::Charged
|
BluesnapTxnType::Refund => Self::Charged,
|
||||||
}
|
|
||||||
BluesnapTxnType::Refund => enums::AttemptStatus::Charged,
|
|
||||||
},
|
},
|
||||||
BluesnapProcessingStatus::Pending | BluesnapProcessingStatus::PendingMerchantReview => {
|
BluesnapProcessingStatus::Pending | BluesnapProcessingStatus::PendingMerchantReview => {
|
||||||
enums::AttemptStatus::Pending
|
Self::Pending
|
||||||
}
|
}
|
||||||
BluesnapProcessingStatus::Fail => enums::AttemptStatus::Failure,
|
BluesnapProcessingStatus::Fail => Self::Failure,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,7 @@ use url::Url;
|
|||||||
use crate::{
|
use crate::{
|
||||||
core::errors,
|
core::errors,
|
||||||
pii, services,
|
pii, services,
|
||||||
types::{
|
types::{self, api, storage::enums, transformers::ForeignFrom},
|
||||||
self, api,
|
|
||||||
storage::enums,
|
|
||||||
transformers::{self, ForeignFrom},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@ -138,38 +134,30 @@ pub enum CheckoutPaymentStatus {
|
|||||||
Captured,
|
Captured,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<transformers::Foreign<(CheckoutPaymentStatus, Option<enums::CaptureMethod>)>>
|
impl ForeignFrom<(CheckoutPaymentStatus, Option<enums::CaptureMethod>)> for enums::AttemptStatus {
|
||||||
for transformers::Foreign<enums::AttemptStatus>
|
fn foreign_from(item: (CheckoutPaymentStatus, Option<enums::CaptureMethod>)) -> Self {
|
||||||
{
|
|
||||||
fn from(
|
|
||||||
item: transformers::Foreign<(CheckoutPaymentStatus, Option<enums::CaptureMethod>)>,
|
|
||||||
) -> Self {
|
|
||||||
let item = item.0;
|
|
||||||
let (status, capture_method) = item;
|
let (status, capture_method) = item;
|
||||||
match status {
|
match status {
|
||||||
CheckoutPaymentStatus::Authorized => {
|
CheckoutPaymentStatus::Authorized => {
|
||||||
if capture_method == Some(enums::CaptureMethod::Automatic)
|
if capture_method == Some(enums::CaptureMethod::Automatic)
|
||||||
|| capture_method.is_none()
|
|| capture_method.is_none()
|
||||||
{
|
{
|
||||||
enums::AttemptStatus::Charged
|
Self::Charged
|
||||||
} else {
|
} else {
|
||||||
enums::AttemptStatus::Authorized
|
Self::Authorized
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CheckoutPaymentStatus::Captured => enums::AttemptStatus::Charged,
|
CheckoutPaymentStatus::Captured => Self::Charged,
|
||||||
CheckoutPaymentStatus::Declined => enums::AttemptStatus::Failure,
|
CheckoutPaymentStatus::Declined => Self::Failure,
|
||||||
CheckoutPaymentStatus::Pending => enums::AttemptStatus::AuthenticationPending,
|
CheckoutPaymentStatus::Pending => Self::AuthenticationPending,
|
||||||
CheckoutPaymentStatus::CardVerified => enums::AttemptStatus::Pending,
|
CheckoutPaymentStatus::CardVerified => Self::Pending,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<transformers::Foreign<(CheckoutPaymentStatus, Option<Balances>)>>
|
impl ForeignFrom<(CheckoutPaymentStatus, Option<Balances>)> for enums::AttemptStatus {
|
||||||
for transformers::Foreign<enums::AttemptStatus>
|
fn foreign_from(item: (CheckoutPaymentStatus, Option<Balances>)) -> Self {
|
||||||
{
|
let (status, balances) = item;
|
||||||
fn from(item: transformers::Foreign<(CheckoutPaymentStatus, Option<Balances>)>) -> Self {
|
|
||||||
let (status, balances) = item.0;
|
|
||||||
|
|
||||||
match status {
|
match status {
|
||||||
CheckoutPaymentStatus::Authorized => {
|
CheckoutPaymentStatus::Authorized => {
|
||||||
@ -177,17 +165,16 @@ impl From<transformers::Foreign<(CheckoutPaymentStatus, Option<Balances>)>>
|
|||||||
available_to_capture: 0,
|
available_to_capture: 0,
|
||||||
}) = balances
|
}) = balances
|
||||||
{
|
{
|
||||||
enums::AttemptStatus::Charged
|
Self::Charged
|
||||||
} else {
|
} else {
|
||||||
enums::AttemptStatus::Authorized
|
Self::Authorized
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CheckoutPaymentStatus::Captured => enums::AttemptStatus::Charged,
|
CheckoutPaymentStatus::Captured => Self::Charged,
|
||||||
CheckoutPaymentStatus::Declined => enums::AttemptStatus::Failure,
|
CheckoutPaymentStatus::Declined => Self::Failure,
|
||||||
CheckoutPaymentStatus::Pending => enums::AttemptStatus::AuthenticationPending,
|
CheckoutPaymentStatus::Pending => Self::AuthenticationPending,
|
||||||
CheckoutPaymentStatus::CardVerified => enums::AttemptStatus::Pending,
|
CheckoutPaymentStatus::CardVerified => Self::Pending,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,11 +7,7 @@ use crate::{
|
|||||||
core::errors,
|
core::errors,
|
||||||
pii::{self, Secret},
|
pii::{self, Secret},
|
||||||
services,
|
services,
|
||||||
types::{
|
types::{self, api, storage::enums, transformers::ForeignFrom},
|
||||||
self, api,
|
|
||||||
storage::enums,
|
|
||||||
transformers::{self, ForeignFrom},
|
|
||||||
},
|
|
||||||
utils::OptionExt,
|
utils::OptionExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -179,29 +175,24 @@ pub enum RapydPaymentStatus {
|
|||||||
New,
|
New,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<transformers::Foreign<(RapydPaymentStatus, NextAction)>>
|
impl ForeignFrom<(RapydPaymentStatus, NextAction)> for enums::AttemptStatus {
|
||||||
for transformers::Foreign<enums::AttemptStatus>
|
fn foreign_from(item: (RapydPaymentStatus, NextAction)) -> Self {
|
||||||
{
|
let (status, next_action) = item;
|
||||||
fn from(item: transformers::Foreign<(RapydPaymentStatus, NextAction)>) -> Self {
|
|
||||||
let (status, next_action) = item.0;
|
|
||||||
match (status, next_action) {
|
match (status, next_action) {
|
||||||
(RapydPaymentStatus::Closed, _) => enums::AttemptStatus::Charged,
|
(RapydPaymentStatus::Closed, _) => Self::Charged,
|
||||||
(RapydPaymentStatus::Active, NextAction::ThreedsVerification) => {
|
(RapydPaymentStatus::Active, NextAction::ThreedsVerification) => {
|
||||||
enums::AttemptStatus::AuthenticationPending
|
Self::AuthenticationPending
|
||||||
}
|
|
||||||
(RapydPaymentStatus::Active, NextAction::PendingCapture) => {
|
|
||||||
enums::AttemptStatus::Authorized
|
|
||||||
}
|
}
|
||||||
|
(RapydPaymentStatus::Active, NextAction::PendingCapture) => Self::Authorized,
|
||||||
(
|
(
|
||||||
RapydPaymentStatus::CanceledByClientOrBank
|
RapydPaymentStatus::CanceledByClientOrBank
|
||||||
| RapydPaymentStatus::Expired
|
| RapydPaymentStatus::Expired
|
||||||
| RapydPaymentStatus::ReversedByRapyd,
|
| RapydPaymentStatus::ReversedByRapyd,
|
||||||
_,
|
_,
|
||||||
) => enums::AttemptStatus::Voided,
|
) => Self::Voided,
|
||||||
(RapydPaymentStatus::Error, _) => enums::AttemptStatus::Failure,
|
(RapydPaymentStatus::Error, _) => Self::Failure,
|
||||||
(RapydPaymentStatus::New, _) => enums::AttemptStatus::Authorizing,
|
(RapydPaymentStatus::New, _) => Self::Authorizing,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,11 +6,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::{
|
use crate::{
|
||||||
connector::utils::{self, CardData},
|
connector::utils::{self, CardData},
|
||||||
core::errors,
|
core::errors,
|
||||||
types::{
|
types::{self, api, storage::enums, transformers::ForeignFrom},
|
||||||
self, api,
|
|
||||||
storage::enums,
|
|
||||||
transformers::{self, ForeignFrom},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
|
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
|
||||||
@ -297,30 +293,25 @@ pub enum PaymentStatus {
|
|||||||
Processing,
|
Processing,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<transformers::Foreign<(PaymentStatus, enums::CaptureMethod)>>
|
impl ForeignFrom<(PaymentStatus, enums::CaptureMethod)> for enums::AttemptStatus {
|
||||||
for transformers::Foreign<enums::AttemptStatus>
|
fn foreign_from(item: (PaymentStatus, enums::CaptureMethod)) -> Self {
|
||||||
{
|
let (status, capture_method) = item;
|
||||||
fn from(item: transformers::Foreign<(PaymentStatus, enums::CaptureMethod)>) -> Self {
|
|
||||||
let (status, capture_method) = item.0;
|
|
||||||
match status {
|
match status {
|
||||||
PaymentStatus::Captured
|
PaymentStatus::Captured
|
||||||
| PaymentStatus::Paid
|
| PaymentStatus::Paid
|
||||||
| PaymentStatus::ChargebackNotification => enums::AttemptStatus::Charged,
|
| PaymentStatus::ChargebackNotification => Self::Charged,
|
||||||
PaymentStatus::Cancelled => enums::AttemptStatus::Voided,
|
PaymentStatus::Cancelled => Self::Voided,
|
||||||
PaymentStatus::Rejected | PaymentStatus::RejectedCapture => {
|
PaymentStatus::Rejected | PaymentStatus::RejectedCapture => Self::Failure,
|
||||||
enums::AttemptStatus::Failure
|
|
||||||
}
|
|
||||||
PaymentStatus::CaptureRequested => {
|
PaymentStatus::CaptureRequested => {
|
||||||
if capture_method == enums::CaptureMethod::Automatic {
|
if capture_method == enums::CaptureMethod::Automatic {
|
||||||
enums::AttemptStatus::Pending
|
Self::Pending
|
||||||
} else {
|
} else {
|
||||||
enums::AttemptStatus::CaptureInitiated
|
Self::CaptureInitiated
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PaymentStatus::PendingApproval => enums::AttemptStatus::Authorized,
|
PaymentStatus::PendingApproval => Self::Authorized,
|
||||||
_ => enums::AttemptStatus::Pending,
|
_ => Self::Pending,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ use crate::{
|
|||||||
self,
|
self,
|
||||||
api::{self, refunds},
|
api::{self, refunds},
|
||||||
storage::{self, enums, ProcessTrackerExt},
|
storage::{self, enums, ProcessTrackerExt},
|
||||||
transformers::{Foreign, ForeignInto},
|
transformers::{ForeignFrom, ForeignInto},
|
||||||
},
|
},
|
||||||
utils::{self, OptionExt},
|
utils::{self, OptionExt},
|
||||||
};
|
};
|
||||||
@ -560,10 +560,10 @@ pub async fn refund_list(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Foreign<storage::Refund>> for Foreign<api::RefundResponse> {
|
impl ForeignFrom<storage::Refund> for api::RefundResponse {
|
||||||
fn from(refund: Foreign<storage::Refund>) -> Self {
|
fn foreign_from(refund: storage::Refund) -> Self {
|
||||||
let refund = refund.0;
|
let refund = refund;
|
||||||
api::RefundResponse {
|
Self {
|
||||||
payment_id: refund.payment_id,
|
payment_id: refund.payment_id,
|
||||||
refund_id: refund.refund_id,
|
refund_id: refund.refund_id,
|
||||||
amount: refund.refund_amount,
|
amount: refund.refund_amount,
|
||||||
@ -576,7 +576,6 @@ impl From<Foreign<storage::Refund>> for Foreign<api::RefundResponse> {
|
|||||||
created_at: Some(refund.created_at),
|
created_at: Some(refund.created_at),
|
||||||
updated_at: Some(refund.updated_at),
|
updated_at: Some(refund.updated_at),
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -153,10 +153,7 @@ async fn refunds_incoming_webhook_flow(
|
|||||||
.foreign_try_into()
|
.foreign_try_into()
|
||||||
.into_report()
|
.into_report()
|
||||||
.change_context(errors::WebhooksFlowError::RefundsCoreFailed)?;
|
.change_context(errors::WebhooksFlowError::RefundsCoreFailed)?;
|
||||||
let refund_response: api_models::refunds::RefundResponse = updated_refund
|
let refund_response: api_models::refunds::RefundResponse = updated_refund.foreign_into();
|
||||||
.foreign_try_into()
|
|
||||||
.into_report()
|
|
||||||
.change_context(errors::WebhooksFlowError::RefundsCoreFailed)?;
|
|
||||||
create_event_and_trigger_outgoing_webhook(
|
create_event_and_trigger_outgoing_webhook(
|
||||||
state,
|
state,
|
||||||
merchant_account,
|
merchant_account,
|
||||||
|
|||||||
@ -5,12 +5,12 @@ pub use api_models::admin::{
|
|||||||
ToggleKVResponse, WebhookDetails,
|
ToggleKVResponse, WebhookDetails,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::types::{storage, transformers::Foreign};
|
use crate::types::{storage, transformers::ForeignFrom};
|
||||||
|
|
||||||
impl From<Foreign<storage::MerchantAccount>> for Foreign<MerchantAccountResponse> {
|
impl ForeignFrom<storage::MerchantAccount> for MerchantAccountResponse {
|
||||||
fn from(value: Foreign<storage::MerchantAccount>) -> Self {
|
fn foreign_from(value: storage::MerchantAccount) -> Self {
|
||||||
let item = value.0;
|
let item = value;
|
||||||
MerchantAccountResponse {
|
Self {
|
||||||
merchant_id: item.merchant_id,
|
merchant_id: item.merchant_id,
|
||||||
merchant_name: item.merchant_name,
|
merchant_name: item.merchant_name,
|
||||||
api_key: item.api_key,
|
api_key: item.api_key,
|
||||||
@ -27,62 +27,5 @@ impl From<Foreign<storage::MerchantAccount>> for Foreign<MerchantAccountResponse
|
|||||||
metadata: item.metadata,
|
metadata: item.metadata,
|
||||||
locker_id: item.locker_id,
|
locker_id: item.locker_id,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
//use crate::newtype;
|
|
||||||
|
|
||||||
//use api_models::admin;
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub CreateMerchantAccount = admin::CreateMerchantAccount,
|
|
||||||
//derives = (Clone, Debug, Deserialize, Serialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub MerchantDetails = admin::MerchantDetails,
|
|
||||||
//derives = (Clone, Debug, Deserialize, Serialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub WebhookDetails = admin::WebhookDetails,
|
|
||||||
//derives = (Clone, Debug, Deserialize, Serialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub CustomRoutingRules = admin::CustomRoutingRules,
|
|
||||||
//derives = (Default, Clone, Debug, Deserialize, Serialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub DeleteResponse = admin::DeleteResponse,
|
|
||||||
//derives = (Debug, Serialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub MerchantId = admin::MerchantId,
|
|
||||||
//derives = (Default, Debug, Deserialize, Serialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub MerchantConnectorId = admin::MerchantConnectorId,
|
|
||||||
//derives = (Default, Debug, Deserialize, Serialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub PaymentConnectorCreate = admin::PaymentConnectorCreate,
|
|
||||||
//derives = (Debug, Clone, Serialize, Deserialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub PaymentMethods = admin::PaymentMethods,
|
|
||||||
//derives = (Debug, Clone, Serialize, Deserialize)
|
|
||||||
//);
|
|
||||||
|
|
||||||
//newtype!(
|
|
||||||
//pub DeleteMcaResponse = admin::DeleteMcaResponse,
|
|
||||||
//derives = (Debug, Clone, Serialize, Deserialize)
|
|
||||||
//);
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ use crate::{
|
|||||||
services::api,
|
services::api,
|
||||||
types::{
|
types::{
|
||||||
self, api as api_types, storage,
|
self, api as api_types, storage,
|
||||||
transformers::{Foreign, ForeignInto},
|
transformers::{ForeignFrom, ForeignInto},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,10 +114,10 @@ impl MandateValidationFieldsExt for MandateValidationFields {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Foreign<storage::PaymentIntent>> for Foreign<PaymentsResponse> {
|
impl ForeignFrom<storage::PaymentIntent> for PaymentsResponse {
|
||||||
fn from(item: Foreign<storage::PaymentIntent>) -> Self {
|
fn foreign_from(item: storage::PaymentIntent) -> Self {
|
||||||
let item = item.0;
|
let item = item;
|
||||||
PaymentsResponse {
|
Self {
|
||||||
payment_id: Some(item.payment_id),
|
payment_id: Some(item.payment_id),
|
||||||
merchant_id: Some(item.merchant_id),
|
merchant_id: Some(item.merchant_id),
|
||||||
status: item.status.foreign_into(),
|
status: item.status.foreign_into(),
|
||||||
@ -131,7 +131,6 @@ impl From<Foreign<storage::PaymentIntent>> for Foreign<PaymentsResponse> {
|
|||||||
customer_id: item.customer_id,
|
customer_id: item.customer_id,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,19 +5,18 @@ pub use api_models::refunds::{
|
|||||||
use super::ConnectorCommon;
|
use super::ConnectorCommon;
|
||||||
use crate::{
|
use crate::{
|
||||||
services::api,
|
services::api,
|
||||||
types::{self, storage::enums as storage_enums, transformers::Foreign},
|
types::{self, storage::enums as storage_enums, transformers::ForeignFrom},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl From<Foreign<storage_enums::RefundStatus>> for Foreign<RefundStatus> {
|
impl ForeignFrom<storage_enums::RefundStatus> for RefundStatus {
|
||||||
fn from(status: Foreign<storage_enums::RefundStatus>) -> Self {
|
fn foreign_from(status: storage_enums::RefundStatus) -> Self {
|
||||||
match status.0 {
|
match status {
|
||||||
storage_enums::RefundStatus::Failure
|
storage_enums::RefundStatus::Failure
|
||||||
| storage_enums::RefundStatus::TransactionFailure => RefundStatus::Failed,
|
| storage_enums::RefundStatus::TransactionFailure => Self::Failed,
|
||||||
storage_enums::RefundStatus::ManualReview => RefundStatus::Review,
|
storage_enums::RefundStatus::ManualReview => Self::Review,
|
||||||
storage_enums::RefundStatus::Pending => RefundStatus::Pending,
|
storage_enums::RefundStatus::Pending => Self::Pending,
|
||||||
storage_enums::RefundStatus::Success => RefundStatus::Succeeded,
|
storage_enums::RefundStatus::Success => Self::Succeeded,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
use std::convert::TryInto;
|
|
||||||
|
|
||||||
use api_models::enums as api_enums;
|
use api_models::enums as api_enums;
|
||||||
use common_utils::ext_traits::ValueExt;
|
use common_utils::ext_traits::ValueExt;
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
@ -10,16 +8,6 @@ use crate::{
|
|||||||
types::{api as api_types, storage},
|
types::{api as api_types, storage},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Foreign<T>(pub T);
|
|
||||||
|
|
||||||
type F<T> = Foreign<T>;
|
|
||||||
|
|
||||||
impl<T> From<T> for Foreign<T> {
|
|
||||||
fn from(val: T) -> Self {
|
|
||||||
Self(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ForeignInto<T> {
|
pub trait ForeignInto<T> {
|
||||||
fn foreign_into(self) -> T;
|
fn foreign_into(self) -> T;
|
||||||
}
|
}
|
||||||
@ -42,142 +30,105 @@ pub trait ForeignTryFrom<F>: Sized {
|
|||||||
|
|
||||||
impl<F, T> ForeignInto<T> for F
|
impl<F, T> ForeignInto<T> for F
|
||||||
where
|
where
|
||||||
Foreign<F>: Into<Foreign<T>>,
|
T: ForeignFrom<F>,
|
||||||
{
|
{
|
||||||
fn foreign_into(self) -> T {
|
fn foreign_into(self) -> T {
|
||||||
let f_from = Foreign(self);
|
T::foreign_from(self)
|
||||||
let f_to: Foreign<T> = f_from.into();
|
|
||||||
f_to.0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F, T> ForeignTryInto<T> for F
|
impl<F, T> ForeignTryInto<T> for F
|
||||||
where
|
where
|
||||||
Foreign<F>: TryInto<Foreign<T>>,
|
T: ForeignTryFrom<F>,
|
||||||
{
|
{
|
||||||
type Error = <Foreign<F> as TryInto<Foreign<T>>>::Error;
|
type Error = <T as ForeignTryFrom<F>>::Error;
|
||||||
|
|
||||||
fn foreign_try_into(self) -> Result<T, Self::Error> {
|
fn foreign_try_into(self) -> Result<T, Self::Error> {
|
||||||
let f_from = Foreign(self);
|
T::foreign_try_from(self)
|
||||||
let f_to: Result<Foreign<T>, Self::Error> = f_from.try_into();
|
|
||||||
f_to.map(|f| f.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F, T> ForeignFrom<F> for T
|
impl ForeignFrom<api_enums::ConnectorType> for storage_enums::ConnectorType {
|
||||||
where
|
fn foreign_from(conn: api_enums::ConnectorType) -> Self {
|
||||||
Foreign<T>: From<Foreign<F>>,
|
frunk::labelled_convert_from(conn)
|
||||||
{
|
|
||||||
fn foreign_from(from: F) -> Self {
|
|
||||||
let f_from = Foreign(from);
|
|
||||||
let f_to: Foreign<Self> = f_from.into();
|
|
||||||
f_to.0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F, T> ForeignTryFrom<F> for T
|
impl ForeignFrom<storage_enums::ConnectorType> for api_enums::ConnectorType {
|
||||||
where
|
fn foreign_from(conn: storage_enums::ConnectorType) -> Self {
|
||||||
Foreign<T>: TryFrom<Foreign<F>>,
|
frunk::labelled_convert_from(conn)
|
||||||
{
|
|
||||||
type Error = <Foreign<T> as TryFrom<Foreign<F>>>::Error;
|
|
||||||
|
|
||||||
fn foreign_try_from(from: F) -> Result<Self, Self::Error> {
|
|
||||||
let f_from = Foreign(from);
|
|
||||||
let f_to: Result<Foreign<Self>, Self::Error> = f_from.try_into();
|
|
||||||
f_to.map(|f| f.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::ConnectorType>> for F<storage_enums::ConnectorType> {
|
impl ForeignFrom<api_models::refunds::RefundType> for storage_enums::RefundType {
|
||||||
fn from(conn: F<api_enums::ConnectorType>) -> Self {
|
fn foreign_from(item: api_models::refunds::RefundType) -> Self {
|
||||||
Self(frunk::labelled_convert_from(conn.0))
|
match item {
|
||||||
}
|
api_models::refunds::RefundType::Instant => Self::InstantRefund,
|
||||||
}
|
api_models::refunds::RefundType::Scheduled => Self::RegularRefund,
|
||||||
|
|
||||||
impl From<F<storage_enums::ConnectorType>> for F<api_enums::ConnectorType> {
|
|
||||||
fn from(conn: F<storage_enums::ConnectorType>) -> Self {
|
|
||||||
Self(frunk::labelled_convert_from(conn.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<F<api_models::refunds::RefundType>> for F<storage_enums::RefundType> {
|
|
||||||
fn from(item: F<api_models::refunds::RefundType>) -> Self {
|
|
||||||
match item.0 {
|
|
||||||
api_models::refunds::RefundType::Instant => storage_enums::RefundType::InstantRefund,
|
|
||||||
api_models::refunds::RefundType::Scheduled => storage_enums::RefundType::RegularRefund,
|
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::MandateStatus>> for F<api_enums::MandateStatus> {
|
impl ForeignFrom<storage_enums::MandateStatus> for api_enums::MandateStatus {
|
||||||
fn from(status: F<storage_enums::MandateStatus>) -> Self {
|
fn foreign_from(status: storage_enums::MandateStatus) -> Self {
|
||||||
Self(frunk::labelled_convert_from(status.0))
|
frunk::labelled_convert_from(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::PaymentMethod>> for F<storage_enums::PaymentMethod> {
|
impl ForeignFrom<api_enums::PaymentMethod> for storage_enums::PaymentMethod {
|
||||||
fn from(pm_type: F<api_enums::PaymentMethod>) -> Self {
|
fn foreign_from(pm_type: api_enums::PaymentMethod) -> Self {
|
||||||
Self(frunk::labelled_convert_from(pm_type.0))
|
frunk::labelled_convert_from(pm_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::PaymentMethod>> for F<api_enums::PaymentMethod> {
|
impl ForeignFrom<storage_enums::PaymentMethod> for api_enums::PaymentMethod {
|
||||||
fn from(pm_type: F<storage_enums::PaymentMethod>) -> Self {
|
fn foreign_from(pm_type: storage_enums::PaymentMethod) -> Self {
|
||||||
Self(frunk::labelled_convert_from(pm_type.0))
|
frunk::labelled_convert_from(pm_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::PaymentMethodIssuerCode>> for F<api_enums::PaymentMethodIssuerCode> {
|
impl ForeignFrom<storage_enums::PaymentMethodIssuerCode> for api_enums::PaymentMethodIssuerCode {
|
||||||
fn from(issuer_code: F<storage_enums::PaymentMethodIssuerCode>) -> Self {
|
fn foreign_from(issuer_code: storage_enums::PaymentMethodIssuerCode) -> Self {
|
||||||
Self(frunk::labelled_convert_from(issuer_code.0))
|
frunk::labelled_convert_from(issuer_code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::PaymentExperience>> for F<storage_enums::PaymentExperience> {
|
impl ForeignFrom<api_enums::PaymentExperience> for storage_enums::PaymentExperience {
|
||||||
fn from(experience: F<api_enums::PaymentExperience>) -> Self {
|
fn foreign_from(experience: api_enums::PaymentExperience) -> Self {
|
||||||
Self(frunk::labelled_convert_from(experience.0))
|
frunk::labelled_convert_from(experience)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::PaymentExperience>> for F<api_enums::PaymentExperience> {
|
impl ForeignFrom<storage_enums::PaymentExperience> for api_enums::PaymentExperience {
|
||||||
fn from(experience: F<storage_enums::PaymentExperience>) -> Self {
|
fn foreign_from(experience: storage_enums::PaymentExperience) -> Self {
|
||||||
Self(frunk::labelled_convert_from(experience.0))
|
frunk::labelled_convert_from(experience)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::IntentStatus>> for F<api_enums::IntentStatus> {
|
impl ForeignFrom<storage_enums::IntentStatus> for api_enums::IntentStatus {
|
||||||
fn from(status: F<storage_enums::IntentStatus>) -> Self {
|
fn foreign_from(status: storage_enums::IntentStatus) -> Self {
|
||||||
Self(frunk::labelled_convert_from(status.0))
|
frunk::labelled_convert_from(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::IntentStatus>> for F<storage_enums::IntentStatus> {
|
impl ForeignFrom<api_enums::IntentStatus> for storage_enums::IntentStatus {
|
||||||
fn from(status: F<api_enums::IntentStatus>) -> Self {
|
fn foreign_from(status: api_enums::IntentStatus) -> Self {
|
||||||
Self(frunk::labelled_convert_from(status.0))
|
frunk::labelled_convert_from(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::AttemptStatus>> for F<storage_enums::IntentStatus> {
|
impl ForeignFrom<storage_enums::AttemptStatus> for storage_enums::IntentStatus {
|
||||||
fn from(s: F<storage_enums::AttemptStatus>) -> Self {
|
fn foreign_from(s: storage_enums::AttemptStatus) -> Self {
|
||||||
match s.0 {
|
match s {
|
||||||
storage_enums::AttemptStatus::Charged | storage_enums::AttemptStatus::AutoRefunded => {
|
storage_enums::AttemptStatus::Charged | storage_enums::AttemptStatus::AutoRefunded => {
|
||||||
storage_enums::IntentStatus::Succeeded
|
Self::Succeeded
|
||||||
}
|
}
|
||||||
|
|
||||||
storage_enums::AttemptStatus::ConfirmationAwaited => {
|
storage_enums::AttemptStatus::ConfirmationAwaited => Self::RequiresConfirmation,
|
||||||
storage_enums::IntentStatus::RequiresConfirmation
|
storage_enums::AttemptStatus::PaymentMethodAwaited => Self::RequiresPaymentMethod,
|
||||||
}
|
|
||||||
storage_enums::AttemptStatus::PaymentMethodAwaited => {
|
|
||||||
storage_enums::IntentStatus::RequiresPaymentMethod
|
|
||||||
}
|
|
||||||
|
|
||||||
storage_enums::AttemptStatus::Authorized => {
|
storage_enums::AttemptStatus::Authorized => Self::RequiresCapture,
|
||||||
storage_enums::IntentStatus::RequiresCapture
|
storage_enums::AttemptStatus::AuthenticationPending => Self::RequiresCustomerAction,
|
||||||
}
|
|
||||||
storage_enums::AttemptStatus::AuthenticationPending => {
|
|
||||||
storage_enums::IntentStatus::RequiresCustomerAction
|
|
||||||
}
|
|
||||||
|
|
||||||
storage_enums::AttemptStatus::PartialCharged
|
storage_enums::AttemptStatus::PartialCharged
|
||||||
| storage_enums::AttemptStatus::Started
|
| storage_enums::AttemptStatus::Started
|
||||||
@ -186,131 +137,125 @@ impl From<F<storage_enums::AttemptStatus>> for F<storage_enums::IntentStatus> {
|
|||||||
| storage_enums::AttemptStatus::CodInitiated
|
| storage_enums::AttemptStatus::CodInitiated
|
||||||
| storage_enums::AttemptStatus::VoidInitiated
|
| storage_enums::AttemptStatus::VoidInitiated
|
||||||
| storage_enums::AttemptStatus::CaptureInitiated
|
| storage_enums::AttemptStatus::CaptureInitiated
|
||||||
| storage_enums::AttemptStatus::Pending => storage_enums::IntentStatus::Processing,
|
| storage_enums::AttemptStatus::Pending => Self::Processing,
|
||||||
|
|
||||||
storage_enums::AttemptStatus::AuthenticationFailed
|
storage_enums::AttemptStatus::AuthenticationFailed
|
||||||
| storage_enums::AttemptStatus::AuthorizationFailed
|
| storage_enums::AttemptStatus::AuthorizationFailed
|
||||||
| storage_enums::AttemptStatus::VoidFailed
|
| storage_enums::AttemptStatus::VoidFailed
|
||||||
| storage_enums::AttemptStatus::RouterDeclined
|
| storage_enums::AttemptStatus::RouterDeclined
|
||||||
| storage_enums::AttemptStatus::CaptureFailed
|
| storage_enums::AttemptStatus::CaptureFailed
|
||||||
| storage_enums::AttemptStatus::Failure => storage_enums::IntentStatus::Failed,
|
| storage_enums::AttemptStatus::Failure => Self::Failed,
|
||||||
storage_enums::AttemptStatus::Voided => storage_enums::IntentStatus::Cancelled,
|
storage_enums::AttemptStatus::Voided => Self::Cancelled,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<F<api_enums::IntentStatus>> for F<storage_enums::EventType> {
|
impl ForeignTryFrom<api_enums::IntentStatus> for storage_enums::EventType {
|
||||||
type Error = errors::ValidationError;
|
type Error = errors::ValidationError;
|
||||||
|
|
||||||
fn try_from(value: F<api_enums::IntentStatus>) -> Result<Self, Self::Error> {
|
fn foreign_try_from(value: api_enums::IntentStatus) -> Result<Self, Self::Error> {
|
||||||
match value.0 {
|
match value {
|
||||||
api_enums::IntentStatus::Succeeded => Ok(storage_enums::EventType::PaymentSucceeded),
|
api_enums::IntentStatus::Succeeded => Ok(Self::PaymentSucceeded),
|
||||||
_ => Err(errors::ValidationError::IncorrectValueProvided {
|
_ => Err(errors::ValidationError::IncorrectValueProvided {
|
||||||
field_name: "intent_status",
|
field_name: "intent_status",
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
.map(Into::into)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<F<storage_enums::RefundStatus>> for F<storage_enums::EventType> {
|
impl ForeignTryFrom<storage_enums::RefundStatus> for storage_enums::EventType {
|
||||||
type Error = errors::ValidationError;
|
type Error = errors::ValidationError;
|
||||||
|
|
||||||
fn try_from(value: F<storage_enums::RefundStatus>) -> Result<Self, Self::Error> {
|
fn foreign_try_from(value: storage_enums::RefundStatus) -> Result<Self, Self::Error> {
|
||||||
match value.0 {
|
match value {
|
||||||
storage_enums::RefundStatus::Success => Ok(storage_enums::EventType::RefundSucceeded),
|
storage_enums::RefundStatus::Success => Ok(Self::RefundSucceeded),
|
||||||
storage_enums::RefundStatus::Failure => Ok(storage_enums::EventType::RefundFailed),
|
storage_enums::RefundStatus::Failure => Ok(Self::RefundFailed),
|
||||||
_ => Err(errors::ValidationError::IncorrectValueProvided {
|
_ => Err(errors::ValidationError::IncorrectValueProvided {
|
||||||
field_name: "refund_status",
|
field_name: "refund_status",
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
.map(Into::into)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<F<api_models::webhooks::IncomingWebhookEvent>> for F<storage_enums::RefundStatus> {
|
impl ForeignTryFrom<api_models::webhooks::IncomingWebhookEvent> for storage_enums::RefundStatus {
|
||||||
type Error = errors::ValidationError;
|
type Error = errors::ValidationError;
|
||||||
|
|
||||||
fn try_from(value: F<api_models::webhooks::IncomingWebhookEvent>) -> Result<Self, Self::Error> {
|
fn foreign_try_from(
|
||||||
match value.0 {
|
value: api_models::webhooks::IncomingWebhookEvent,
|
||||||
api_models::webhooks::IncomingWebhookEvent::RefundSuccess => {
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(storage_enums::RefundStatus::Success)
|
match value {
|
||||||
}
|
api_models::webhooks::IncomingWebhookEvent::RefundSuccess => Ok(Self::Success),
|
||||||
api_models::webhooks::IncomingWebhookEvent::RefundFailure => {
|
api_models::webhooks::IncomingWebhookEvent::RefundFailure => Ok(Self::Failure),
|
||||||
Ok(storage_enums::RefundStatus::Failure)
|
|
||||||
}
|
|
||||||
_ => Err(errors::ValidationError::IncorrectValueProvided {
|
_ => Err(errors::ValidationError::IncorrectValueProvided {
|
||||||
field_name: "incoming_webhook_event_type",
|
field_name: "incoming_webhook_event_type",
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
.map(Into::into)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::EventType>> for F<api_enums::EventType> {
|
impl ForeignFrom<storage_enums::EventType> for api_enums::EventType {
|
||||||
fn from(event_type: F<storage_enums::EventType>) -> Self {
|
fn foreign_from(event_type: storage_enums::EventType) -> Self {
|
||||||
Self(frunk::labelled_convert_from(event_type.0))
|
frunk::labelled_convert_from(event_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::FutureUsage>> for F<storage_enums::FutureUsage> {
|
impl ForeignFrom<api_enums::FutureUsage> for storage_enums::FutureUsage {
|
||||||
fn from(future_usage: F<api_enums::FutureUsage>) -> Self {
|
fn foreign_from(future_usage: api_enums::FutureUsage) -> Self {
|
||||||
Self(frunk::labelled_convert_from(future_usage.0))
|
frunk::labelled_convert_from(future_usage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::FutureUsage>> for F<api_enums::FutureUsage> {
|
impl ForeignFrom<storage_enums::FutureUsage> for api_enums::FutureUsage {
|
||||||
fn from(future_usage: F<storage_enums::FutureUsage>) -> Self {
|
fn foreign_from(future_usage: storage_enums::FutureUsage) -> Self {
|
||||||
Self(frunk::labelled_convert_from(future_usage.0))
|
frunk::labelled_convert_from(future_usage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::RefundStatus>> for F<api_enums::RefundStatus> {
|
impl ForeignFrom<storage_enums::RefundStatus> for api_enums::RefundStatus {
|
||||||
fn from(status: F<storage_enums::RefundStatus>) -> Self {
|
fn foreign_from(status: storage_enums::RefundStatus) -> Self {
|
||||||
Self(frunk::labelled_convert_from(status.0))
|
frunk::labelled_convert_from(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::CaptureMethod>> for F<storage_enums::CaptureMethod> {
|
impl ForeignFrom<api_enums::CaptureMethod> for storage_enums::CaptureMethod {
|
||||||
fn from(capture_method: F<api_enums::CaptureMethod>) -> Self {
|
fn foreign_from(capture_method: api_enums::CaptureMethod) -> Self {
|
||||||
Self(frunk::labelled_convert_from(capture_method.0))
|
frunk::labelled_convert_from(capture_method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::CaptureMethod>> for F<api_enums::CaptureMethod> {
|
impl ForeignFrom<storage_enums::CaptureMethod> for api_enums::CaptureMethod {
|
||||||
fn from(capture_method: F<storage_enums::CaptureMethod>) -> Self {
|
fn foreign_from(capture_method: storage_enums::CaptureMethod) -> Self {
|
||||||
Self(frunk::labelled_convert_from(capture_method.0))
|
frunk::labelled_convert_from(capture_method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::AuthenticationType>> for F<storage_enums::AuthenticationType> {
|
impl ForeignFrom<api_enums::AuthenticationType> for storage_enums::AuthenticationType {
|
||||||
fn from(auth_type: F<api_enums::AuthenticationType>) -> Self {
|
fn foreign_from(auth_type: api_enums::AuthenticationType) -> Self {
|
||||||
Self(frunk::labelled_convert_from(auth_type.0))
|
frunk::labelled_convert_from(auth_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::AuthenticationType>> for F<api_enums::AuthenticationType> {
|
impl ForeignFrom<storage_enums::AuthenticationType> for api_enums::AuthenticationType {
|
||||||
fn from(auth_type: F<storage_enums::AuthenticationType>) -> Self {
|
fn foreign_from(auth_type: storage_enums::AuthenticationType) -> Self {
|
||||||
Self(frunk::labelled_convert_from(auth_type.0))
|
frunk::labelled_convert_from(auth_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_enums::Currency>> for F<storage_enums::Currency> {
|
impl ForeignFrom<api_enums::Currency> for storage_enums::Currency {
|
||||||
fn from(currency: F<api_enums::Currency>) -> Self {
|
fn foreign_from(currency: api_enums::Currency) -> Self {
|
||||||
Self(frunk::labelled_convert_from(currency.0))
|
frunk::labelled_convert_from(currency)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<F<storage_enums::Currency>> for F<api_enums::Currency> {
|
impl ForeignFrom<storage_enums::Currency> for api_enums::Currency {
|
||||||
fn from(currency: F<storage_enums::Currency>) -> Self {
|
fn foreign_from(currency: storage_enums::Currency) -> Self {
|
||||||
Self(frunk::labelled_convert_from(currency.0))
|
frunk::labelled_convert_from(currency)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<F<&'a api_types::Address>> for F<storage::AddressUpdate> {
|
impl<'a> ForeignFrom<&'a api_types::Address> for storage::AddressUpdate {
|
||||||
fn from(address: F<&api_types::Address>) -> Self {
|
fn foreign_from(address: &api_types::Address) -> Self {
|
||||||
let address = address.0;
|
let address = address;
|
||||||
storage::AddressUpdate::Update {
|
Self::Update {
|
||||||
city: address.address.as_ref().and_then(|a| a.city.clone()),
|
city: address.address.as_ref().and_then(|a| a.city.clone()),
|
||||||
country: address.address.as_ref().and_then(|a| a.country.clone()),
|
country: address.address.as_ref().and_then(|a| a.country.clone()),
|
||||||
line1: address.address.as_ref().and_then(|a| a.line1.clone()),
|
line1: address.address.as_ref().and_then(|a| a.line1.clone()),
|
||||||
@ -323,35 +268,32 @@ impl<'a> From<F<&'a api_types::Address>> for F<storage::AddressUpdate> {
|
|||||||
phone_number: address.phone.as_ref().and_then(|a| a.number.clone()),
|
phone_number: address.phone.as_ref().and_then(|a| a.number.clone()),
|
||||||
country_code: address.phone.as_ref().and_then(|a| a.country_code.clone()),
|
country_code: address.phone.as_ref().and_then(|a| a.country_code.clone()),
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage::Config>> for F<api_types::Config> {
|
impl ForeignFrom<storage::Config> for api_types::Config {
|
||||||
fn from(config: F<storage::Config>) -> Self {
|
fn foreign_from(config: storage::Config) -> Self {
|
||||||
let config = config.0;
|
let config = config;
|
||||||
api_types::Config {
|
Self {
|
||||||
key: config.key,
|
key: config.key,
|
||||||
value: config.config,
|
value: config.config,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<F<&'a api_types::ConfigUpdate>> for F<storage::ConfigUpdate> {
|
impl<'a> ForeignFrom<&'a api_types::ConfigUpdate> for storage::ConfigUpdate {
|
||||||
fn from(config: F<&api_types::ConfigUpdate>) -> Self {
|
fn foreign_from(config: &api_types::ConfigUpdate) -> Self {
|
||||||
let config_update = config.0;
|
let config_update = config;
|
||||||
storage::ConfigUpdate::Update {
|
Self::Update {
|
||||||
config: Some(config_update.value.clone()),
|
config: Some(config_update.value.clone()),
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<F<&'a storage::Address>> for F<api_types::Address> {
|
impl<'a> ForeignFrom<&'a storage::Address> for api_types::Address {
|
||||||
fn from(address: F<&storage::Address>) -> Self {
|
fn foreign_from(address: &storage::Address) -> Self {
|
||||||
let address = address.0;
|
let address = address;
|
||||||
api_types::Address {
|
Self {
|
||||||
address: Some(api_types::AddressDetails {
|
address: Some(api_types::AddressDetails {
|
||||||
city: address.city.clone(),
|
city: address.city.clone(),
|
||||||
country: address.country.clone(),
|
country: address.country.clone(),
|
||||||
@ -368,16 +310,15 @@ impl<'a> From<F<&'a storage::Address>> for F<api_types::Address> {
|
|||||||
country_code: address.country_code.clone(),
|
country_code: address.country_code.clone(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<F<storage::MerchantConnectorAccount>>
|
impl ForeignTryFrom<storage::MerchantConnectorAccount>
|
||||||
for F<api_models::admin::PaymentConnectorCreate>
|
for api_models::admin::PaymentConnectorCreate
|
||||||
{
|
{
|
||||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||||
fn try_from(item: F<storage::MerchantConnectorAccount>) -> Result<Self, Self::Error> {
|
fn foreign_try_from(item: storage::MerchantConnectorAccount) -> Result<Self, Self::Error> {
|
||||||
let merchant_ca = item.0;
|
let merchant_ca = item;
|
||||||
|
|
||||||
let payment_methods_enabled = match merchant_ca.payment_methods_enabled {
|
let payment_methods_enabled = match merchant_ca.payment_methods_enabled {
|
||||||
Some(val) => serde_json::Value::Array(val)
|
Some(val) => serde_json::Value::Array(val)
|
||||||
@ -386,7 +327,7 @@ impl TryFrom<F<storage::MerchantConnectorAccount>>
|
|||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(api_models::admin::PaymentConnectorCreate {
|
Ok(Self {
|
||||||
connector_type: merchant_ca.connector_type.foreign_into(),
|
connector_type: merchant_ca.connector_type.foreign_into(),
|
||||||
connector_name: merchant_ca.connector_name,
|
connector_name: merchant_ca.connector_name,
|
||||||
merchant_connector_id: Some(merchant_ca.merchant_connector_id),
|
merchant_connector_id: Some(merchant_ca.merchant_connector_id),
|
||||||
@ -397,27 +338,30 @@ impl TryFrom<F<storage::MerchantConnectorAccount>>
|
|||||||
disabled: merchant_ca.disabled,
|
disabled: merchant_ca.disabled,
|
||||||
metadata: merchant_ca.metadata,
|
metadata: merchant_ca.metadata,
|
||||||
payment_methods_enabled,
|
payment_methods_enabled,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_models::enums::PaymentMethodType>> for F<storage_models::enums::PaymentMethodType> {
|
impl ForeignFrom<api_models::enums::PaymentMethodType>
|
||||||
fn from(payment_method_type: F<api_models::enums::PaymentMethodType>) -> Self {
|
for storage_models::enums::PaymentMethodType
|
||||||
Self(frunk::labelled_convert_from(payment_method_type.0))
|
{
|
||||||
|
fn foreign_from(payment_method_type: api_models::enums::PaymentMethodType) -> Self {
|
||||||
|
frunk::labelled_convert_from(payment_method_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_models::enums::PaymentMethodType>> for F<api_models::enums::PaymentMethodType> {
|
impl ForeignFrom<storage_models::enums::PaymentMethodType>
|
||||||
fn from(payment_method_type: F<storage_models::enums::PaymentMethodType>) -> Self {
|
for api_models::enums::PaymentMethodType
|
||||||
Self(frunk::labelled_convert_from(payment_method_type.0))
|
{
|
||||||
|
fn foreign_from(payment_method_type: storage_models::enums::PaymentMethodType) -> Self {
|
||||||
|
frunk::labelled_convert_from(payment_method_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_models::payments::AddressDetails>> for F<storage_models::address::AddressNew> {
|
impl ForeignFrom<api_models::payments::AddressDetails> for storage_models::address::AddressNew {
|
||||||
fn from(item: F<api_models::payments::AddressDetails>) -> Self {
|
fn foreign_from(item: api_models::payments::AddressDetails) -> Self {
|
||||||
let address = item.0;
|
let address = item;
|
||||||
storage_models::address::AddressNew {
|
Self {
|
||||||
city: address.city,
|
city: address.city,
|
||||||
country: address.country,
|
country: address.country,
|
||||||
line1: address.line1,
|
line1: address.line1,
|
||||||
@ -429,28 +373,25 @@ impl From<F<api_models::payments::AddressDetails>> for F<storage_models::address
|
|||||||
last_name: address.last_name,
|
last_name: address.last_name,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl
|
impl
|
||||||
From<
|
ForeignFrom<(
|
||||||
F<(
|
storage_models::api_keys::ApiKey,
|
||||||
storage_models::api_keys::ApiKey,
|
crate::core::api_keys::PlaintextApiKey,
|
||||||
crate::core::api_keys::PlaintextApiKey,
|
)> for api_models::api_keys::CreateApiKeyResponse
|
||||||
)>,
|
|
||||||
> for F<api_models::api_keys::CreateApiKeyResponse>
|
|
||||||
{
|
{
|
||||||
fn from(
|
fn foreign_from(
|
||||||
item: F<(
|
item: (
|
||||||
storage_models::api_keys::ApiKey,
|
storage_models::api_keys::ApiKey,
|
||||||
crate::core::api_keys::PlaintextApiKey,
|
crate::core::api_keys::PlaintextApiKey,
|
||||||
)>,
|
),
|
||||||
) -> Self {
|
) -> Self {
|
||||||
use masking::StrongSecret;
|
use masking::StrongSecret;
|
||||||
|
|
||||||
let (api_key, plaintext_api_key) = item.0;
|
let (api_key, plaintext_api_key) = item;
|
||||||
api_models::api_keys::CreateApiKeyResponse {
|
Self {
|
||||||
key_id: api_key.key_id.clone(),
|
key_id: api_key.key_id.clone(),
|
||||||
merchant_id: api_key.merchant_id,
|
merchant_id: api_key.merchant_id,
|
||||||
name: api_key.name,
|
name: api_key.name,
|
||||||
@ -463,14 +404,15 @@ impl
|
|||||||
created: api_key.created_at,
|
created: api_key.created_at,
|
||||||
expiration: api_key.expires_at.into(),
|
expiration: api_key.expires_at.into(),
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_models::api_keys::ApiKey>> for F<api_models::api_keys::RetrieveApiKeyResponse> {
|
impl ForeignFrom<storage_models::api_keys::ApiKey>
|
||||||
fn from(item: F<storage_models::api_keys::ApiKey>) -> Self {
|
for api_models::api_keys::RetrieveApiKeyResponse
|
||||||
let api_key = item.0;
|
{
|
||||||
api_models::api_keys::RetrieveApiKeyResponse {
|
fn foreign_from(item: storage_models::api_keys::ApiKey) -> Self {
|
||||||
|
let api_key = item;
|
||||||
|
Self {
|
||||||
key_id: api_key.key_id.clone(),
|
key_id: api_key.key_id.clone(),
|
||||||
merchant_id: api_key.merchant_id,
|
merchant_id: api_key.merchant_id,
|
||||||
name: api_key.name,
|
name: api_key.name,
|
||||||
@ -479,27 +421,25 @@ impl From<F<storage_models::api_keys::ApiKey>> for F<api_models::api_keys::Retri
|
|||||||
created: api_key.created_at,
|
created: api_key.created_at,
|
||||||
expiration: api_key.expires_at.into(),
|
expiration: api_key.expires_at.into(),
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<api_models::api_keys::UpdateApiKeyRequest>>
|
impl ForeignFrom<api_models::api_keys::UpdateApiKeyRequest>
|
||||||
for F<storage_models::api_keys::ApiKeyUpdate>
|
for storage_models::api_keys::ApiKeyUpdate
|
||||||
{
|
{
|
||||||
fn from(item: F<api_models::api_keys::UpdateApiKeyRequest>) -> Self {
|
fn foreign_from(item: api_models::api_keys::UpdateApiKeyRequest) -> Self {
|
||||||
let api_key = item.0;
|
let api_key = item;
|
||||||
storage_models::api_keys::ApiKeyUpdate::Update {
|
Self::Update {
|
||||||
name: api_key.name,
|
name: api_key.name,
|
||||||
description: api_key.description,
|
description: api_key.description,
|
||||||
expires_at: api_key.expiration.map(Into::into),
|
expires_at: api_key.expiration.map(Into::into),
|
||||||
last_used: None,
|
last_used: None,
|
||||||
}
|
}
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<F<storage_enums::AttemptStatus>> for F<api_enums::AttemptStatus> {
|
impl ForeignFrom<storage_enums::AttemptStatus> for api_enums::AttemptStatus {
|
||||||
fn from(status: F<storage_enums::AttemptStatus>) -> Self {
|
fn foreign_from(status: storage_enums::AttemptStatus) -> Self {
|
||||||
Self(frunk::labelled_convert_from(status.0))
|
frunk::labelled_convert_from(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user