Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): [Paypal] fix PSync for redirection flow for PayPal (#2068)
Prasunna Soppae730c7351688
diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rsindex af74f1c494..e8b4269d38 100644--- a/crates/router/src/connector/paypal.rs+++ b/crates/router/src/connector/paypal.rs@@ -569,9 +569,9 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRematch data.payment_method {diesel_models::enums::PaymentMethod::Wallet| diesel_models::enums::PaymentMethod::BankRedirect => {- let response: paypal::PaypalOrdersResponse = res+ let response: paypal::PaypalSyncResponse = res.response- .parse_struct("paypal PaymentsOrderResponse")+ .parse_struct("paypal SyncResponse").change_context(errors::ConnectorError::ResponseDeserializationFailed)?;types::RouterData::try_from(types::ResponseRouterData {response,@@ -659,6 +659,7 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme.headers(types::PaymentsCaptureType::get_headers(self, req, connectors,)?)+ .body(types::PaymentsCaptureType::get_request_body(self, req)?).build(),))}diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rsindex d274e76696..0de25af53e 100644--- a/crates/router/src/connector/paypal/transformers.rs+++ b/crates/router/src/connector/paypal/transformers.rs@@ -410,6 +410,13 @@ pub struct PaypalRedirectResponse {links: Vec<PaypalLinks>,}+#[derive(Debug, Deserialize)]+#[serde(untagged)]+pub enum PaypalSyncResponse {+ PaypalOrdersSyncResponse(PaypalOrdersResponse),+ PaypalRedirectSyncResponse(PaypalRedirectResponse),+}+#[derive(Debug, Serialize, Deserialize)]pub struct PaypalPaymentsSyncResponse {id: String,@@ -535,6 +542,32 @@ fn get_redirect_url(Ok(link)}+impl<F, T> TryFrom<types::ResponseRouterData<F, PaypalSyncResponse, T, types::PaymentsResponseData>>+ for types::RouterData<F, T, types::PaymentsResponseData>+{+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ item: types::ResponseRouterData<F, PaypalSyncResponse, T, types::PaymentsResponseData>,+ ) -> Result<Self, Self::Error> {+ match item.response {+ PaypalSyncResponse::PaypalOrdersSyncResponse(response) => {+ Self::try_from(types::ResponseRouterData {+ response,+ data: item.data,+ http_code: item.http_code,+ })+ }+ PaypalSyncResponse::PaypalRedirectSyncResponse(response) => {+ Self::try_from(types::ResponseRouterData {+ response,+ data: item.data,+ http_code: item.http_code,+ })+ }+ }+ }+}+impl<F, T>TryFrom<types::ResponseRouterData<F, PaypalRedirectResponse, T, types::PaymentsResponseData>>for types::RouterData<F, T, types::PaymentsResponseData>diff --git a/crates/router/tests/connectors/paypal.rs b/crates/router/tests/connectors/paypal.rsindex 4affb82785..faf8f4d228 100644--- a/crates/router/tests/connectors/paypal.rs+++ b/crates/router/tests/connectors/paypal.rs@@ -175,6 +175,7 @@ async fn should_void_authorized_payment() {// Refunds a payment using the manual capture flow (Non 3DS).#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_refund_manually_captured_payment() {let authorize_response = CONNECTOR.authorize_payment(get_payment_data(), get_default_payment_info())@@ -213,6 +214,7 @@ async fn should_refund_manually_captured_payment() {// Partially refunds a payment using the manual capture flow (Non 3DS).#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_partially_refund_manually_captured_payment() {let authorize_response = CONNECTOR.authorize_payment(get_payment_data(), get_default_payment_info())@@ -252,6 +254,7 @@ async fn should_partially_refund_manually_captured_payment() {// Synchronizes a refund using the manual capture flow (Non 3DS).#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_sync_manually_captured_refund() {let authorize_response = CONNECTOR.authorize_payment(get_payment_data(), get_default_payment_info())@@ -343,6 +346,7 @@ async fn should_sync_auto_captured_payment() {// Refunds a payment using the automatic capture flow (Non 3DS).#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_refund_auto_captured_payment() {let response = CONNECTOR.make_payment_and_refund(get_payment_data(), None, get_default_payment_info())@@ -356,6 +360,7 @@ async fn should_refund_auto_captured_payment() {// Partially refunds a payment using the automatic capture flow (Non 3DS).#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_partially_refund_succeeded_payment() {let authorize_response = CONNECTOR.make_payment(get_payment_data(), get_default_payment_info())@@ -382,6 +387,7 @@ async fn should_partially_refund_succeeded_payment() {// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS).#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_refund_succeeded_payment_multiple_times() {let authorize_response = CONNECTOR.make_payment(get_payment_data(), get_default_payment_info())@@ -410,6 +416,7 @@ async fn should_refund_succeeded_payment_multiple_times() {// Synchronizes a refund using the automatic capture flow (Non 3DS).#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_sync_refund() {let refund_response = CONNECTOR.make_payment_and_refund(get_payment_data(), None, get_default_payment_info())@@ -585,6 +592,7 @@ async fn should_fail_capture_for_invalid_payment() {// Refunds a payment with refund amount higher than payment amount.#[actix_web::test]+#[ignore = "Since Payment status is in pending status, cannot refund"]async fn should_fail_for_refund_amount_higher_than_payment_amount() {let authorize_response = CONNECTOR.make_payment(get_payment_data(), get_default_payment_info())