mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 17:47:54 +08:00
feat(connector): add support for surcharge in trustpay (#2581)
This commit is contained in:
@ -301,11 +301,21 @@ pub struct PaymentsRequest {
|
|||||||
/// associated with the merchant account will be used.
|
/// associated with the merchant account will be used.
|
||||||
pub profile_id: Option<String>,
|
pub profile_id: Option<String>,
|
||||||
|
|
||||||
|
/// surcharge_details for this payment
|
||||||
|
#[schema(value_type = Option<RequestSurchargeDetails>)]
|
||||||
|
pub surcharge_details: Option<RequestSurchargeDetails>,
|
||||||
|
|
||||||
/// The type of the payment that differentiates between normal and various types of mandate payments
|
/// The type of the payment that differentiates between normal and various types of mandate payments
|
||||||
#[schema(value_type = Option<PaymentType>)]
|
#[schema(value_type = Option<PaymentType>)]
|
||||||
pub payment_type: Option<api_enums::PaymentType>,
|
pub payment_type: Option<api_enums::PaymentType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize, Copy, ToSchema)]
|
||||||
|
pub struct RequestSurchargeDetails {
|
||||||
|
pub surcharge_amount: i64,
|
||||||
|
pub tax_amount: Option<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Copy)]
|
#[derive(Default, Debug, Clone, Copy)]
|
||||||
pub struct HeaderPayload {
|
pub struct HeaderPayload {
|
||||||
pub payment_confirm_source: Option<api_enums::PaymentSource>,
|
pub payment_confirm_source: Option<api_enums::PaymentSource>,
|
||||||
|
|||||||
@ -430,8 +430,13 @@ impl
|
|||||||
&self,
|
&self,
|
||||||
req: &types::PaymentsPreProcessingRouterData,
|
req: &types::PaymentsPreProcessingRouterData,
|
||||||
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
||||||
let amount = req.request.get_amount()?;
|
|
||||||
let currency = req.request.get_currency()?;
|
let currency = req.request.get_currency()?;
|
||||||
|
let amount = req
|
||||||
|
.request
|
||||||
|
.surcharge_details
|
||||||
|
.as_ref()
|
||||||
|
.map(|surcharge_details| surcharge_details.final_amount)
|
||||||
|
.unwrap_or(req.request.get_amount()?);
|
||||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((
|
let connector_router_data = trustpay::TrustpayRouterData::try_from((
|
||||||
&self.get_currency_unit(),
|
&self.get_currency_unit(),
|
||||||
currency,
|
currency,
|
||||||
@ -542,10 +547,16 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
|||||||
&self,
|
&self,
|
||||||
req: &types::PaymentsAuthorizeRouterData,
|
req: &types::PaymentsAuthorizeRouterData,
|
||||||
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
||||||
|
let amount = req
|
||||||
|
.request
|
||||||
|
.surcharge_details
|
||||||
|
.as_ref()
|
||||||
|
.map(|surcharge_details| surcharge_details.final_amount)
|
||||||
|
.unwrap_or(req.request.amount);
|
||||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((
|
let connector_router_data = trustpay::TrustpayRouterData::try_from((
|
||||||
&self.get_currency_unit(),
|
&self.get_currency_unit(),
|
||||||
req.request.currency,
|
req.request.currency,
|
||||||
req.request.amount,
|
amount,
|
||||||
req,
|
req,
|
||||||
))?;
|
))?;
|
||||||
let connector_req = trustpay::TrustpayPaymentsRequest::try_from(&connector_router_data)?;
|
let connector_req = trustpay::TrustpayPaymentsRequest::try_from(&connector_router_data)?;
|
||||||
|
|||||||
@ -381,6 +381,7 @@ impl TryFrom<types::PaymentsAuthorizeData> for types::PaymentsPreProcessingData
|
|||||||
webhook_url: data.webhook_url,
|
webhook_url: data.webhook_url,
|
||||||
complete_authorize_url: data.complete_authorize_url,
|
complete_authorize_url: data.complete_authorize_url,
|
||||||
browser_info: data.browser_info,
|
browser_info: data.browser_info,
|
||||||
|
surcharge_details: data.surcharge_details,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -549,7 +549,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
|
|||||||
multiple_capture_data.update_capture(updated_capture);
|
multiple_capture_data.update_capture(updated_capture);
|
||||||
}
|
}
|
||||||
|
|
||||||
let authorized_amount = payment_data.payment_attempt.amount;
|
let authorized_amount = payment_data.payment_attempt.get_total_amount();
|
||||||
|
|
||||||
payment_attempt_update = Some(storage::PaymentAttemptUpdate::AmountToCaptureUpdate {
|
payment_attempt_update = Some(storage::PaymentAttemptUpdate::AmountToCaptureUpdate {
|
||||||
status: multiple_capture_data.get_attempt_status(authorized_amount),
|
status: multiple_capture_data.get_attempt_status(authorized_amount),
|
||||||
|
|||||||
@ -1418,6 +1418,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
|
|||||||
webhook_url,
|
webhook_url,
|
||||||
complete_authorize_url,
|
complete_authorize_url,
|
||||||
browser_info,
|
browser_info,
|
||||||
|
surcharge_details: payment_data.surcharge_details,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ pub mod compatibility;
|
|||||||
pub mod configs;
|
pub mod configs;
|
||||||
pub mod connection;
|
pub mod connection;
|
||||||
pub mod connector;
|
pub mod connector;
|
||||||
pub(crate) mod consts;
|
pub mod consts;
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod cors;
|
pub mod cors;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|||||||
@ -297,6 +297,7 @@ Never share your secret api keys. Keep them guarded and secure.
|
|||||||
api_models::payments::SepaBankTransferInstructions,
|
api_models::payments::SepaBankTransferInstructions,
|
||||||
api_models::payments::BacsBankTransferInstructions,
|
api_models::payments::BacsBankTransferInstructions,
|
||||||
api_models::payments::RedirectResponse,
|
api_models::payments::RedirectResponse,
|
||||||
|
api_models::payments::RequestSurchargeDetails,
|
||||||
api_models::payments::PaymentAttemptResponse,
|
api_models::payments::PaymentAttemptResponse,
|
||||||
api_models::payments::CaptureResponse,
|
api_models::payments::CaptureResponse,
|
||||||
api_models::payment_methods::RequiredFieldInfo,
|
api_models::payment_methods::RequiredFieldInfo,
|
||||||
|
|||||||
@ -439,6 +439,7 @@ pub struct PaymentsPreProcessingData {
|
|||||||
pub router_return_url: Option<String>,
|
pub router_return_url: Option<String>,
|
||||||
pub webhook_url: Option<String>,
|
pub webhook_url: Option<String>,
|
||||||
pub complete_authorize_url: Option<String>,
|
pub complete_authorize_url: Option<String>,
|
||||||
|
pub surcharge_details: Option<api_models::payment_methods::SurchargeDetailsResponse>,
|
||||||
pub browser_info: Option<BrowserInformation>,
|
pub browser_info: Option<BrowserInformation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@ pub trait PaymentAttemptExt {
|
|||||||
|
|
||||||
fn get_next_capture_id(&self) -> String;
|
fn get_next_capture_id(&self) -> String;
|
||||||
fn get_intent_status(&self, amount_captured: Option<i64>) -> enums::IntentStatus;
|
fn get_intent_status(&self, amount_captured: Option<i64>) -> enums::IntentStatus;
|
||||||
|
fn get_total_amount(&self) -> i64;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PaymentAttemptExt for PaymentAttempt {
|
impl PaymentAttemptExt for PaymentAttempt {
|
||||||
@ -67,6 +68,10 @@ impl PaymentAttemptExt for PaymentAttempt {
|
|||||||
intent_status
|
intent_status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_total_amount(&self) -> i64 {
|
||||||
|
self.amount + self.surcharge_amount.unwrap_or(0) + self.tax_amount.unwrap_or(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AttemptStatusExt {
|
pub trait AttemptStatusExt {
|
||||||
|
|||||||
@ -8900,6 +8900,14 @@
|
|||||||
"description": "The business profile to use for this payment, if not passed the default business profile\nassociated with the merchant account will be used.",
|
"description": "The business profile to use for this payment, if not passed the default business profile\nassociated with the merchant account will be used.",
|
||||||
"nullable": true
|
"nullable": true
|
||||||
},
|
},
|
||||||
|
"surcharge_details": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/RequestSurchargeDetails"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
"payment_type": {
|
"payment_type": {
|
||||||
"allOf": [
|
"allOf": [
|
||||||
{
|
{
|
||||||
@ -9256,6 +9264,14 @@
|
|||||||
"description": "The business profile to use for this payment, if not passed the default business profile\nassociated with the merchant account will be used.",
|
"description": "The business profile to use for this payment, if not passed the default business profile\nassociated with the merchant account will be used.",
|
||||||
"nullable": true
|
"nullable": true
|
||||||
},
|
},
|
||||||
|
"surcharge_details": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/RequestSurchargeDetails"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
"payment_type": {
|
"payment_type": {
|
||||||
"allOf": [
|
"allOf": [
|
||||||
{
|
{
|
||||||
@ -10644,6 +10660,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"RequestSurchargeDetails": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"surcharge_amount"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"surcharge_amount": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
},
|
||||||
|
"tax_amount": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"nullable": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"RequiredFieldInfo": {
|
"RequiredFieldInfo": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Required fields info used while listing the payment_method_data",
|
"description": "Required fields info used while listing the payment_method_data",
|
||||||
|
|||||||
Reference in New Issue
Block a user