Skip to content

Commit

Permalink
sync with main
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-sharma-juspay committed Nov 2, 2023
2 parents feeb85d + 1094493 commit 1b1d206
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Conventional Commit Message Check
name: PR Title Checks

on:
# This is a dangerous event trigger as it causes the workflow to run in the
Expand Down Expand Up @@ -35,6 +35,19 @@ env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
typos:
name: Spell check PR title
runs-on: ubuntu-latest
steps:
- name: Store PR title in a file
shell: bash
run: echo '${{ github.event.pull_request.title }}' > pr_title.txt

- name: Spell check
uses: crate-ci/typos@master
with:
files: ./pr_title.txt

pr_title_check:
name: Verify PR title follows conventional commit standards
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion crates/router/src/compatibility/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ where
Q: Serialize + std::fmt::Debug + 'a,
S: TryFrom<Q> + Serialize,
E: Serialize + error_stack::Context + actix_web::ResponseError + Clone,
U: auth::AuthInfo,
error_stack::Report<E>: services::EmbedError,
errors::ApiErrorResponse: ErrorSwitch<E>,
T: std::fmt::Debug + Serialize,
Expand Down
16 changes: 9 additions & 7 deletions crates/router/src/connector/multisafepay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
data: &types::PaymentsSyncRouterData,
res: Response,
) -> CustomResult<types::PaymentsSyncRouterData, errors::ConnectorError> {
let response: multisafepay::MultisafepayPaymentsResponse = res
let response: multisafepay::MultisafepayAuthResponse = res
.response
.parse_struct("multisafepay PaymentsResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

types::RouterData::try_from(types::ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -301,10 +302,11 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
data: &types::PaymentsAuthorizeRouterData,
res: Response,
) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> {
let response: multisafepay::MultisafepayPaymentsResponse = res
let response: multisafepay::MultisafepayAuthResponse = res
.response
.parse_struct("MultisafepayPaymentsResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

types::ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -399,17 +401,17 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
data: &types::RefundsRouterData<api::Execute>,
res: Response,
) -> CustomResult<types::RefundsRouterData<api::Execute>, errors::ConnectorError> {
let response: multisafepay::RefundResponse = res
let response: multisafepay::MultisafepayRefundResponse = res
.response
.parse_struct("multisafepay RefundResponse")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
types::ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
}
.try_into()
.change_context(errors::ConnectorError::ResponseHandlingFailed)
.change_context(errors::ConnectorError::ResponseDeserializationFailed)
}

fn get_error_response(
Expand Down Expand Up @@ -472,7 +474,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
data: &types::RefundSyncRouterData,
res: Response,
) -> CustomResult<types::RefundSyncRouterData, errors::ConnectorError> {
let response: multisafepay::RefundResponse = res
let response: multisafepay::MultisafepayRefundResponse = res
.response
.parse_struct("multisafepay RefundResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
Expand All @@ -482,7 +484,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
http_code: res.status_code,
}
.try_into()
.change_context(errors::ConnectorError::ResponseHandlingFailed)
.change_context(errors::ConnectorError::ResponseDeserializationFailed)
}

fn get_error_response(
Expand Down
189 changes: 120 additions & 69 deletions crates/router/src/connector/multisafepay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,57 +636,76 @@ pub struct MultisafepayPaymentsResponse {
pub data: Data,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum MultisafepayAuthResponse {
ErrorResponse(MultisafepayErrorResponse),
PaymentResponse(MultisafepayPaymentsResponse),
}

impl<F, T>
TryFrom<
types::ResponseRouterData<F, MultisafepayPaymentsResponse, T, types::PaymentsResponseData>,
> for types::RouterData<F, T, types::PaymentsResponseData>
TryFrom<types::ResponseRouterData<F, MultisafepayAuthResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ParsingError>;
fn try_from(
item: types::ResponseRouterData<
F,
MultisafepayPaymentsResponse,
MultisafepayAuthResponse,
T,
types::PaymentsResponseData,
>,
) -> Result<Self, Self::Error> {
let redirection_data = item
.response
.data
.payment_url
.clone()
.map(|url| services::RedirectForm::from((url, services::Method::Get)));

let default_status = if item.response.success {
MultisafepayPaymentStatus::Initialized
} else {
MultisafepayPaymentStatus::Declined
};

let status = item.response.data.status.unwrap_or(default_status);

Ok(Self {
status: enums::AttemptStatus::from(status),
response: Ok(types::PaymentsResponseData::TransactionResponse {
resource_id: types::ResponseId::ConnectorTransactionId(
item.response.data.order_id.clone(),
),
redirection_data,
mandate_reference: item
.response
match item.response {
MultisafepayAuthResponse::PaymentResponse(payment_response) => {
let redirection_data = payment_response
.data
.payment_details
.and_then(|payment_details| payment_details.recurring_id)
.map(|id| types::MandateReference {
connector_mandate_id: Some(id),
payment_method_id: None,
.payment_url
.clone()
.map(|url| services::RedirectForm::from((url, services::Method::Get)));

let default_status = if payment_response.success {
MultisafepayPaymentStatus::Initialized
} else {
MultisafepayPaymentStatus::Declined
};

let status = payment_response.data.status.unwrap_or(default_status);

Ok(Self {
status: enums::AttemptStatus::from(status),
response: Ok(types::PaymentsResponseData::TransactionResponse {
resource_id: types::ResponseId::ConnectorTransactionId(
payment_response.data.order_id.clone(),
),
redirection_data,
mandate_reference: payment_response
.data
.payment_details
.and_then(|payment_details| payment_details.recurring_id)
.map(|id| types::MandateReference {
connector_mandate_id: Some(id),
payment_method_id: None,
}),
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: Some(
payment_response.data.order_id.clone(),
),
}),
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: Some(item.response.data.order_id.clone()),
..item.data
})
}
MultisafepayAuthResponse::ErrorResponse(error_response) => Ok(Self {
response: Err(types::ErrorResponse {
code: error_response.error_code.to_string(),
message: error_response.error_info.clone(),
reason: Some(error_response.error_info),
status_code: item.http_code,
}),
..item.data
}),
..item.data
})
}
}
}

Expand Down Expand Up @@ -747,61 +766,93 @@ pub struct RefundData {
pub error_code: Option<i32>,
pub error_info: Option<String>,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RefundResponse {
pub success: bool,
pub data: RefundData,
}

impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MultisafepayRefundResponse {
ErrorResponse(MultisafepayErrorResponse),
RefundResponse(RefundResponse),
}

impl TryFrom<types::RefundsResponseRouterData<api::Execute, MultisafepayRefundResponse>>
for types::RefundsRouterData<api::Execute>
{
type Error = error_stack::Report<errors::ParsingError>;
fn try_from(
item: types::RefundsResponseRouterData<api::Execute, RefundResponse>,
item: types::RefundsResponseRouterData<api::Execute, MultisafepayRefundResponse>,
) -> Result<Self, Self::Error> {
let refund_stat = if item.response.success {
RefundStatus::Succeeded
} else {
RefundStatus::Failed
};

Ok(Self {
response: Ok(types::RefundsResponseData {
connector_refund_id: item.response.data.refund_id.to_string(),
refund_status: enums::RefundStatus::from(refund_stat),
match item.response {
MultisafepayRefundResponse::RefundResponse(refund_data) => {
let refund_status = if refund_data.success {
RefundStatus::Succeeded
} else {
RefundStatus::Failed
};

Ok(Self {
response: Ok(types::RefundsResponseData {
connector_refund_id: refund_data.data.refund_id.to_string(),
refund_status: enums::RefundStatus::from(refund_status),
}),
..item.data
})
}
MultisafepayRefundResponse::ErrorResponse(error_response) => Ok(Self {
response: Err(types::ErrorResponse {
code: error_response.error_code.to_string(),
message: error_response.error_info.clone(),
reason: Some(error_response.error_info),
status_code: item.http_code,
}),
..item.data
}),
..item.data
})
}
}
}

impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>>
impl TryFrom<types::RefundsResponseRouterData<api::RSync, MultisafepayRefundResponse>>
for types::RefundsRouterData<api::RSync>
{
type Error = error_stack::Report<errors::ParsingError>;
fn try_from(
item: types::RefundsResponseRouterData<api::RSync, RefundResponse>,
item: types::RefundsResponseRouterData<api::RSync, MultisafepayRefundResponse>,
) -> Result<Self, Self::Error> {
let refund_status = if item.response.success {
RefundStatus::Succeeded
} else {
RefundStatus::Failed
};

Ok(Self {
response: Ok(types::RefundsResponseData {
connector_refund_id: item.response.data.refund_id.to_string(),
refund_status: enums::RefundStatus::from(refund_status),
match item.response {
MultisafepayRefundResponse::RefundResponse(refund_data) => {
let refund_status = if refund_data.success {
RefundStatus::Succeeded
} else {
RefundStatus::Failed
};

Ok(Self {
response: Ok(types::RefundsResponseData {
connector_refund_id: refund_data.data.refund_id.to_string(),
refund_status: enums::RefundStatus::from(refund_status),
}),
..item.data
})
}
MultisafepayRefundResponse::ErrorResponse(error_response) => Ok(Self {
response: Err(types::ErrorResponse {
code: error_response.error_code.to_string(),
message: error_response.error_info.clone(),
reason: Some(error_response.error_info),
status_code: item.http_code,
}),
..item.data
}),
..item.data
})
}
}
}

#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MultisafepayErrorResponse {
pub success: bool,
pub error_code: i32,
pub error_info: String,
}
9 changes: 7 additions & 2 deletions crates/router/src/events/api_logs.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use router_env::{tracing_actix_web::RequestId, types::FlowMetric};
use serde::{Deserialize, Serialize};
use serde::Serialize;
use time::OffsetDateTime;

use super::{EventType, RawEvent};
use crate::services::authentication::AuthenticationType;

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct ApiEvent {
api_flow: String,
created_at_timestamp: i128,
request_id: String,
latency: u128,
status_code: i64,
#[serde(flatten)]
auth_type: AuthenticationType,
request: serde_json::Value,
response: Option<serde_json::Value>,
hs_latency: Option<u128>,
Expand All @@ -25,6 +28,7 @@ impl ApiEvent {
request: serde_json::Value,
response: Option<serde_json::Value>,
hs_latency: Option<u128>,
auth_type: AuthenticationType,
) -> Self {
Self {
api_flow: api_flow.to_string(),
Expand All @@ -35,6 +39,7 @@ impl ApiEvent {
request,
response,
hs_latency,
auth_type,
}
}
}
Expand Down
Loading

0 comments on commit 1b1d206

Please sign in to comment.