|
1 | 1 | pub mod transformers;
|
2 |
| - |
3 | 2 | use base64::Engine;
|
4 | 3 | use common_enums::{enums, PaymentAction};
|
5 | 4 | use common_utils::{
|
@@ -51,7 +50,7 @@ use transformers as trustpay;
|
51 | 50 | use crate::{
|
52 | 51 | constants::headers,
|
53 | 52 | types::ResponseRouterData,
|
54 |
| - utils::{self, ConnectorErrorType, PaymentsPreProcessingRequestData}, |
| 53 | + utils::{self, self as connector_utils, ConnectorErrorType, PaymentsPreProcessingRequestData}, |
55 | 54 | };
|
56 | 55 |
|
57 | 56 | #[derive(Clone)]
|
@@ -415,6 +414,34 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Tru
|
415 | 414 | .parse_struct("trustpay PaymentsResponse")
|
416 | 415 | .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
417 | 416 |
|
| 417 | + if let trustpay::TrustpayPaymentsResponse::WebhookResponse(ref webhook_response) = response |
| 418 | + { |
| 419 | + let amount = StringMajorUnit::f64_to_string_major_unit(webhook_response.amount.amount); |
| 420 | + let currency = webhook_response.amount.currency; |
| 421 | + |
| 422 | + let response_integrity_object = connector_utils::get_sync_integrity_object( |
| 423 | + self.amount_converter, |
| 424 | + amount, |
| 425 | + currency.to_string(), |
| 426 | + )?; |
| 427 | + |
| 428 | + event_builder.map(|i| i.set_response_body(&response)); |
| 429 | + router_env::logger::info!(connector_response=?response); |
| 430 | + |
| 431 | + let new_router_data = RouterData::try_from(ResponseRouterData { |
| 432 | + response, |
| 433 | + data: data.clone(), |
| 434 | + http_code: res.status_code, |
| 435 | + }); |
| 436 | + |
| 437 | + return new_router_data |
| 438 | + .map(|mut router_data| { |
| 439 | + router_data.request.integrity_object = Some(response_integrity_object); |
| 440 | + router_data |
| 441 | + }) |
| 442 | + .change_context(errors::ConnectorError::ResponseHandlingFailed); |
| 443 | + } |
| 444 | + |
418 | 445 | event_builder.map(|i| i.set_response_body(&response));
|
419 | 446 | router_env::logger::info!(connector_response=?response);
|
420 | 447 |
|
@@ -801,6 +828,32 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Trustpay
|
801 | 828 | .parse_struct("trustpay RefundResponse")
|
802 | 829 | .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
803 | 830 |
|
| 831 | + if let trustpay::RefundResponse::WebhookRefund(ref webhook_response) = response { |
| 832 | + let currency = webhook_response.amount.currency; |
| 833 | + |
| 834 | + let amount = StringMajorUnit::f64_to_string_major_unit(webhook_response.amount.amount); |
| 835 | + let response_integrity_object = connector_utils::get_refund_integrity_object( |
| 836 | + self.amount_converter, |
| 837 | + amount, |
| 838 | + currency.to_string(), |
| 839 | + )?; |
| 840 | + |
| 841 | + event_builder.map(|i| i.set_response_body(&response)); |
| 842 | + router_env::logger::info!(connector_response=?response); |
| 843 | + |
| 844 | + let new_router_data = RouterData::try_from(ResponseRouterData { |
| 845 | + response, |
| 846 | + data: data.clone(), |
| 847 | + http_code: res.status_code, |
| 848 | + }); |
| 849 | + |
| 850 | + return new_router_data |
| 851 | + .map(|mut router_data| { |
| 852 | + router_data.request.integrity_object = Some(response_integrity_object); |
| 853 | + router_data |
| 854 | + }) |
| 855 | + .change_context(errors::ConnectorError::ResponseHandlingFailed); |
| 856 | + } |
804 | 857 | event_builder.map(|i| i.set_response_body(&response));
|
805 | 858 | router_env::logger::info!(connector_response=?response);
|
806 | 859 |
|
|
0 commit comments