refactor: rename the payment request struct (#48)

This commit is contained in:
Narayan Bhat
2022-12-01 16:30:34 +05:30
committed by GitHub
parent 5a5ac61d01
commit 2a050cc340
29 changed files with 436 additions and 710 deletions

View File

@ -16,7 +16,7 @@ use crate::{
types::{
self, api,
storage::{self, enums},
PaymentsRequestData, PaymentsResponseData, PaymentsRouterData,
PaymentsAuthorizeData, PaymentsAuthorizeRouterData, PaymentsResponseData,
},
utils,
};
@ -25,7 +25,7 @@ use crate::{
impl
ConstructFlowSpecificData<
api::Authorize,
types::PaymentsRequestData,
types::PaymentsAuthorizeData,
types::PaymentsResponseData,
> for PaymentData<api::Authorize>
{
@ -35,11 +35,15 @@ impl
connector_id: &str,
merchant_account: &storage::MerchantAccount,
) -> RouterResult<
types::RouterData<api::Authorize, types::PaymentsRequestData, types::PaymentsResponseData>,
types::RouterData<
api::Authorize,
types::PaymentsAuthorizeData,
types::PaymentsResponseData,
>,
> {
let output = transformers::construct_payment_router_data::<
api::Authorize,
types::PaymentsRequestData,
types::PaymentsAuthorizeData,
>(state, self.clone(), connector_id, merchant_account)
.await?;
Ok(output.1)
@ -47,8 +51,8 @@ impl
}
#[async_trait]
impl Feature<api::Authorize, types::PaymentsRequestData>
for types::RouterData<api::Authorize, types::PaymentsRequestData, types::PaymentsResponseData>
impl Feature<api::Authorize, types::PaymentsAuthorizeData>
for types::RouterData<api::Authorize, types::PaymentsAuthorizeData, types::PaymentsResponseData>
{
async fn decide_flows<'a>(
self,
@ -61,7 +65,7 @@ impl Feature<api::Authorize, types::PaymentsRequestData>
where
dyn api::Connector: services::ConnectorIntegration<
api::Authorize,
types::PaymentsRequestData,
types::PaymentsAuthorizeData,
types::PaymentsResponseData,
>,
{
@ -81,7 +85,7 @@ impl Feature<api::Authorize, types::PaymentsRequestData>
}
}
impl PaymentsRouterData {
impl PaymentsAuthorizeRouterData {
pub async fn decide_flow<'a, 'b>(
&'b self,
state: &'a AppState,
@ -89,11 +93,11 @@ impl PaymentsRouterData {
maybe_customer: &Option<api::CustomerResponse>,
confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<PaymentsRouterData>
) -> RouterResult<PaymentsAuthorizeRouterData>
where
dyn api::Connector + Sync: services::ConnectorIntegration<
api::Authorize,
PaymentsRequestData,
PaymentsAuthorizeData,
PaymentsResponseData,
>,
{
@ -101,7 +105,7 @@ impl PaymentsRouterData {
Some(true) => {
let connector_integration: services::BoxedConnectorIntegration<
api::Authorize,
PaymentsRequestData,
PaymentsAuthorizeData,
PaymentsResponseData,
> = connector.connector.get_connector_integration();
let mut resp = services::execute_connector_processing_step(

View File

@ -8,26 +8,22 @@ use crate::{
},
routes::AppState,
services,
types::{self, api, storage, PaymentRouterCancelData, PaymentsResponseData},
types::{self, api, storage, PaymentsCancelRouterData, PaymentsResponseData},
};
#[async_trait]
impl
ConstructFlowSpecificData<
api::Void,
types::PaymentRequestCancelData,
types::PaymentsResponseData,
> for PaymentData<api::Void>
impl ConstructFlowSpecificData<api::Void, types::PaymentsCancelData, types::PaymentsResponseData>
for PaymentData<api::Void>
{
async fn construct_r_d<'a>(
&self,
state: &AppState,
connector_id: &str,
merchant_account: &storage::MerchantAccount,
) -> RouterResult<PaymentRouterCancelData> {
) -> RouterResult<PaymentsCancelRouterData> {
let output = transformers::construct_payment_router_data::<
api::Void,
types::PaymentRequestCancelData,
types::PaymentsCancelData,
>(state, self.clone(), connector_id, merchant_account)
.await?;
Ok(output.1)
@ -35,8 +31,8 @@ impl
}
#[async_trait]
impl Feature<api::Void, types::PaymentRequestCancelData>
for types::RouterData<api::Void, types::PaymentRequestCancelData, types::PaymentsResponseData>
impl Feature<api::Void, types::PaymentsCancelData>
for types::RouterData<api::Void, types::PaymentsCancelData, types::PaymentsResponseData>
{
async fn decide_flows<'a>(
self,
@ -49,7 +45,7 @@ impl Feature<api::Void, types::PaymentRequestCancelData>
where
dyn api::Connector: services::ConnectorIntegration<
api::Void,
types::PaymentRequestCancelData,
types::PaymentsCancelData,
types::PaymentsResponseData,
>,
{
@ -67,7 +63,7 @@ impl Feature<api::Void, types::PaymentRequestCancelData>
}
}
impl PaymentRouterCancelData {
impl PaymentsCancelRouterData {
#[allow(clippy::too_many_arguments)]
pub async fn decide_flow<'a, 'b>(
&'b self,
@ -76,18 +72,18 @@ impl PaymentRouterCancelData {
_maybe_customer: &Option<api::CustomerResponse>,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<PaymentRouterCancelData>
) -> RouterResult<PaymentsCancelRouterData>
where
// P: 'a,
dyn api::Connector + Sync: services::ConnectorIntegration<
api::Void,
types::PaymentRequestCancelData,
types::PaymentsCancelData,
PaymentsResponseData,
>,
{
let connector_integration: services::BoxedConnectorIntegration<
api::Void,
types::PaymentRequestCancelData,
types::PaymentsCancelData,
PaymentsResponseData,
> = connector.connector.get_connector_integration();
let resp = services::execute_connector_processing_step(

View File

@ -9,28 +9,24 @@ use crate::{
routes::AppState,
services,
types::{
self, api, storage, PaymentsRequestCaptureData, PaymentsResponseData,
PaymentsRouterCaptureData,
self, api, storage, PaymentsCaptureData, PaymentsCaptureRouterData, PaymentsResponseData,
},
};
#[async_trait]
impl
ConstructFlowSpecificData<
api::PCapture,
types::PaymentsRequestCaptureData,
types::PaymentsResponseData,
> for PaymentData<api::PCapture>
ConstructFlowSpecificData<api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData>
for PaymentData<api::Capture>
{
async fn construct_r_d<'a>(
&self,
state: &AppState,
connector_id: &str,
merchant_account: &storage::MerchantAccount,
) -> RouterResult<PaymentsRouterCaptureData> {
) -> RouterResult<PaymentsCaptureRouterData> {
let output = transformers::construct_payment_router_data::<
api::PCapture,
types::PaymentsRequestCaptureData,
api::Capture,
types::PaymentsCaptureData,
>(state, self.clone(), connector_id, merchant_account)
.await?;
Ok(output.1)
@ -38,25 +34,21 @@ impl
}
#[async_trait]
impl Feature<api::PCapture, types::PaymentsRequestCaptureData>
for types::RouterData<
api::PCapture,
types::PaymentsRequestCaptureData,
types::PaymentsResponseData,
>
impl Feature<api::Capture, types::PaymentsCaptureData>
for types::RouterData<api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData>
{
async fn decide_flows<'a>(
self,
state: &AppState,
connector: api::ConnectorData,
customer: &Option<api::CustomerResponse>,
payment_data: PaymentData<api::PCapture>,
payment_data: PaymentData<api::Capture>,
call_connector_action: payments::CallConnectorAction,
) -> (RouterResult<Self>, PaymentData<api::PCapture>)
) -> (RouterResult<Self>, PaymentData<api::Capture>)
where
dyn api::Connector: services::ConnectorIntegration<
api::PCapture,
types::PaymentsRequestCaptureData,
api::Capture,
types::PaymentsCaptureData,
types::PaymentsResponseData,
>,
{
@ -74,7 +66,7 @@ impl Feature<api::PCapture, types::PaymentsRequestCaptureData>
}
}
impl PaymentsRouterCaptureData {
impl PaymentsCaptureRouterData {
#[allow(clippy::too_many_arguments)]
pub async fn decide_flow<'a, 'b>(
&'b self,
@ -83,17 +75,14 @@ impl PaymentsRouterCaptureData {
_maybe_customer: &Option<api::CustomerResponse>,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<PaymentsRouterCaptureData>
) -> RouterResult<PaymentsCaptureRouterData>
where
dyn api::Connector + Sync: services::ConnectorIntegration<
api::PCapture,
PaymentsRequestCaptureData,
PaymentsResponseData,
>,
dyn api::Connector + Sync:
services::ConnectorIntegration<api::Capture, PaymentsCaptureData, PaymentsResponseData>,
{
let connector_integration: services::BoxedConnectorIntegration<
api::PCapture,
PaymentsRequestCaptureData,
api::Capture,
PaymentsCaptureData,
PaymentsResponseData,
> = connector.connector.get_connector_integration();
let resp = services::execute_connector_processing_step(

View File

@ -8,18 +8,12 @@ use crate::{
},
routes::AppState,
services,
types::{
self, api, storage, PaymentsRequestSyncData, PaymentsResponseData, PaymentsRouterSyncData,
},
types::{self, api, storage, PaymentsResponseData, PaymentsSyncData, PaymentsSyncRouterData},
};
#[async_trait]
impl
ConstructFlowSpecificData<
api::PSync,
types::PaymentsRequestSyncData,
types::PaymentsResponseData,
> for PaymentData<api::PSync>
impl ConstructFlowSpecificData<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>
for PaymentData<api::PSync>
{
async fn construct_r_d<'a>(
&self,
@ -27,11 +21,11 @@ impl
connector_id: &str,
merchant_account: &storage::MerchantAccount,
) -> RouterResult<
types::RouterData<api::PSync, types::PaymentsRequestSyncData, types::PaymentsResponseData>,
types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>,
> {
let output = transformers::construct_payment_router_data::<
api::PSync,
types::PaymentsRequestSyncData,
types::PaymentsSyncData,
>(state, self.clone(), connector_id, merchant_account)
.await?;
Ok(output.1)
@ -39,8 +33,8 @@ impl
}
#[async_trait]
impl Feature<api::PSync, types::PaymentsRequestSyncData>
for types::RouterData<api::PSync, types::PaymentsRequestSyncData, types::PaymentsResponseData>
impl Feature<api::PSync, types::PaymentsSyncData>
for types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>
{
async fn decide_flows<'a>(
self,
@ -53,7 +47,7 @@ impl Feature<api::PSync, types::PaymentsRequestSyncData>
where
dyn api::Connector: services::ConnectorIntegration<
api::PSync,
types::PaymentsRequestSyncData,
types::PaymentsSyncData,
types::PaymentsResponseData,
>,
{
@ -71,7 +65,7 @@ impl Feature<api::PSync, types::PaymentsRequestSyncData>
}
}
impl PaymentsRouterSyncData {
impl PaymentsSyncRouterData {
pub async fn decide_flow<'a, 'b>(
&'b self,
state: &'a AppState,
@ -79,17 +73,14 @@ impl PaymentsRouterSyncData {
_maybe_customer: &Option<api::CustomerResponse>,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<PaymentsRouterSyncData>
) -> RouterResult<PaymentsSyncRouterData>
where
dyn api::Connector + Sync: services::ConnectorIntegration<
api::PSync,
PaymentsRequestSyncData,
PaymentsResponseData,
>,
dyn api::Connector + Sync:
services::ConnectorIntegration<api::PSync, PaymentsSyncData, PaymentsResponseData>,
{
let connector_integration: services::BoxedConnectorIntegration<
api::PSync,
PaymentsRequestSyncData,
PaymentsSyncData,
PaymentsResponseData,
> = connector.connector.get_connector_integration();
let resp = services::execute_connector_processing_step(

View File

@ -25,7 +25,7 @@ use crate::{
pub struct PaymentResponse;
#[async_trait]
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestData>
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthorizeData>
for PaymentResponse
{
async fn update_tracker<'b>(
@ -34,7 +34,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestData>
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
response: Option<
types::RouterData<F, types::PaymentsRequestData, types::PaymentsResponseData>,
types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
>,
) -> RouterResult<PaymentData<F>>
where
@ -49,16 +49,14 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestData>
}
#[async_trait]
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestSyncData>
for PaymentResponse
{
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for PaymentResponse {
async fn update_tracker<'b>(
&'b self,
db: &dyn Db,
payment_id: &api::PaymentIdType,
payment_data: PaymentData<F>,
response: Option<
types::RouterData<F, types::PaymentsRequestSyncData, types::PaymentsResponseData>,
types::RouterData<F, types::PaymentsSyncData, types::PaymentsResponseData>,
>,
) -> RouterResult<PaymentData<F>>
where
@ -69,7 +67,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestSyncDa
}
#[async_trait]
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestCaptureData>
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCaptureData>
for PaymentResponse
{
async fn update_tracker<'b>(
@ -78,7 +76,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestCaptur
payment_id: &api::PaymentIdType,
payment_data: PaymentData<F>,
response: Option<
types::RouterData<F, types::PaymentsRequestCaptureData, types::PaymentsResponseData>,
types::RouterData<F, types::PaymentsCaptureData, types::PaymentsResponseData>,
>,
) -> RouterResult<PaymentData<F>>
where
@ -89,16 +87,14 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRequestCaptur
}
#[async_trait]
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentRequestCancelData>
for PaymentResponse
{
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCancelData> for PaymentResponse {
async fn update_tracker<'b>(
&'b self,
db: &dyn Db,
payment_id: &api::PaymentIdType,
payment_data: PaymentData<F>,
response: Option<
types::RouterData<F, types::PaymentRequestCancelData, types::PaymentsResponseData>,
types::RouterData<F, types::PaymentsCancelData, types::PaymentsResponseData>,
>,
) -> RouterResult<PaymentData<F>>
where

View File

@ -246,7 +246,7 @@ where
})
}
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestData {
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsAuthorizeData {
type Error = error_stack::Report<errors::ApiErrorResponse>;
fn try_from(payment_data: PaymentData<F>) -> Result<Self, Self::Error> {
@ -286,7 +286,7 @@ impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestData {
}
}
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestSyncData {
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsSyncData {
type Error = errors::ApiErrorResponse;
fn try_from(payment_data: PaymentData<F>) -> Result<Self, Self::Error> {
@ -300,7 +300,7 @@ impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestSyncData {
}
}
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestCaptureData {
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsCaptureData {
type Error = errors::ApiErrorResponse;
fn try_from(payment_data: PaymentData<F>) -> Result<Self, Self::Error> {
@ -314,7 +314,7 @@ impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestCaptureData {
}
}
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentRequestCancelData {
impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsCancelData {
type Error = errors::ApiErrorResponse;
fn try_from(payment_data: PaymentData<F>) -> Result<Self, Self::Error> {

View File

@ -117,7 +117,7 @@ pub async fn trigger_refund_to_gateway(
logger::debug!(?router_data);
let connector_integration: services::BoxedConnectorIntegration<
api::Execute,
types::RefundsRequestData,
types::RefundsData,
types::RefundsResponseData,
> = connector.connector.get_connector_integration();
let router_data = services::execute_connector_processing_step(
@ -226,7 +226,7 @@ pub async fn sync_refund_with_gateway(
let connector_integration: services::BoxedConnectorIntegration<
api::RSync,
types::RefundsRequestData,
types::RefundsData,
types::RefundsResponseData,
> = connector.connector.get_connector_integration();
let router_data = services::execute_connector_processing_step(

View File

@ -80,7 +80,7 @@ pub async fn construct_refund_router_data<'a, F>(
address: PaymentAddress::default(),
auth_type: payment_attempt.authentication_type.unwrap_or_default(),
request: types::RefundsRequestData {
request: types::RefundsData {
refund_id: refund.refund_id.clone(),
payment_method_data,
connector_transaction_id: refund.transaction_id.clone(),