feat(connector): add support for surcharge in trustpay (#2581)

This commit is contained in:
Hrithikesh
2023-10-16 14:30:43 +05:30
committed by GitHub
parent f43ed3c1b9
commit 2d5d3b8efb
10 changed files with 67 additions and 4 deletions

View File

@ -301,11 +301,21 @@ pub struct PaymentsRequest {
/// associated with the merchant account will be used.
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
#[schema(value_type = Option<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)]
pub struct HeaderPayload {
pub payment_confirm_source: Option<api_enums::PaymentSource>,

View File

@ -430,8 +430,13 @@ impl
&self,
req: &types::PaymentsPreProcessingRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let amount = req.request.get_amount()?;
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((
&self.get_currency_unit(),
currency,
@ -542,10 +547,16 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
&self,
req: &types::PaymentsAuthorizeRouterData,
) -> 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((
&self.get_currency_unit(),
req.request.currency,
req.request.amount,
amount,
req,
))?;
let connector_req = trustpay::TrustpayPaymentsRequest::try_from(&connector_router_data)?;

View File

@ -381,6 +381,7 @@ impl TryFrom<types::PaymentsAuthorizeData> for types::PaymentsPreProcessingData
webhook_url: data.webhook_url,
complete_authorize_url: data.complete_authorize_url,
browser_info: data.browser_info,
surcharge_details: data.surcharge_details,
})
}
}

View File

@ -549,7 +549,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
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 {
status: multiple_capture_data.get_attempt_status(authorized_amount),

View File

@ -1418,6 +1418,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
webhook_url,
complete_authorize_url,
browser_info,
surcharge_details: payment_data.surcharge_details,
})
}
}

View File

@ -6,7 +6,7 @@ pub mod compatibility;
pub mod configs;
pub mod connection;
pub mod connector;
pub(crate) mod consts;
pub mod consts;
pub mod core;
pub mod cors;
pub mod db;

View File

@ -297,6 +297,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::SepaBankTransferInstructions,
api_models::payments::BacsBankTransferInstructions,
api_models::payments::RedirectResponse,
api_models::payments::RequestSurchargeDetails,
api_models::payments::PaymentAttemptResponse,
api_models::payments::CaptureResponse,
api_models::payment_methods::RequiredFieldInfo,

View File

@ -439,6 +439,7 @@ pub struct PaymentsPreProcessingData {
pub router_return_url: Option<String>,
pub webhook_url: Option<String>,
pub complete_authorize_url: Option<String>,
pub surcharge_details: Option<api_models::payment_methods::SurchargeDetailsResponse>,
pub browser_info: Option<BrowserInformation>,
}

View File

@ -17,6 +17,7 @@ pub trait PaymentAttemptExt {
fn get_next_capture_id(&self) -> String;
fn get_intent_status(&self, amount_captured: Option<i64>) -> enums::IntentStatus;
fn get_total_amount(&self) -> i64;
}
impl PaymentAttemptExt for PaymentAttempt {
@ -67,6 +68,10 @@ impl PaymentAttemptExt for PaymentAttempt {
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 {

View File

@ -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.",
"nullable": true
},
"surcharge_details": {
"allOf": [
{
"$ref": "#/components/schemas/RequestSurchargeDetails"
}
],
"nullable": true
},
"payment_type": {
"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.",
"nullable": true
},
"surcharge_details": {
"allOf": [
{
"$ref": "#/components/schemas/RequestSurchargeDetails"
}
],
"nullable": true
},
"payment_type": {
"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": {
"type": "object",
"description": "Required fields info used while listing the payment_method_data",