Skip to content

Commit

Permalink
comments resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranKBR committed May 20, 2024
1 parent 1aa77fb commit 4707994
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 48 deletions.
16 changes: 4 additions & 12 deletions crates/router/src/connector/payone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use masking::{ExposeInterface, PeekInterface};
use ring::hmac;
#[cfg(feature = "payouts")]
use router_env::{instrument, tracing};
use time::{format_description, OffsetDateTime};

use self::transformers as payone;
#[cfg(feature = "payouts")]
Expand All @@ -32,7 +31,8 @@ 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 @@ -64,15 +64,7 @@ impl Payone {
Ok(signature_header)
}
}
pub fn get_current_date_time() -> CustomResult<String, errors::ConnectorError> {
let format = format_description::parse(
"[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second] GMT",
)
.change_context(errors::ConnectorError::InvalidDateFormat)?;
OffsetDateTime::now_utc()
.format(&format)
.change_context(errors::ConnectorError::InvalidDateFormat)
}

impl api::Payment for Payone {}
impl api::PaymentSession for Payone {}
impl api::ConnectorAccessToken for Payone {}
Expand Down Expand Up @@ -110,7 +102,7 @@ where
let content_type = Self::get_content_type(self);
let base_url = self.base_url(connectors);
let url = Self::get_url(self, req, connectors)?;
let date_header = get_current_date_time()?;
let date_header = get_current_date_time_in_rfc1123_format()?;
let path: String = url.replace(base_url, "/");

