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

feat(core): paypal manual capture changes in sessionApi (#12374)

Nithin Nbeb6e86bf45d
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 2d54b9a678..13a66498c9 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -36321,6 +36321,13 @@
"propertyName": "field_type"
}
},
+ "PaypalCaptureMethod": {
+ "type": "string",
+ "enum": [
+ "capture",
+ "authorize"
+ ]
+ },
"PaypalFlow": {
"type": "string",
"enum": [
@@ -36375,6 +36382,22 @@
"type": "string",
"description": "User token required for returning customer flow, used by client to initiate sdk",
"nullable": true
+ },
+ "currency": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/Currency"
+ }
+ ],
+ "nullable": true
+ },
+ "intent": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PaypalCaptureMethod"
+ }
+ ],
+ "nullable": true
}
}
},
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 9a43429837..733606e1ce 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -26319,6 +26319,13 @@
"propertyName": "field_type"
}
},
+ "PaypalCaptureMethod": {
+ "type": "string",
+ "enum": [
+ "capture",
+ "authorize"
+ ]
+ },
"PaypalFlow": {
"type": "string",
"enum": [
@@ -26373,6 +26380,22 @@
"type": "string",
"description": "User token required for returning customer flow, used by client to initiate sdk",
"nullable": true
+ },
+ "currency": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/Currency"
+ }
+ ],
+ "nullable": true
+ },
+ "intent": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PaypalCaptureMethod"
+ }
+ ],
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index d60ffc01b8..be888822ea 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -10390,6 +10390,28 @@ pub enum PaypalFlow {
Checkout,
}
+#[derive(
+ Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel,
+)]
+#[serde(rename_all = "snake_case")]
+#[smithy(namespace = "com.hyperswitch.smithy.types")]
+pub enum PaypalCaptureMethod {
+ Capture,
+ Authorize,
+}
+
+impl From<common_enums::CaptureMethod> for PaypalCaptureMethod {
+ fn from(from: common_enums::CaptureMethod) -> Self {
+ match from {
+ common_enums::CaptureMethod::SequentialAutomatic
+ | common_enums::CaptureMethod::Automatic => Self::Capture,
+ common_enums::CaptureMethod::Manual
+ | common_enums::CaptureMethod::ManualMultiple
+ | common_enums::CaptureMethod::Scheduled => Self::Authorize,
+ }
+ }
+}
+
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct PaypalTransactionInfo {
/// Paypal flow type
@@ -10424,6 +10446,14 @@ pub struct PaypalSessionTokenResponse {
pub transaction_info: Option<PaypalTransactionInfo>,
/// User token required for returning customer flow, used by client to initiate sdk
pub data_user_id_token: Option<String>,
+ /// Transaction currency code
+ #[schema(example = "USD", value_type = Option<Currency>)]
+ #[smithy(value_type = "Option<Currency>")]
+ pub currency: Option<common_enums::Currency>,
+ /// PayPal capture method
+ #[schema(value_type = Option<PaypalCaptureMethod>)]
+ #[smithy(value_type = "Option<PaypalCaptureMethod>")]
+ pub intent: Option<PaypalCaptureMethod>,
}
#[derive(
diff --git a/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs b/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
index 313c56a3fa..22c600a994 100644
--- a/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
@@ -1,6 +1,5 @@
use api_models::{
- payments as payment_types,
- payments::{ApplePaySessionResponse, SessionToken},
+ payments::{self as payment_types, ApplePaySessionResponse, PaypalCaptureMethod, SessionToken},
webhooks::IncomingWebhookEvent,
};
use common_enums::enums;
@@ -2004,6 +2003,8 @@ impl
)?,
},
),
+ currency: Some(data.request.currency),
+ intent: data.request.capture_method.map(PaypalCaptureMethod::from),
},
))
}
diff --git a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
index cb2e354489..0358b5372f 100644
--- a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
@@ -2,7 +2,10 @@
use api_models::payouts::{PayoutMethodData, Wallet as WalletPayout};
use api_models::{
enums,
- payments::{NextActionCall, PaypalSessionTokenResponse, SdkNextAction, SessionToken},
+ payments::{
+ NextActionCall, PaypalCaptureMethod, PaypalSessionTokenResponse, SdkNextAction,
+ SessionToken,
+ },
webhooks::IncomingWebhookEvent,
};
use base64::Engine;
@@ -1564,6 +1567,8 @@ impl
client_token: None,
data_user_id_token: response.id_token.clone().map(|id| id.expose()),
transaction_info: None,
+ currency: Some(data.request.currency),
+ intent: data.request.capture_method.map(PaypalCaptureMethod::from),
}));
Ok(Self {
response: Ok(PaymentsResponseData::SessionResponse { session_token }),
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index f1364a8477..46be0ab553 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -1722,6 +1722,7 @@ pub struct PaymentsSessionData {
pub amount: i64,
pub currency: common_enums::Currency,
pub country: Option<common_enums::CountryAlpha2>,
+ pub capture_method: Option<storage_enums::CaptureMethod>,
pub surcharge_details: Option<SurchargeDetails>,
pub order_details: Option<Vec<OrderDetailsWithAmount>>,
pub email: Option<pii::Email>,
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 5be2461f97..76668edf57 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -678,6 +678,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::GooglePayThirdPartySdkData,
api_models::payments::KlarnaSessionTokenResponse,
api_models::payments::PaypalSessionTokenResponse,
+ api_models::payments::PaypalCaptureMethod,
api_models::payments::PaypalFlow,
api_models::payments::PaypalTransactionInfo,
api_models::payments::ApplepaySessionTokenResponse,
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index 3e7d5143ff..59d9ddb700 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -579,6 +579,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::GooglePayThirdPartySdkData,
api_models::payments::KlarnaSessionTokenResponse,
api_models::payments::PaypalSessionTokenResponse,
+ api_models::payments::PaypalCaptureMethod,
api_models::payments::PaypalFlow,
api_models::payments::PaypalTransactionInfo,
api_models::payments::ApplepaySessionTokenResponse,
diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs
index a2fccaaff3..a8f11e0627 100644
--- a/crates/router/src/core/payments/flows/session_flow.rs
+++ b/crates/router/src/core/payments/flows/session_flow.rs
@@ -1,4 +1,7 @@
-use api_models::{admin as admin_types, payments as payment_types};
+use api_models::{
+ admin as admin_types,
+ payments::{self as payment_types, PaypalCaptureMethod},
+};
use async_trait::async_trait;
use common_utils::{
ext_traits::ByteSliceExt,
@@ -1401,6 +1404,11 @@ fn create_paypal_sdk_session_token(
data_user_id_token: None,
client_token: None,
transaction_info: None,
+ currency: Some(router_data.request.currency),
+ intent: router_data
+ .request
+ .capture_method
+ .map(PaypalCaptureMethod::from),
},
)),
}),
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index f53d87052a..7a31702819 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -1370,6 +1370,7 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>(
payment_method: None,
payment_method_type: None,
split_payments: payment_data.payment_intent.split_payments,
+ capture_method: Some(payment_data.payment_intent.capture_method),
};
// TODO: evaluate the fields in router data, if they are required or not
@@ -5911,6 +5912,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
payment_method: Some(payment_data.payment_attempt.payment_method_type),
payment_method_type: payment_data.payment_attempt.payment_method_subtype,
split_payments: payment_data.payment_intent.split_payments,
+ capture_method: Some(payment_data.payment_intent.capture_method),
})
}
}
@@ -6020,6 +6022,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
payment_method: payment_data.payment_attempt.payment_method,
payment_method_type: payment_data.payment_attempt.payment_method_type,
split_payments: payment_data.payment_intent.split_payments,
+ capture_method: payment_data.payment_attempt.capture_method,
})
}
}
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index f48addf7e3..6fbc0140dd 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -4880,6 +4880,8 @@ impl transformers::ForeignTryFrom<payments_grpc::ClientAuthenticationTokenData>
.transpose()?,
// todo UCS
data_user_id_token: None,
+ currency: None,
+ intent: None,
};
Ok(Self::Paypal(Box::new(paypal_session_token_response)))