mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(connector): add support for surcharge in trustpay (#2581)
This commit is contained in:
@ -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)?;
|
||||
|
||||
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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>,
|
||||
}
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user