Skip to content

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

fix(connector): [Paypal] make order status optional in PSync to handle declined captures (#12783)

DEEPANSHU BANSALd22357305f67
diff --git a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
index a323e93402..ebb59aa1e6 100644
--- a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
@@ -2226,7 +2226,12 @@ pub enum AuthenticationStatus {
pub struct PaypalOrdersResponse {
id: String,
intent: PaypalPaymentIntent,
- status: PaypalOrderStatus,
+ // PayPal can omit the top-level order `status` in some Orders v2 responses (observed in PSync
+ // for an order whose only capture was `DECLINED`). This field is kept optional so the response
+ // still deserializes when it is absent. The attempt status is not derived from this field
+ // anyway: for orders it is taken from the capture/authorization status inside `purchase_units`
+ // (see `TryFrom<ResponseRouterData<F, PaypalOrdersResponse, ..>>`).
+ status: Option<PaypalOrderStatus>,
purchase_units: Vec<PurchaseUnitItem>,
payment_source: Option<PaymentSourceItemResponse>,
payer: Option<Payer>,
@@ -2417,6 +2422,9 @@ where
_ => None,
}
.ok_or(errors::ConnectorError::ResponseDeserializationFailed)?;
+ // Derive the attempt status from the capture/authorization status rather than the
+ // top-level order `status`, which PayPal may omit (e.g. a declined capture). For example a
+ // `DECLINED` capture maps to `AttemptStatus::Failure` and is handled by the branch below.
let status = payment_collection_item.status.clone();
let status = storage_enums::AttemptStatus::from(status);
@@ -3834,7 +3842,7 @@ impl TryFrom<(PaypalRedirectsWebhooks, PaypalWebhookEventType)> for PaypalOrders
Ok(Self {
id: webhook_body.id,
intent: webhook_body.intent,
- status: PaypalOrderStatus::try_from(webhook_event)?,
+ status: Some(PaypalOrderStatus::try_from(webhook_event)?),
purchase_units: webhook_body.purchase_units,
payment_source: None,
payer: webhook_body.payer,