Skip to content

Commit

Permalink
comments resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranKBR committed May 21, 2024
1 parent 5bced6f commit 3f722ef
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 72 deletions.
41 changes: 18 additions & 23 deletions crates/router/src/connector/payone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use router_env::{instrument, tracing};
use self::transformers as payone;
#[cfg(feature = "payouts")]
use crate::services;
#[cfg(feature = "payouts")]
use crate::utils::get_current_date_time_in_rfc1123_format;
use crate::{
configs::settings,
consts,
Expand All @@ -31,8 +33,6 @@ use crate::{
},
utils::BytesExt,
};
#[cfg(feature = "payouts")]
use crate::utils::get_current_date_time_in_rfc1123_format;
#[derive(Debug, Clone)]
pub struct Payone;

Expand Down Expand Up @@ -167,19 +167,17 @@ impl ConnectorCommon for Payone {
router_env::logger::info!(connector_response=?response);

match response.errors {
Some(errors) =>
{
Some(errors) => {
let first_error = errors.first();
let code = first_error.map(|error| error.code.clone());
let code = first_error.map(|error| error.code.clone());
Ok(ErrorResponse {
status_code:res.status_code,
status_code: res.status_code,
code: code.unwrap_or_else(|| consts::NO_ERROR_CODE.to_string()),
message:
errors
.iter()
.map(|error| format!("{} : {}", error.code, error.message))
.collect::<Vec<_>>()
.join(", "),
message: errors
.iter()
.map(|error| format!("{} : {}", error.code, error.message))
.collect::<Vec<_>>()
.join(", "),
reason: Some(
errors
.iter()
Expand All @@ -190,20 +188,17 @@ impl ConnectorCommon for Payone {
attempt_status: None,
connector_transaction_id: None,
})
},
None => {
Ok(ErrorResponse {
status_code:res.status_code,
code: consts::NO_ERROR_CODE.to_string(),
message: consts::NO_ERROR_MESSAGE.to_string(),
reason: None,
attempt_status: None,
connector_transaction_id: None,
}
)
None => Ok(ErrorResponse {
status_code: res.status_code,
code: consts::NO_ERROR_CODE.to_string(),
message: consts::NO_ERROR_MESSAGE.to_string(),
reason: None,
attempt_status: None,
connector_transaction_id: None,
}),
}
}
}
}
impl ConnectorValidation for Payone {}

Expand Down
91 changes: 43 additions & 48 deletions crates/router/src/connector/payone/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use cards::CardNumber;
use error_stack::ResultExt;
use masking::Secret;
use serde::{Deserialize, Serialize};
// #[cfg(feature = "payouts")]
use serde_repr::{Serialize_repr, Deserialize_repr};
use serde_repr::{Deserialize_repr, Serialize_repr};

use crate::connector::utils::{get_unimplemented_payment_method_error_message, CardIssuer};

Expand All @@ -16,27 +15,23 @@ type Error = error_stack::Report<errors::ConnectorError>;

#[cfg(feature = "payouts")]
use crate::{
connector::utils::{ CardData, RouterData},
connector::utils::{CardData, RouterData},
core::errors,
types::{self, api, storage::enums as storage_enums, transformers::ForeignFrom},
utils::OptionExt,
};
#[cfg(not(feature = "payouts"))]
use crate::{core::errors, types::{self,api,storage::enums as storage_enums}};
use crate::{
core::errors,
types::{self, api, storage::enums as storage_enums},
};

pub struct PayoneRouterData<T> {
pub amount:i64,
pub amount: i64,
pub router_data: T,
}

impl<T>
TryFrom<(
&api::CurrencyUnit,
storage_enums::Currency,
i64,
T,
)> for PayoneRouterData<T>
{
impl<T> TryFrom<(&api::CurrencyUnit, storage_enums::Currency, i64, T)> for PayoneRouterData<T> {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
(_currency_unit, _currency, amount, item): (
Expand Down Expand Up @@ -125,13 +120,6 @@ pub struct Card {
expiry_date: Secret<String>,
}

#[cfg(feature = "payouts")]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmnichannelPayoutSpecificInput {
payment_id: String,
}

#[cfg(feature = "payouts")]
impl TryFrom<PayoneRouterData<&types::PayoutsRouterData<api::PoFulfill>>>
for PayonePayoutFulfillRequest
Expand All @@ -147,27 +135,34 @@ impl TryFrom<PayoneRouterData<&types::PayoutsRouterData<api::PoFulfill>>>
amount: item.amount,
currency_code: item.router_data.request.destination_currency.to_string(),
};
let card_payout_method_specific_input = match item.router_data.get_payout_method_data()?{
PayoutMethodData::Card(card_data) => {
CardPayoutMethodSpecificInput{
card: Card {
card_number: card_data.card_number.clone(),
card_holder_name: card_data
.card_holder_name
.clone()
.get_required_value("card_holder_name")
.change_context(errors::ConnectorError::MissingRequiredField {
field_name: "payout_method_data.card.holder_name",
})?,
expiry_date: card_data.get_card_expiry_month_year_2_digit_with_delimiter("".to_string())?,
},
payment_product_id: PaymentProductId::try_from(card_data.get_card_issuer()?)? ,
}
let card_payout_method_specific_input = match item
.router_data
.get_payout_method_data()?
{
PayoutMethodData::Card(card_data) => CardPayoutMethodSpecificInput {
card: Card {
card_number: card_data.card_number.clone(),
card_holder_name: card_data
.card_holder_name
.clone()
.get_required_value("card_holder_name")
.change_context(errors::ConnectorError::MissingRequiredField {
field_name: "payout_method_data.card.holder_name",
})?,
expiry_date: card_data
.get_card_expiry_month_year_2_digit_with_delimiter(
"".to_string(),
)?,
},
payment_product_id: PaymentProductId::try_from(
card_data.get_card_issuer()?,
)?,
},
PayoutMethodData::Bank(_) |
PayoutMethodData::Wallet(_) => Err(errors::ConnectorError::NotImplemented(
get_unimplemented_payment_method_error_message("Payout"),
))?
PayoutMethodData::Bank(_) | PayoutMethodData::Wallet(_) => {
Err(errors::ConnectorError::NotImplemented(
get_unimplemented_payment_method_error_message("Payout"),
))?
}
};
Ok(Self {
amount_of_money,
Expand All @@ -185,7 +180,7 @@ impl TryFrom<PayoneRouterData<&types::PayoutsRouterData<api::PoFulfill>>>
#[repr(i32)]
pub enum PaymentProductId {
Visa = 1,
MasterCard =3,
MasterCard = 3,
}

impl TryFrom<CardIssuer> for PaymentProductId {
Expand All @@ -194,12 +189,12 @@ impl TryFrom<CardIssuer> for PaymentProductId {
match issuer {
CardIssuer::Master => Ok(Self::MasterCard),
CardIssuer::Visa => Ok(Self::Visa),
CardIssuer::AmericanExpress |
CardIssuer::Maestro |
CardIssuer::Discover |
CardIssuer::DinersClub |
CardIssuer::JCB|
CardIssuer::CarteBlanche => Err(errors::ConnectorError::NotImplemented(
CardIssuer::AmericanExpress
| CardIssuer::Maestro
| CardIssuer::Discover
| CardIssuer::DinersClub
| CardIssuer::JCB
| CardIssuer::CarteBlanche => Err(errors::ConnectorError::NotImplemented(
get_unimplemented_payment_method_error_message("payone"),
)
.into()),
Expand Down Expand Up @@ -243,7 +238,7 @@ impl ForeignFrom<PayoneStatus> for storage_enums::PayoutStatus {
fn foreign_from(payone_status: PayoneStatus) -> Self {
match payone_status {
PayoneStatus::AccountCredited => Self::Success,
PayoneStatus::RejectedCredit | PayoneStatus::Rejected |
PayoneStatus::RejectedCredit | PayoneStatus::Rejected => Self::Failed,
PayoneStatus::Cancelled | PayoneStatus::Reversed => Self::Cancelled,
PayoneStatus::Created
| PayoneStatus::PendingApproval
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use nanoid::nanoid;
use qrcode;
use serde::de::DeserializeOwned;
use serde_json::Value;
use time::{format_description, OffsetDateTime};
use tracing_futures::Instrument;
use uuid::Uuid;

Expand All @@ -56,7 +57,6 @@ use crate::{
transformers::ForeignFrom,
},
};
use time::{format_description, OffsetDateTime};

pub mod error_parser {
use std::fmt::Display;
Expand Down

0 comments on commit 3f722ef

Please sign in to comment.