let authorization_header: String = self.generate_signature(
Expand Down
28 changes: 9 additions & 19 deletions crates/router/src/connector/payone/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
use crate::{core::errors, types::{self,api,storage::enums as storage_enums}};

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

Expand Down Expand Up @@ -127,7 +127,7 @@ pub struct Card {
}

#[cfg(feature = "payouts")]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmnichannelPayoutSpecificInput {
payment_id: String,
Expand All @@ -147,13 +147,13 @@ impl TryFrom<PayoneRouterData<&types::PayoutsRouterData<api::PoFulfill>>>
match request.payout_type.to_owned() {
storage_enums::PayoutType::Card => {
let amount_of_money: AmountOfMoney = AmountOfMoney {
amount: item.router_data.request.amount,
amount: item.amount.parse::<i64>().change_context(errors::ConnectorError::ParsingFailed)?,
currency_code: item.router_data.request.destination_currency.to_string(),
};
let _card_issuer =
let card_issuer =
CardAndCardIssuer::try_from(&item.router_data.get_payout_method_data()?)?;
let card = _card_issuer.0;
let card_issuer = _card_issuer.1;
let card = card_issuer.0;
let card_issuer = card_issuer.1;

let card_payout_method_specific_input: CardPayoutMethodSpecificInput =
CardPayoutMethodSpecificInput {
Expand Down Expand Up @@ -208,7 +208,7 @@ impl TryFrom<&PayoutMethodData> for CardAndCardIssuer {
.change_context(errors::ConnectorError::MissingRequiredField {
field_name: "payout_method_data.card.holder_name",
})?,
expiry_date: match card.get_expiry_date_as_mmyy() {
expiry_date: match card.get_card_expiry_month_year_2_digit_with_delimiter("".to_string()) {
Ok(date) => date,
Err(_) => Err(errors::ConnectorError::MissingRequiredField {
field_name: "payout_method_data.card.expiry_date",
Expand All @@ -225,7 +225,7 @@ impl TryFrom<&PayoutMethodData> for CardAndCardIssuer {
}

#[cfg(feature = "payouts")]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PayoneStatus {
Created,
Expand All @@ -238,16 +238,7 @@ pub enum PayoneStatus {
Cancelled,
Reversed,
}
#[cfg(feature = "payouts")]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PayoneTransferDetails {
transfer_purpose: Option<String>,
source_of_funds: Option<String>,
transfer_purpose_sub_transfer_purpose: Option<String>,
}

#[allow(dead_code)]
#[cfg(feature = "payouts")]
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -257,7 +248,6 @@ pub struct PayonePayoutFulfillResponse {
status: PayoneStatus,
}

#[allow(dead_code)]
#[cfg(feature = "payouts")]
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -270,7 +260,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 => Self::Cancelled,
PayoneStatus::RejectedCredit | PayoneStatus::Rejected |
PayoneStatus::Cancelled | PayoneStatus::Reversed => Self::Cancelled,
PayoneStatus::Created
| PayoneStatus::PendingApproval
Expand Down
12 changes: 1 addition & 11 deletions crates/router/src/connector/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,6 @@ pub trait CardData {
fn get_expiry_date_as_mmyyyy(&self, delimiter: &str) -> Secret<String>;
fn get_expiry_year_4_digit(&self) -> Secret<String>;
fn get_expiry_date_as_yymm(&self) -> Result<Secret<String>, errors::ConnectorError>;
fn get_expiry_date_as_mmyy(&self) -> Result<Secret<String>, errors::ConnectorError>;
fn get_expiry_month_as_i8(&self) -> Result<Secret<i8>, Error>;
fn get_expiry_year_as_i32(&self) -> Result<Secret<i32>, Error>;
}
Expand Down Expand Up @@ -1152,11 +1151,7 @@ impl CardData for payouts::Card {
}
Secret::new(year)
}
fn get_expiry_date_as_mmyy(&self) -> Result<Secret<String>, errors::ConnectorError> {
let year = self.get_card_expiry_year_2_digit()?.expose();
let month = self.expiry_month.clone().expose();
Ok(Secret::new(format!("{month}{year}")))
}

fn get_expiry_date_as_yymm(&self) -> Result<Secret<String>, errors::ConnectorError> {
let year = self.get_card_expiry_year_2_digit()?.expose();
let month = self.expiry_month.clone().expose();
Expand Down Expand Up @@ -1235,11 +1230,6 @@ impl CardData for domain::Card {
let month = self.card_exp_month.clone().expose();
Ok(Secret::new(format!("{year}{month}")))
}
fn get_expiry_date_as_mmyy(&self) -> Result<Secret<String>, errors::ConnectorError> {
let year = self.get_card_expiry_year_2_digit()?.expose();
let month = self.card_exp_month.clone().expose();
Ok(Secret::new(format!("{month}{year}")))
}
fn get_expiry_month_as_i8(&self) -> Result<Secret<i8>, Error> {
self.card_exp_month
.peek()
Expand Down
8 changes: 4 additions & 4 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,10 +1793,6 @@ pub(crate) fn validate_auth_and_metadata_type(
use crate::connector::*;

match connector_name {
api_enums::Connector::Payone => {
payone::transformers::PayoneAuthType::try_from(val)?;
Ok(())
}
// api_enums::Connector::Mifinity => {
// mifinity::transformers::MifinityAuthType::try_from(val)?;
// Ok(())
Expand Down Expand Up @@ -1968,6 +1964,10 @@ pub(crate) fn validate_auth_and_metadata_type(
paypal::transformers::PaypalAuthType::try_from(val)?;
Ok(())
}
api_enums::Connector::Payone => {
payone::transformers::PayoneAuthType::try_from(val)?;
Ok(())
}
api_enums::Connector::Payu => {
payu::transformers::PayuAuthType::try_from(val)?;
Ok(())
Expand Down
11 changes: 10 additions & 1 deletion crates/router/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use crate::{
transformers::ForeignFrom,
},
};
use time::{format_description, OffsetDateTime};

pub mod error_parser {
use std::fmt::Display;
Expand Down Expand Up @@ -160,7 +161,15 @@ impl<E> ConnectorResponseExt
pub fn get_payment_attempt_id(payment_id: impl std::fmt::Display, attempt_count: i16) -> String {
format!("{payment_id}_{attempt_count}")
}

pub fn get_current_date_time_in_rfc1123_format() -> CustomResult<String, errors::ConnectorError> {
let format = format_description::parse(
"[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second] GMT",
)
.change_context(errors::ConnectorError::InvalidDateFormat)?;
OffsetDateTime::now_utc()
.format(&format)
.change_context(errors::ConnectorError::InvalidDateFormat)
}
#[derive(Debug)]
pub struct QrImage {
pub data: String,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/tests/connectors/payone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl utils::Connector for PayoneTest {
use router::connector::Payone;
types::api::ConnectorData {
connector: Box::new(&Payone),
connector_name: types::Connector::Adyen,
connector_name: types::Connector::Payone,
get_token: types::api::GetToken::Connector,
merchant_connector_id: None,
}
Expand Down

0 comments on commit 4707994

Please sign in to comment.