Skip to content

Commit

Permalink
fix(connector): Trigger Psync after redirection url (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamraatBansal authored Oct 12, 2023
1 parent fc97ded commit 8029a89
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 116 deletions.
8 changes: 6 additions & 2 deletions crates/router/src/connector/authorizedotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,12 @@ impl services::ConnectorRedirectResponse for Authorizedotnet {
&self,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
Ok(payments::CallConnectorAction::Trigger)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}
8 changes: 6 additions & 2 deletions crates/router/src/connector/bambora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,13 @@ impl services::ConnectorRedirectResponse for Bambora {
&self,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
Ok(payments::CallConnectorAction::Trigger)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}

Expand Down
49 changes: 27 additions & 22 deletions crates/router/src/connector/bluesnap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,31 +1095,36 @@ impl services::ConnectorRedirectResponse for Bluesnap {
&self,
_query_params: &str,
json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
let redirection_response: bluesnap::BluesnapRedirectionResponse = json_payload
.ok_or(errors::ConnectorError::MissingConnectorRedirectionPayload {
field_name: "json_payload",
})?
.parse_value("BluesnapRedirectionResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
match action {
services::PaymentAction::PSync => Ok(payments::CallConnectorAction::Trigger),
services::PaymentAction::CompleteAuthorize => {
let redirection_response: bluesnap::BluesnapRedirectionResponse = json_payload
.ok_or(errors::ConnectorError::MissingConnectorRedirectionPayload {
field_name: "json_payload",
})?
.parse_value("BluesnapRedirectionResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

let redirection_result: bluesnap::BluesnapThreeDsResult = redirection_response
.authentication_response
.parse_struct("BluesnapThreeDsResult")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
let redirection_result: bluesnap::BluesnapThreeDsResult = redirection_response
.authentication_response
.parse_struct("BluesnapThreeDsResult")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

match redirection_result.status.as_str() {
"Success" => Ok(payments::CallConnectorAction::Trigger),
_ => Ok(payments::CallConnectorAction::StatusUpdate {
status: enums::AttemptStatus::AuthenticationFailed,
error_code: redirection_result.code,
error_message: redirection_result
.info
.as_ref()
.and_then(|info| info.errors.as_ref().and_then(|error| error.first()))
.cloned(),
}),
match redirection_result.status.as_str() {
"Success" => Ok(payments::CallConnectorAction::Trigger),
_ => Ok(payments::CallConnectorAction::StatusUpdate {
status: enums::AttemptStatus::AuthenticationFailed,
error_code: redirection_result.code,
error_message: redirection_result
.info
.as_ref()
.and_then(|info| info.errors.as_ref().and_then(|error| error.first()))
.cloned(),
}),
}
}
}
}
}
Expand Down
24 changes: 7 additions & 17 deletions crates/router/src/connector/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,25 +1289,15 @@ impl api::IncomingWebhook for Checkout {
impl services::ConnectorRedirectResponse for Checkout {
fn get_flow_type(
&self,
query_params: &str,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
let query =
serde_urlencoded::from_str::<transformers::CheckoutRedirectResponse>(query_params)
.into_report()
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
let connector_action = query
.status
.map(
|checkout_status| payments::CallConnectorAction::StatusUpdate {
status: diesel_models::enums::AttemptStatus::from(checkout_status),
error_code: None,
error_message: None,
},
)
.unwrap_or(payments::CallConnectorAction::Trigger);
Ok(connector_action)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}

Expand Down
25 changes: 7 additions & 18 deletions crates/router/src/connector/globalpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,25 +926,14 @@ impl api::IncomingWebhook for Globalpay {
impl services::ConnectorRedirectResponse for Globalpay {
fn get_flow_type(
&self,
query_params: &str,
_query_params: &str,
_json_payload: Option<Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
let query = serde_urlencoded::from_str::<response::GlobalpayRedirectResponse>(query_params)
.into_report()
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
Ok(query.status.map_or(
payments::CallConnectorAction::Trigger,
|status| match status {
response::GlobalpayPaymentStatus::Captured => {
payments::CallConnectorAction::StatusUpdate {
status: diesel_models::enums::AttemptStatus::from(status),
error_code: None,
error_message: None,
}
}
_ => payments::CallConnectorAction::Trigger,
},
))
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}
8 changes: 6 additions & 2 deletions crates/router/src/connector/mollie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,12 @@ impl services::ConnectorRedirectResponse for Mollie {
&self,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
Ok(payments::CallConnectorAction::Trigger)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}
8 changes: 6 additions & 2 deletions crates/router/src/connector/noon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,13 @@ impl services::ConnectorRedirectResponse for Noon {
&self,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
Ok(payments::CallConnectorAction::Trigger)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions crates/router/src/connector/payme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,13 @@ impl services::ConnectorRedirectResponse for Payme {
&self,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
Ok(payments::CallConnectorAction::Trigger)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions crates/router/src/connector/paypal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,8 +1150,12 @@ impl services::ConnectorRedirectResponse for Paypal {
&self,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: PaymentAction,
action: PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
Ok(payments::CallConnectorAction::Trigger)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}
33 changes: 7 additions & 26 deletions crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1962,33 +1962,14 @@ impl api::IncomingWebhook for Stripe {
impl services::ConnectorRedirectResponse for Stripe {
fn get_flow_type(
&self,
query_params: &str,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<crate::core::payments::CallConnectorAction, errors::ConnectorError> {
let query =
serde_urlencoded::from_str::<transformers::StripeRedirectResponse>(query_params)
.into_report()
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

crate::logger::debug!(stripe_redirect_response=?query);

Ok(query
.redirect_status
.map_or(
payments::CallConnectorAction::Trigger,
|status| match status {
transformers::StripePaymentStatus::Failed
| transformers::StripePaymentStatus::Pending
| transformers::StripePaymentStatus::Succeeded => {
payments::CallConnectorAction::Trigger
}
_ => payments::CallConnectorAction::StatusUpdate {
status: enums::AttemptStatus::from(status),
error_code: None,
error_message: None,
},
},
))
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}
25 changes: 7 additions & 18 deletions crates/router/src/connector/trustpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,26 +956,15 @@ impl api::IncomingWebhook for Trustpay {
impl services::ConnectorRedirectResponse for Trustpay {
fn get_flow_type(
&self,
query_params: &str,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
let query =
serde_urlencoded::from_str::<transformers::TrustpayRedirectResponse>(query_params)
.into_report()
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
crate::logger::debug!(trustpay_redirect_response=?query);
Ok(query.status.map_or(
payments::CallConnectorAction::Trigger,
|status| match status.as_str() {
"SuccessOk" => payments::CallConnectorAction::StatusUpdate {
status: diesel_models::enums::AttemptStatus::Charged,
error_code: None,
error_message: None,
},
_ => payments::CallConnectorAction::Trigger,
},
))
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions crates/router/src/connector/zen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,12 @@ impl services::ConnectorRedirectResponse for Zen {
&self,
_query_params: &str,
_json_payload: Option<serde_json::Value>,
_action: services::PaymentAction,
action: services::PaymentAction,
) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {
Ok(payments::CallConnectorAction::Trigger)
match action {
services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {
Ok(payments::CallConnectorAction::Trigger)
}
}
}
}
2 changes: 1 addition & 1 deletion crates/router/src/services/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ pub fn build_redirection_form(
(PreEscaped(format!("<script>
bluesnap.threeDsPaymentsSetup(\"{payment_fields_token}\",
function(sdkResponse) {{
console.log(sdkResponse);
// console.log(sdkResponse);
var f = document.createElement('form');
f.action=window.location.pathname.replace(/payments\\/redirect\\/(\\w+)\\/(\\w+)\\/\\w+/, \"payments/$1/$2/redirect/complete/bluesnap?paymentToken={payment_fields_token}\");
f.method='POST';
Expand Down

0 comments on commit 8029a89

Please sign in to comment.