Skip to content

Commit

Permalink
refactor: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakilmostak committed Oct 19, 2023
1 parent 4492b5b commit 46e9dc8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 48 deletions.
6 changes: 6 additions & 0 deletions crates/common_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ pub const SURCHARGE_PERCENTAGE_PRECISION_LENGTH: u8 = 2;

/// Header Key for application overhead of a request
pub const X_HS_LATENCY: &str = "x-hs-latency";

/// Redirect url for Prophetpay
pub const PROPHETPAY_REDIRECT_URL: &str = "https://ccm-thirdparty.cps.golf/hp/tokenize/";

/// Variable which store the card token for Prophetpay
pub const PROPHETPAY_TOKEN: &str = "cctoken";
111 changes: 63 additions & 48 deletions crates/router/src/connector/prophetpay/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use common_utils::errors::CustomResult;
use common_utils::{consts, errors::CustomResult};
use error_stack::{IntoReport, ResultExt};
use masking::{PeekInterface, Secret};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -83,13 +83,14 @@ pub enum ProphetpayEntryMethod {
CardSwipe,
}

fn get_entry_method(method: ProphetpayEntryMethod) -> i8 {
match method {
ProphetpayEntryMethod::ManualEntry => 1,
ProphetpayEntryMethod::CardSwipe => 2,
impl ProphetpayEntryMethod {
fn get_entry_method(&self) -> i8 {
match self {
Self::ManualEntry => 1,
Self::CardSwipe => 2,
}
}
}

#[derive(Debug, Clone)]
#[repr(i8)]
pub enum ProphetpayTokenType {
Expand All @@ -98,11 +99,13 @@ pub enum ProphetpayTokenType {
TemporarySave,
}

fn get_token_type(token_type: ProphetpayTokenType) -> i8 {
match token_type {
ProphetpayTokenType::Normal => 0,
ProphetpayTokenType::SaleTab => 1,
ProphetpayTokenType::TemporarySave => 2,
impl ProphetpayTokenType {
fn get_token_type(&self) -> i8 {
match self {
Self::Normal => 0,
Self::SaleTab => 1,
Self::TemporarySave => 2,
}
}
}

Expand All @@ -113,10 +116,12 @@ pub enum ProphetpayCardContext {
WebConsumerInitiated,
}

fn get_card_context(context: ProphetpayCardContext) -> i8 {
match context {
ProphetpayCardContext::NotApplicable => 0,
ProphetpayCardContext::WebConsumerInitiated => 5,
impl ProphetpayCardContext {
fn get_card_context(&self) -> i8 {
match self {
Self::NotApplicable => 0,
Self::WebConsumerInitiated => 5,
}
}
}

Expand All @@ -127,23 +132,33 @@ impl TryFrom<&ProphetpayRouterData<&types::PaymentsAuthorizeRouterData>>
fn try_from(
item: &ProphetpayRouterData<&types::PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
match item.router_data.request.payment_method_data.clone() {
api::PaymentMethodData::CardRedirect(
api_models::payments::CardRedirectData::CardRedirect {},
) => {
let auth_data =
ProphetpayAuthType::try_from(&item.router_data.connector_auth_type)?;
Ok(Self {
ref_info: item.router_data.connector_request_reference_id.to_owned(),
profile: auth_data.profile_id,
entry_method: get_entry_method(ProphetpayEntryMethod::ManualEntry),
token_type: get_token_type(ProphetpayTokenType::SaleTab),
card_entry_context: get_card_context(
ProphetpayCardContext::WebConsumerInitiated,
),
})
if item.router_data.request.currency == api_models::enums::Currency::USD {
match item.router_data.request.payment_method_data.clone() {
api::PaymentMethodData::CardRedirect(
api_models::payments::CardRedirectData::CardRedirect {},
) => {
let auth_data =
ProphetpayAuthType::try_from(&item.router_data.connector_auth_type)?;
Ok(Self {
ref_info: item.router_data.connector_request_reference_id.to_owned(),
profile: auth_data.profile_id,
entry_method: ProphetpayEntryMethod::get_entry_method(
&ProphetpayEntryMethod::ManualEntry,
),
token_type: ProphetpayTokenType::get_token_type(
&ProphetpayTokenType::SaleTab,
),
card_entry_context: ProphetpayCardContext::get_card_context(
&ProphetpayCardContext::WebConsumerInitiated,
),
})
}
_ => Err(
errors::ConnectorError::NotImplemented("Payment methods".to_string()).into(),
),
}
_ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()),
} else {
Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into())
}
}
}
Expand Down Expand Up @@ -174,7 +189,8 @@ impl<F>
>,
) -> Result<Self, Self::Error> {
let url_data = format!(
"https://ccm-thirdparty.cps.golf/hp/tokenize/{}",
"{}{}",
consts::PROPHETPAY_REDIRECT_URL,
item.response.hosted_tokenize_id
);

Expand Down Expand Up @@ -207,11 +223,7 @@ fn get_redirect_url_form(
mut redirect_url: Url,
complete_auth_url: Option<String>,
) -> CustomResult<services::RedirectForm, errors::ConnectorError> {
let mut form_fields = std::collections::HashMap::from_iter(
redirect_url
.query_pairs()
.map(|(key, value)| (key.to_string(), value.to_string())),
);
let mut form_fields = std::collections::HashMap::<String, String>::new();

form_fields.insert(
String::from("redirectUrl"),
Expand Down Expand Up @@ -253,7 +265,7 @@ impl TryFrom<&ProphetpayRouterData<&types::PaymentsCompleteAuthorizeRouterData>>
amount: item.amount.to_owned(),
ref_info: item.router_data.connector_request_reference_id.to_owned(),
profile: auth_data.profile_id,
action_type: get_action_type(ProphetpayActionType::Charge),
action_type: ProphetpayActionType::get_action_type(&ProphetpayActionType::Charge),
card_token,
})
}
Expand All @@ -279,7 +291,7 @@ fn get_card_token(
.ok_or(errors::ConnectorError::ResponseDeserializationFailed)?;

for (key, val) in queries_params {
if key.as_str() == "cctoken" {
if key.as_str() == consts::PROPHETPAY_TOKEN {
return Ok(val);
}
}
Expand All @@ -305,11 +317,13 @@ pub enum ProphetpayActionType {
Inquiry,
}

fn get_action_type(action: ProphetpayActionType) -> i8 {
match action {
ProphetpayActionType::Charge => 1,
ProphetpayActionType::Refund => 3,
ProphetpayActionType::Inquiry => 7,
impl ProphetpayActionType {
fn get_action_type(&self) -> i8 {
match self {
Self::Charge => 1,
Self::Refund => 3,
Self::Inquiry => 7,
}
}
}

Expand All @@ -320,7 +334,7 @@ impl TryFrom<&types::PaymentsSyncRouterData> for ProphetpaySyncRequest {
Ok(Self {
ref_info: item.attempt_id.to_owned(),
profile: auth_data.profile_id,
action_type: get_action_type(ProphetpayActionType::Inquiry),
action_type: ProphetpayActionType::get_action_type(&ProphetpayActionType::Inquiry),
})
}
}
Expand Down Expand Up @@ -390,7 +404,7 @@ impl TryFrom<&types::PaymentsCancelRouterData> for ProphetpayVoidRequest {
transaction_id,
ref_info: item.attempt_id.to_owned(),
profile: auth_data.profile_id,
action_type: get_action_type(ProphetpayActionType::Inquiry),
action_type: ProphetpayActionType::get_action_type(&ProphetpayActionType::Inquiry),
})
}
}
Expand All @@ -414,7 +428,7 @@ impl<F> TryFrom<&ProphetpayRouterData<&types::RefundsRouterData<F>>> for Prophet
amount: item.amount.to_owned(),
profile: auth_data.profile_id,
ref_info: item.router_data.attempt_id.to_owned(),
action_type: get_action_type(ProphetpayActionType::Refund),
action_type: ProphetpayActionType::get_action_type(&ProphetpayActionType::Refund),
})
}
}
Expand Down Expand Up @@ -476,7 +490,7 @@ impl TryFrom<&types::RefundSyncRouterData> for ProphetpayRefundSyncRequest {
Ok(Self {
ref_info: item.attempt_id.to_owned(),
profile: auth_data.profile_id,
action_type: get_action_type(ProphetpayActionType::Inquiry),
action_type: ProphetpayActionType::get_action_type(&ProphetpayActionType::Inquiry),
})
}
}
Expand All @@ -498,6 +512,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, ProphetpayRefundRespon
}
}

// Error Response body is yet to be confirmed with the connector
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ProphetpayErrorResponse {
Expand Down

0 comments on commit 46e9dc8

Please sign in to comment.