Skip to content

Commit

Permalink
feat: add routing configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakilmostak committed Nov 16, 2023
1 parent 16b9187 commit 3fb79ad
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 12 deletions.
1 change: 1 addition & 0 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pub enum RoutableConnectors {
Payu,
Powertranz,
Prophetpay,
Rapyd,
Shift4,
Square,
Stax,
Expand Down
1 change: 1 addition & 0 deletions crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ impl From<RoutableConnectorChoice> for ast::ConnectorChoice {
RoutableConnectors::Paypal => euclid_enums::Connector::Paypal,
RoutableConnectors::Payu => euclid_enums::Connector::Payu,
RoutableConnectors::Powertranz => euclid_enums::Connector::Powertranz,
RoutableConnectors::Prophetpay => euclid_enums::Connector::Prophetpay,
RoutableConnectors::Rapyd => euclid_enums::Connector::Rapyd,
RoutableConnectors::Shift4 => euclid_enums::Connector::Shift4,
RoutableConnectors::Square => euclid_enums::Connector::Square,
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub enum Connector {
Paypal,
Payu,
Powertranz,
Prophetpay,
Rapyd,
Shift4,
Square,
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/frontend/dir/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub enum CardRedirectType {
Benefit,
Knet,
MomoAtm,
CardRedirect,
}

#[derive(
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/frontend/dir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl From<enums::CardRedirectType> for global_enums::PaymentMethodType {
enums::CardRedirectType::Benefit => Self::Benefit,
enums::CardRedirectType::Knet => Self::Knet,
enums::CardRedirectType::MomoAtm => Self::MomoAtm,
enums::CardRedirectType::CardRedirect => Self::CardRedirect,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/euclid/src/frontend/dir/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ impl IntoDirValue for (global_enums::PaymentMethodType, global_enums::PaymentMet
}
global_enums::PaymentMethodType::MomoAtm => Ok(dirval!(CardRedirectType = MomoAtm)),
global_enums::PaymentMethodType::Oxxo => Ok(dirval!(VoucherType = Oxxo)),
global_enums::PaymentMethodType::CardRedirect => {
Ok(dirval!(CardRedirectType = CardRedirect))
}
}
}
}
3 changes: 3 additions & 0 deletions crates/kgraph_utils/src/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ impl IntoDirValue for (api_enums::PaymentMethodType, api_enums::PaymentMethod) {
}
api_enums::PaymentMethodType::MomoAtm => Ok(dirval!(CardRedirectType = MomoAtm)),
api_enums::PaymentMethodType::Oxxo => Ok(dirval!(VoucherType = Oxxo)),
api_enums::PaymentMethodType::CardRedirect => {
Ok(dirval!(CardRedirectType = CardRedirect))
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions crates/router/src/connector/prophetpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl
fn get_request_body(
&self,
req: &types::PaymentsCompleteAuthorizeRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = prophetpay::ProphetpayRouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -309,7 +310,7 @@ impl
self, req, connectors,
)?)
.body(types::PaymentsCompleteAuthorizeType::get_request_body(
self, req,
self, req, connectors,
)?)
.build(),
))
Expand Down Expand Up @@ -371,6 +372,7 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
fn get_request_body(
&self,
req: &types::PaymentsSyncRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let req_obj = prophetpay::ProphetpaySyncRequest::try_from(req)?;

Expand All @@ -389,10 +391,13 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
Ok(Some(
services::RequestBuilder::new()
.method(services::Method::Get)
.method(services::Method::Post)
.url(&types::PaymentsSyncType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::PaymentsSyncType::get_headers(self, req, connectors)?)
.body(types::PaymentsSyncType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -455,6 +460,7 @@ impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsR
fn get_request_body(
&self,
req: &types::PaymentsCancelRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let req_obj = prophetpay::ProphetpayVoidRequest::try_from(req)?;

Expand Down Expand Up @@ -582,6 +588,7 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
.response
.parse_struct("prophetpay ProphetpayRefundResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

types::RouterData::try_from(types::ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -626,6 +633,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
fn get_request_body(
&self,
req: &types::RefundSyncRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let req_obj = prophetpay::ProphetpayRefundSyncRequest::try_from(req)?;

Expand Down
42 changes: 33 additions & 9 deletions crates/router/src/connector/prophetpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,31 @@ impl TryFrom<&types::PaymentsSyncRouterData> for ProphetpaySyncRequest {
#[derive(Debug, Clone, Deserialize)]
pub enum ProphetpayPaymentStatus {
Success,
#[serde(rename = "Transaction Approved")]
Charged,
Failure,
#[serde(rename = "Transaction Voided")]
Voided,
#[serde(rename = "Requires a card on file.")]
CardTokenNotFound,
#[serde(rename = "RefInfo and InquiryReference are duplicated")]
DuplicateValue,
#[serde(rename = "Profile is missing")]
MissingProfile,
#[serde(rename = "RefInfo is empty.")]
EmptyRef,
}

impl From<ProphetpayPaymentStatus> for enums::AttemptStatus {
fn from(item: ProphetpayPaymentStatus) -> Self {
match item {
ProphetpayPaymentStatus::Success => Self::Charged,
ProphetpayPaymentStatus::Failure => Self::Failure,
ProphetpayPaymentStatus::Success | ProphetpayPaymentStatus::Charged => Self::Charged,
ProphetpayPaymentStatus::Failure
| ProphetpayPaymentStatus::CardTokenNotFound
| ProphetpayPaymentStatus::DuplicateValue
| ProphetpayPaymentStatus::MissingProfile
| ProphetpayPaymentStatus::EmptyRef => Self::Failure,
ProphetpayPaymentStatus::Voided => Self::Voided,
ProphetpayPaymentStatus::CardTokenNotFound => Self::Failure,
}
}
}
Expand Down Expand Up @@ -466,15 +477,29 @@ impl<F> TryFrom<&ProphetpayRouterData<&types::RefundsRouterData<F>>> for Prophet
pub enum RefundStatus {
Success,
Failure,
#[serde(rename = "Transaction Voided")]
Voided,
#[serde(rename = "Requires a card on file.")]
CardTokenNotFound,
#[serde(rename = "RefInfo and InquiryReference are duplicated")]
DuplicateValue,
#[serde(rename = "Profile is missing")]
MissingProfile,
#[serde(rename = "RefInfo is empty.")]
EmptyRef,
}

impl From<RefundStatus> for enums::RefundStatus {
fn from(item: RefundStatus) -> Self {
match item {
RefundStatus::Success => Self::Success,
RefundStatus::Failure | RefundStatus::CardTokenNotFound => Self::Failure,
RefundStatus::Success
// in retrieving refund, if it is successful, it is shown as voided
| RefundStatus::Voided => Self::Success,
RefundStatus::Failure
| RefundStatus::CardTokenNotFound
| RefundStatus::DuplicateValue
| RefundStatus::MissingProfile
| RefundStatus::EmptyRef => Self::Failure,
}
}
}
Expand All @@ -483,8 +508,6 @@ impl From<RefundStatus> for enums::RefundStatus {
#[serde(rename_all = "camelCase")]
pub struct ProphetpayRefundResponse {
pub response_text: RefundStatus,
#[serde(rename = "transactionID")]
pub transaction_id: String,
}

impl TryFrom<types::RefundsResponseRouterData<api::Execute, ProphetpayRefundResponse>>
Expand All @@ -496,7 +519,8 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, ProphetpayRefundResp
) -> Result<Self, Self::Error> {
Ok(Self {
response: Ok(types::RefundsResponseData {
connector_refund_id: item.response.transaction_id.to_string(),
// no refund id is generated, rather transaction id is used for referring to status in refund also
connector_refund_id: item.data.request.connector_transaction_id.clone(),
refund_status: enums::RefundStatus::from(item.response.response_text),
}),
..item.data
Expand Down Expand Up @@ -533,7 +557,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, ProphetpayRefundRespon
) -> Result<Self, Self::Error> {
Ok(Self {
response: Ok(types::RefundsResponseData {
connector_refund_id: item.response.transaction_id.to_string(),
connector_refund_id: item.data.request.connector_transaction_id.clone(),
refund_status: enums::RefundStatus::from(item.response.response_text),
}),
..item.data
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/connector/zen/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ impl TryFrom<&api_models::payments::CardRedirectData> for ZenPaymentsRequest {
match value {
api_models::payments::CardRedirectData::Knet {}
| api_models::payments::CardRedirectData::Benefit {}
| api_models::payments::CardRedirectData::MomoAtm {} => {
| api_models::payments::CardRedirectData::MomoAtm {}
| api_models::payments::CardRedirectData::CardRedirect {} => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
)
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments/routing/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl ForeignFrom<api_enums::RoutableConnectors> for dsl_enums::Connector {
api_enums::RoutableConnectors::Paypal => Self::Paypal,
api_enums::RoutableConnectors::Payu => Self::Payu,
api_enums::RoutableConnectors::Powertranz => Self::Powertranz,
api_enums::RoutableConnectors::Prophetpay => Self::Prophetpay,
api_enums::RoutableConnectors::Rapyd => Self::Rapyd,
api_enums::RoutableConnectors::Shift4 => Self::Shift4,
api_enums::RoutableConnectors::Square => Self::Square,
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl ForeignTryFrom<api_enums::Connector> for api_enums::RoutableConnectors {
.into_report()?
}
api_enums::Connector::Powertranz => Self::Powertranz,
api_enums::Connector::Prophetpay => Self::Prophetpay,
api_enums::Connector::Rapyd => Self::Rapyd,
api_enums::Connector::Shift4 => Self::Shift4,
api_enums::Connector::Signifyd => {
Expand Down Expand Up @@ -302,6 +303,7 @@ impl ForeignFrom<dsl_enums::Connector> for api_enums::RoutableConnectors {
dsl_enums::Connector::Paypal => Self::Paypal,
dsl_enums::Connector::Payu => Self::Payu,
dsl_enums::Connector::Powertranz => Self::Powertranz,
dsl_enums::Connector::Prophetpay => Self::Prophetpay,
dsl_enums::Connector::Rapyd => Self::Rapyd,
dsl_enums::Connector::Shift4 => Self::Shift4,
dsl_enums::Connector::Square => Self::Square,
Expand Down

0 comments on commit 3fb79ad

Please sign in to comment.