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
feat(connector): [Paypal] use connector request reference id as reference for paypal (#2577)
Prasunna Soppa500405d78938
diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rsindex 1f872868a0..fd104ac4aa 100644--- a/crates/router/src/connector/paypal.rs+++ b/crates/router/src/connector/paypal.rs@@ -1091,7 +1091,7 @@ impl api::IncomingWebhook for Paypal {resource.purchase_units.first()- .map(|unit| unit.reference_id.clone())+ .and_then(|unit| unit.invoice_id.clone().or(unit.reference_id.clone())).ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?,),))diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rsindex 78bd75efe1..72dccaed73 100644--- a/crates/router/src/connector/paypal/transformers.rs+++ b/crates/router/src/connector/paypal/transformers.rs@@ -73,7 +73,9 @@ pub struct OrderAmount {#[derive(Default, Debug, Serialize, Eq, PartialEq)]pub struct PurchaseUnitRequest {- reference_id: String,+ reference_id: Option<String>, //reference for an item in purchase_units+ invoice_id: Option<String>, //The API caller-provided external invoice number for this order. Appears in both the payer's transaction history and the emails that the payer receives.+ custom_id: Option<String>, //Used to reconcile client transactions with PayPal transactions.amount: OrderAmount,}@@ -260,10 +262,13 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalPcurrency_code: item.router_data.request.currency,value: item.amount.to_owned(),};- let reference_id = item.router_data.attempt_id.clone();+ let connector_request_reference_id =+ item.router_data.connector_request_reference_id.clone();let purchase_units = vec![PurchaseUnitRequest {- reference_id,+ reference_id: Some(connector_request_reference_id.clone()),+ custom_id: Some(connector_request_reference_id.clone()),+ invoice_id: Some(connector_request_reference_id),amount,}];let card = item.router_data.request.get_card()?;@@ -304,9 +309,14 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalPcurrency_code: item.router_data.request.currency,value: item.amount.to_owned(),};- let reference_id = item.router_data.attempt_id.clone();++ let connector_req_reference_id =+ item.router_data.connector_request_reference_id.clone();+let purchase_units = vec![PurchaseUnitRequest {- reference_id,+ reference_id: Some(connector_req_reference_id.clone()),+ custom_id: Some(connector_req_reference_id.clone()),+ invoice_id: Some(connector_req_reference_id),amount,}];let payment_source =@@ -367,9 +377,13 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalPcurrency_code: item.router_data.request.currency,value: item.amount.to_owned(),};- let reference_id = item.router_data.attempt_id.clone();+ let connector_req_reference_id =+ item.router_data.connector_request_reference_id.clone();+let purchase_units = vec![PurchaseUnitRequest {- reference_id,+ reference_id: Some(connector_req_reference_id.clone()),+ custom_id: Some(connector_req_reference_id.clone()),+ invoice_id: Some(connector_req_reference_id),amount,}];let payment_source =@@ -655,7 +669,8 @@ pub struct PaymentsCollection {#[derive(Default, Debug, Clone, Serialize, Deserialize)]pub struct PurchaseUnitItem {- pub reference_id: String,+ pub reference_id: Option<String>,+ pub invoice_id: Option<String>,pub payments: PaymentsCollection,}@@ -680,11 +695,17 @@ pub struct PaypalLinks {rel: String,}+#[derive(Default, Debug, Clone, Serialize, Deserialize)]+pub struct RedirectPurchaseUnitItem {+ pub invoice_id: String,+}+#[derive(Debug, Clone, Serialize, Deserialize)]pub struct PaypalRedirectResponse {id: String,intent: PaypalPaymentIntent,status: PaypalOrderStatus,+ purchase_units: Vec<RedirectPurchaseUnitItem>,links: Vec<PaypalLinks>,}@@ -712,6 +733,7 @@ pub struct PaypalPaymentsSyncResponse {id: String,status: PaypalPaymentStatus,amount: OrderAmount,+ invoice_id: Option<String>,supplementary_data: PaypalSupplementaryData,}@@ -792,7 +814,7 @@ impl<F, T>capture_id: Some(id),psync_flow: item.response.intent.clone()}),- types::ResponseId::ConnectorTransactionId(item.response.id),+ types::ResponseId::ConnectorTransactionId(item.response.id.clone()),),PaypalPaymentIntent::Authorize => (@@ -801,7 +823,7 @@ impl<F, T>capture_id: None,psync_flow: item.response.intent.clone()}),- types::ResponseId::ConnectorTransactionId(item.response.id),+ types::ResponseId::ConnectorTransactionId(item.response.id.clone()),),PaypalPaymentIntent::Authenticate => {@@ -836,7 +858,10 @@ impl<F, T>mandate_reference: None,connector_metadata: Some(connector_meta),network_txn_id: None,- connector_response_reference_id: None,+ connector_response_reference_id: purchase_units+ .invoice_id+ .clone()+ .or(Some(item.response.id)),}),..item.data})@@ -925,11 +950,12 @@ impl<F, T>capture_id: None,psync_flow: item.response.intent});+ let purchase_units = item.response.purchase_units.first();Ok(Self {status,response: Ok(types::PaymentsResponseData::TransactionResponse {- resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),+ resource_id: types::ResponseId::ConnectorTransactionId(item.response.id.clone()),redirection_data: Some(services::RedirectForm::from((link.ok_or(errors::ConnectorError::ResponseDeserializationFailed)?,services::Method::Get,@@ -937,7 +963,9 @@ impl<F, T>mandate_reference: None,connector_metadata: Some(connector_meta),network_txn_id: None,- connector_response_reference_id: None,+ connector_response_reference_id: Some(+ purchase_units.map_or(item.response.id, |item| item.invoice_id.clone()),+ ),}),..item.data})@@ -1075,13 +1103,21 @@ impl<F, T>status: storage_enums::AttemptStatus::from(item.response.status),response: Ok(types::PaymentsResponseData::TransactionResponse {resource_id: types::ResponseId::ConnectorTransactionId(- item.response.supplementary_data.related_ids.order_id,+ item.response+ .supplementary_data+ .related_ids+ .order_id+ .clone(),),redirection_data: None,mandate_reference: None,connector_metadata: None,network_txn_id: None,- connector_response_reference_id: None,+ connector_response_reference_id: item+ .response+ .invoice_id+ .clone()+ .or(Some(item.response.supplementary_data.related_ids.order_id)),}),..item.data})@@ -1133,6 +1169,7 @@ pub struct PaypalCaptureResponse {id: String,status: PaypalPaymentStatus,amount: Option<OrderAmount>,+ invoice_id: Option<String>,final_capture: bool,}@@ -1174,11 +1211,14 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<PaypalCaptureResponse>>mandate_reference: None,connector_metadata: Some(serde_json::json!(PaypalMeta {authorize_id: connector_payment_id.authorize_id,- capture_id: Some(item.response.id),+ capture_id: Some(item.response.id.clone()),psync_flow: PaypalPaymentIntent::Capture})),network_txn_id: None,- connector_response_reference_id: None,+ connector_response_reference_id: item+ .response+ .invoice_id+ .or(Some(item.response.id)),}),amount_captured: Some(amount_captured),..item.data@@ -1193,11 +1233,11 @@ pub enum PaypalCancelStatus {}#[derive(Debug, Serialize, Deserialize, PartialEq)]-#[serde(rename_all = "camelCase")]pub struct PaypalPaymentsCancelResponse {id: String,status: PaypalCancelStatus,amount: Option<OrderAmount>,+ invoice_id: Option<String>,}impl<F, T>@@ -1220,12 +1260,15 @@ impl<F, T>Ok(Self {status,response: Ok(types::PaymentsResponseData::TransactionResponse {- resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),+ resource_id: types::ResponseId::ConnectorTransactionId(item.response.id.clone()),redirection_data: None,mandate_reference: None,connector_metadata: None,network_txn_id: None,- connector_response_reference_id: None,+ connector_response_reference_id: item+ .response+ .invoice_id+ .or(Some(item.response.id)),}),..item.data})@@ -1408,6 +1451,7 @@ pub struct PaypalSellerPayableBreakdown {pub struct PaypalCardWebhooks {pub supplementary_data: PaypalSupplementaryData,pub amount: OrderAmount,+ pub invoice_id: Option<String>,}#[derive(Deserialize, Debug, Serialize)]@@ -1528,6 +1572,7 @@ impl TryFrom<(PaypalCardWebhooks, PaypalWebhookEventType)> for PaypalPaymentsSynstatus: PaypalPaymentStatus::try_from(webhook_event)?,amount: webhook_body.amount,supplementary_data: webhook_body.supplementary_data,+ invoice_id: webhook_body.invoice_id,})}}