Skip to content

Commit 537d175

Browse files
bsayak03Sayak Bhattacharya
andauthored
fix(connector): [TRUSTPAY] Consuming Amount in PSync Response (#8455)
Co-authored-by: Sayak Bhattacharya <[email protected]>
1 parent b185d85 commit 537d175

File tree

2 files changed

+59
-29
lines changed

2 files changed

+59
-29
lines changed

crates/hyperswitch_connectors/src/connectors/trustpay.rs

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -423,40 +423,69 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Tru
423423
.parse_struct("trustpay PaymentsResponse")
424424
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
425425

426-
if let trustpay::TrustpayPaymentsResponse::WebhookResponse(ref webhook_response) = response
427-
{
428-
let response_integrity_object = connector_utils::get_sync_integrity_object(
429-
self.amount_converter_to_float_major_unit,
430-
webhook_response.amount.amount,
431-
webhook_response.amount.currency.to_string(),
432-
)?;
433-
434-
event_builder.map(|i| i.set_response_body(&response));
435-
router_env::logger::info!(connector_response=?response);
436-
437-
let new_router_data = RouterData::try_from(ResponseRouterData {
438-
response,
439-
data: data.clone(),
440-
http_code: res.status_code,
441-
});
442-
443-
return new_router_data
426+
match &response {
427+
trustpay::TrustpayPaymentsResponse::WebhookResponse(webhook_response) => {
428+
let response_integrity_object = connector_utils::get_sync_integrity_object(
429+
self.amount_converter_to_float_major_unit,
430+
webhook_response.amount.amount,
431+
webhook_response.amount.currency.to_string(),
432+
)?;
433+
434+
event_builder.map(|i| i.set_response_body(&response));
435+
router_env::logger::info!(connector_response=?response);
436+
437+
RouterData::try_from(ResponseRouterData {
438+
response,
439+
data: data.clone(),
440+
http_code: res.status_code,
441+
})
444442
.map(|mut router_data| {
445443
router_data.request.integrity_object = Some(response_integrity_object);
446444
router_data
447445
})
448-
.change_context(errors::ConnectorError::ResponseHandlingFailed);
449-
}
446+
.change_context(errors::ConnectorError::ResponseHandlingFailed)
447+
}
450448

451-
event_builder.map(|i| i.set_response_body(&response));
452-
router_env::logger::info!(connector_response=?response);
449+
trustpay::TrustpayPaymentsResponse::BankRedirectSync(bank_redirect_sync_response) => {
450+
let response_integrity_object = connector_utils::get_sync_integrity_object(
451+
self.amount_converter_to_float_major_unit,
452+
bank_redirect_sync_response
453+
.payment_information
454+
.amount
455+
.amount,
456+
bank_redirect_sync_response
457+
.payment_information
458+
.amount
459+
.currency
460+
.to_string(),
461+
)?;
462+
463+
event_builder.map(|i| i.set_response_body(&response));
464+
router_env::logger::info!(connector_response=?response);
465+
466+
RouterData::try_from(ResponseRouterData {
467+
response,
468+
data: data.clone(),
469+
http_code: res.status_code,
470+
})
471+
.map(|mut router_data| {
472+
router_data.request.integrity_object = Some(response_integrity_object);
473+
router_data
474+
})
475+
.change_context(errors::ConnectorError::ResponseHandlingFailed)
476+
}
453477

454-
RouterData::try_from(ResponseRouterData {
455-
response,
456-
data: data.clone(),
457-
http_code: res.status_code,
458-
})
459-
.change_context(errors::ConnectorError::ResponseHandlingFailed)
478+
_ => {
479+
event_builder.map(|i| i.set_response_body(&response));
480+
router_env::logger::info!(connector_response=?response);
481+
RouterData::try_from(ResponseRouterData {
482+
response,
483+
data: data.clone(),
484+
http_code: res.status_code,
485+
})
486+
.change_context(errors::ConnectorError::ResponseHandlingFailed)
487+
}
488+
}
460489
}
461490
}
462491

crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ pub struct BankPaymentInformation {
147147
pub debtor: Option<DebtorInformation>,
148148
}
149149

150-
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
150+
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
151151
#[serde(rename_all = "PascalCase")]
152152
pub struct BankPaymentInformationResponse {
153153
pub status: TrustpayBankRedirectPaymentStatus,
154154
pub status_reason_information: Option<StatusReasonInformation>,
155155
pub references: ReferencesResponse,
156+
pub amount: WebhookAmount,
156157
}
157158

158159
#[derive(Debug, Serialize, Eq, PartialEq)]

0 commit comments

Comments
 (0)