Skip to content

Commit

Permalink
feat(connector): [BANKOFAMERICA] Resolve PR Comments Part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshu-iiitu committed Nov 8, 2023
1 parent cd98423 commit 80548e6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 53 deletions.
20 changes: 7 additions & 13 deletions crates/router/src/connector/bankofamerica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,8 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
.get_connector_transaction_id()
.change_context(errors::ConnectorError::MissingConnectorTransactionID)?;
Ok(format!(
"{}tss/v2/transactions/{}",
self.base_url(connectors),
connector_payment_id
"{}tss/v2/transactions/{connector_payment_id}",
self.base_url(connectors)
))
}

Expand Down Expand Up @@ -425,16 +424,11 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
.response
.parse_struct("BankOfAmerica PaymentSyncResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
let is_auto_capture =
data.request.capture_method == Some(diesel_models::enums::CaptureMethod::Automatic);
types::RouterData::try_from((
types::ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
},
is_auto_capture,
))
types::RouterData::try_from(types::ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
})
}

fn get_error_response(
Expand Down
72 changes: 32 additions & 40 deletions crates/router/src/connector/bankofamerica/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ use serde::{Deserialize, Serialize};

use crate::{
connector::utils::{
self, AddressDetailsData, CardData, CardIssuer, PaymentsAuthorizeRequestData, RouterData,
self, AddressDetailsData, CardData, CardIssuer, PaymentsAuthorizeRequestData,
PaymentsSyncRequestData, RouterData,
},
consts,
core::errors,
types::{
self,
api::{self, enums as api_enums},
storage::enums,
transformers::ForeignFrom,
},
};

Expand Down Expand Up @@ -269,9 +271,9 @@ pub enum BankofamericaPaymentStatus {
Transmitted,
}

impl From<BankofamericaPaymentStatus> for enums::AttemptStatus {
fn from(item: BankofamericaPaymentStatus) -> Self {
match item {
impl ForeignFrom<(BankofamericaPaymentStatus, bool)> for enums::AttemptStatus {
fn foreign_from(item: (BankofamericaPaymentStatus, bool)) -> Self {
let status = match item.0 {
BankofamericaPaymentStatus::Authorized
| BankofamericaPaymentStatus::AuthorizedPendingReview => Self::Authorized,
BankofamericaPaymentStatus::Succeeded | BankofamericaPaymentStatus::Transmitted => {
Expand All @@ -284,7 +286,11 @@ impl From<BankofamericaPaymentStatus> for enums::AttemptStatus {
Self::Failure
}
BankofamericaPaymentStatus::Pending => Self::Pending,
};
if item.1 && status == Self::Authorized {
return enums::AttemptStatus::Pending;
}
status
}
}

Expand All @@ -302,14 +308,6 @@ pub struct BankofamericaErrorInformation {
message: String,
}

fn get_payment_status(is_capture: bool, status: enums::AttemptStatus) -> enums::AttemptStatus {
let is_authorized = matches!(status, enums::AttemptStatus::Authorized);
if is_capture && is_authorized {
return enums::AttemptStatus::Pending;
}
status
}

impl<F>
TryFrom<
types::ResponseRouterData<
Expand All @@ -330,10 +328,10 @@ impl<F>
>,
) -> Result<Self, Self::Error> {
Ok(Self {
status: get_payment_status(
status: enums::AttemptStatus::foreign_from((
item.response.status,
item.data.request.is_auto_capture()?,
item.response.status.into(),
),
)),
response: match item.response.error_information {
Some(error) => Err(types::ErrorResponse {
code: consts::NO_ERROR_CODE.to_string(),
Expand Down Expand Up @@ -382,7 +380,7 @@ impl<F>
>,
) -> Result<Self, Self::Error> {
Ok(Self {
status: get_payment_status(true, item.response.status.into()),
status: enums::AttemptStatus::foreign_from((item.response.status, true)),
response: match item.response.error_information {
Some(error) => Err(types::ErrorResponse {
code: consts::NO_ERROR_CODE.to_string(),
Expand Down Expand Up @@ -431,7 +429,7 @@ impl<F>
>,
) -> Result<Self, Self::Error> {
Ok(Self {
status: item.response.status.into(),
status: enums::AttemptStatus::foreign_from((item.response.status, false)),
response: match item.response.error_information {
Some(error) => Err(types::ErrorResponse {
code: consts::NO_ERROR_CODE.to_string(),
Expand Down Expand Up @@ -474,36 +472,30 @@ pub struct ApplicationInformation {
status: BankofamericaPaymentStatus,
}

impl<F, T>
TryFrom<(
impl<F>
TryFrom<
types::ResponseRouterData<
F,
BankofamericaTransactionResponse,
T,
types::PaymentsSyncData,
types::PaymentsResponseData,
>,
bool,
)> for types::RouterData<F, T, types::PaymentsResponseData>
> for types::RouterData<F, types::PaymentsSyncData, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
data: (
types::ResponseRouterData<
F,
BankofamericaTransactionResponse,
T,
types::PaymentsResponseData,
>,
bool,
),
item: types::ResponseRouterData<
F,
BankofamericaTransactionResponse,
types::PaymentsSyncData,
types::PaymentsResponseData,
>,
) -> Result<Self, Self::Error> {
let item = data.0;
let is_capture = data.1;
Ok(Self {
status: get_payment_status(
is_capture,
item.response.application_information.status.into(),
),
status: enums::AttemptStatus::foreign_from((
item.response.application_information.status,
item.data.request.is_auto_capture()?,
)),
response: Ok(types::PaymentsResponseData::TransactionResponse {
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id.clone()),
redirection_data: None,
Expand Down Expand Up @@ -588,7 +580,7 @@ impl<F> TryFrom<&BankofamericaRouterData<&types::RefundsRouterData<F>>>
Ok(Self {
order_information: OrderInformation {
amount_details: Amount {
total_amount: item.router_data.request.refund_amount.to_string(),
total_amount: item.amount.clone(),
currency: item.router_data.request.currency.to_string(),
},
},
Expand All @@ -605,8 +597,8 @@ impl From<BankofamericaPaymentStatus> for enums::RefundStatus {
BankofamericaPaymentStatus::Succeeded | BankofamericaPaymentStatus::Transmitted => {
Self::Success
}
BankofamericaPaymentStatus::Failed
| BankofamericaPaymentStatus::Authorized
BankofamericaPaymentStatus::Failed => Self::Failure,
BankofamericaPaymentStatus::Authorized
| BankofamericaPaymentStatus::Voided
| BankofamericaPaymentStatus::Reversed
| BankofamericaPaymentStatus::Pending
Expand Down

0 comments on commit 80548e6

Please sign in to comment.