From 99ff82ef6d42899d6cb16f05c7a0c2bc193074a3 Mon Sep 17 00:00:00 2001 From: Prasunna Soppa <70575890+prasunna09@users.noreply.github.com> Date: Fri, 1 Sep 2023 20:07:05 +0530 Subject: [PATCH] feat(connector): [Paypal] Add manual capture for paypal wallet (#2072) --- crates/router/src/connector/paypal.rs | 7 ++++++- crates/router/src/connector/paypal/transformers.rs | 9 ++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs index e8b4269d38..adf6e51dee 100644 --- a/crates/router/src/connector/paypal.rs +++ b/crates/router/src/connector/paypal.rs @@ -437,8 +437,13 @@ impl req: &types::PaymentsCompleteAuthorizeRouterData, connectors: &settings::Connectors, ) -> CustomResult { + 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(), + }; Ok(format!( - "{}v2/checkout/orders/{}/capture", + "{}v2/checkout/orders/{}/{complete_authorize_url}", self.base_url(connectors), req.request .connector_transaction_id diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs index 0de25af53e..3e4cb2a7d5 100644 --- a/crates/router/src/connector/paypal/transformers.rs +++ b/crates/router/src/connector/paypal/transformers.rs @@ -207,9 +207,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaypalPaymentsRequest { let intent = if item.request.is_auto_capture()? { PaypalPaymentIntent::Capture } else { - Err(errors::ConnectorError::NotImplemented( - "Manual capture method for Paypal wallet".to_string(), - ))? + PaypalPaymentIntent::Authorize }; let amount = OrderAmount { currency_code: item.request.currency, @@ -476,7 +474,7 @@ impl .ok_or(errors::ConnectorError::MissingConnectorTransactionID)?; let id = get_id_based_on_intent(&item.response.intent, purchase_units)?; - let (connector_meta, capture_id) = match item.response.intent.clone() { + let (connector_meta, order_id) = match item.response.intent.clone() { PaypalPaymentIntent::Capture => ( serde_json::json!(PaypalMeta { authorize_id: None, @@ -509,6 +507,7 @@ impl ) { (Some(authorizations), None) => authorizations.first(), (None, Some(captures)) => captures.first(), + (Some(_), Some(captures)) => captures.first(), _ => None, } .ok_or(errors::ConnectorError::ResponseDeserializationFailed)?; @@ -517,7 +516,7 @@ impl Ok(Self { status, response: Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: capture_id, + resource_id: order_id, redirection_data: None, mandate_reference: None, connector_metadata: Some(connector_meta),