Skip to content

Commit

Permalink
feat(connector): [Paypal] Implement 3DS for Cards (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakilmostak authored Oct 6, 2023
1 parent 53b4816 commit d95a64d
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 25 deletions.
53 changes: 35 additions & 18 deletions crates/router/src/connector/paypal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use error_stack::{IntoReport, ResultExt};
use masking::PeekInterface;
use transformers as paypal;

use self::transformers::PaypalMeta;
use self::transformers::{PaypalAuthResponse, PaypalMeta};
use super::utils::PaymentsCompleteAuthorizeRequestData;
use crate::{
configs::settings,
connector::{
Expand Down Expand Up @@ -391,24 +392,27 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
data: &types::PaymentsAuthorizeRouterData,
res: Response,
) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> {
match data.payment_method {
diesel_models::enums::PaymentMethod::Wallet
| diesel_models::enums::PaymentMethod::BankRedirect => {
let response: paypal::PaypalRedirectResponse = res
.response
.parse_struct("paypal PaymentsRedirectResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
let response: PaypalAuthResponse =
res.response
.parse_struct("paypal PaypalAuthResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

match response {
PaypalAuthResponse::PaypalOrdersResponse(response) => {
types::RouterData::try_from(types::ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
})
}
_ => {
let response: paypal::PaypalOrdersResponse = res
.response
.parse_struct("paypal PaymentsOrderResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
PaypalAuthResponse::PaypalRedirectResponse(response) => {
types::RouterData::try_from(types::ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
})
}
PaypalAuthResponse::PaypalThreeDsResponse(response) => {
types::RouterData::try_from(types::ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -450,10 +454,10 @@ impl
req: &types::PaymentsCompleteAuthorizeRouterData,
connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
let paypal_meta: PaypalMeta = to_connector_meta(req.request.connector_meta.clone())?;
let complete_authorize_url = match paypal_meta.psync_flow {
transformers::PaypalPaymentIntent::Authorize => "authorize".to_string(),
transformers::PaypalPaymentIntent::Capture => "capture".to_string(),
let complete_authorize_url = if req.request.is_auto_capture()? {
"capture".to_string()
} else {
"authorize".to_string()
};
Ok(format!(
"{}v2/checkout/orders/{}/{complete_authorize_url}",
Expand Down Expand Up @@ -493,7 +497,7 @@ impl
) -> CustomResult<types::PaymentsCompleteAuthorizeRouterData, errors::ConnectorError> {
let response: paypal::PaypalOrdersResponse = res
.response
.parse_struct("paypal PaymentsOrderResponse")
.parse_struct("paypal PaypalOrdersResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
types::RouterData::try_from(types::ResponseRouterData {
response,
Expand Down Expand Up @@ -559,6 +563,19 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
)?;
format!("v2/payments/captures/{capture_id}")
}
// only set when payment is done through card 3DS
//because no authorize or capture id is generated during payment authorize call for card 3DS
transformers::PaypalPaymentIntent::Authenticate => {
format!(
"v2/checkout/orders/{}",
req.request
.connector_transaction_id
.get_connector_transaction_id()
.change_context(
errors::ConnectorError::MissingConnectorTransactionID
)?
)
}
};
Ok(format!("{}{psync_url}", self.base_url(connectors)))
}
Expand Down
Loading

0 comments on commit d95a64d

Please sign in to comment.