1
1
pub mod transformers;
2
2
3
- use std:: collections:: { HashMap , HashSet } ;
3
+ use std:: {
4
+ any:: type_name,
5
+ borrow:: Cow ,
6
+ collections:: { HashMap , HashSet } ,
7
+ } ;
4
8
5
9
use common_enums:: { CaptureMethod , PaymentMethod , PaymentMethodType } ;
6
10
use common_utils:: {
@@ -53,6 +57,40 @@ use crate::{
53
57
utils:: { self , PaymentMethodDataType } ,
54
58
} ;
55
59
60
+ pub fn parse_and_log_keys_in_url_encoded_response < T > ( data : & [ u8 ] ) {
61
+ match std:: str:: from_utf8 ( data) {
62
+ Ok ( query_str) => {
63
+ let loggable_keys = [
64
+ "status" ,
65
+ "orderid" ,
66
+ "tranID" ,
67
+ "nbcb" ,
68
+ "amount" ,
69
+ "currency" ,
70
+ "paydate" ,
71
+ "channel" ,
72
+ "error_desc" ,
73
+ "error_code" ,
74
+ "extraP" ,
75
+ ] ;
76
+ let keys: Vec < ( Cow < ' _ , str > , String ) > =
77
+ url:: form_urlencoded:: parse ( query_str. as_bytes ( ) )
78
+ . map ( |( key, value) | {
79
+ if loggable_keys. contains ( & key. to_string ( ) . as_str ( ) ) {
80
+ ( key, value. to_string ( ) )
81
+ } else {
82
+ ( key, "SECRET" . to_string ( ) )
83
+ }
84
+ } )
85
+ . collect ( ) ;
86
+ router_env:: logger:: info!( "Keys in {} response\n {:?}" , type_name:: <T >( ) , keys) ;
87
+ }
88
+ Err ( err) => {
89
+ router_env:: logger:: error!( "Failed to convert bytes to string: {:?}" , err) ;
90
+ }
91
+ }
92
+ }
93
+
56
94
fn parse_response < T > ( data : & [ u8 ] ) -> Result < T , errors:: ConnectorError >
57
95
where
58
96
T : for < ' de > Deserialize < ' de > ,
@@ -87,6 +125,27 @@ where
87
125
json. insert ( "miscellaneous" . to_string ( ) , misc_value) ;
88
126
}
89
127
128
+ // TODO: Remove this after debugging
129
+ let loggable_keys = [
130
+ "StatCode" ,
131
+ "StatName" ,
132
+ "TranID" ,
133
+ "ErrorCode" ,
134
+ "ErrorDesc" ,
135
+ "miscellaneous" ,
136
+ ] ;
137
+ let keys: Vec < ( & str , Value ) > = json
138
+ . iter ( )
139
+ . map ( |( key, value) | {
140
+ if loggable_keys. contains ( & key. as_str ( ) ) {
141
+ ( key. as_str ( ) , value. to_owned ( ) )
142
+ } else {
143
+ ( key. as_str ( ) , Value :: String ( "SECRET" . to_string ( ) ) )
144
+ }
145
+ } )
146
+ . collect ( ) ;
147
+ router_env:: logger:: info!( "Keys in response for type {}\n {:?}" , type_name:: <T >( ) , keys) ;
148
+
90
149
let response: T = serde_json:: from_value ( Value :: Object ( json) ) . map_err ( |e| {
91
150
router_env:: logger:: error!( "Error in Deserializing Response Data: {:?}" , e) ;
92
151
errors:: ConnectorError :: ResponseDeserializationFailed
@@ -747,6 +806,7 @@ impl webhooks::IncomingWebhook for Fiuu {
747
806
) -> CustomResult < Vec < u8 > , errors:: ConnectorError > {
748
807
let header = utils:: get_header_key_value ( "content-type" , request. headers ) ?;
749
808
let resource: FiuuWebhooksResponse = if header == "application/x-www-form-urlencoded" {
809
+ parse_and_log_keys_in_url_encoded_response :: < FiuuWebhooksResponse > ( request. body ) ;
750
810
serde_urlencoded:: from_bytes :: < FiuuWebhooksResponse > ( request. body )
751
811
. change_context ( errors:: ConnectorError :: WebhookSourceVerificationFailed ) ?
752
812
} else {
@@ -776,6 +836,7 @@ impl webhooks::IncomingWebhook for Fiuu {
776
836
) -> CustomResult < Vec < u8 > , errors:: ConnectorError > {
777
837
let header = utils:: get_header_key_value ( "content-type" , request. headers ) ?;
778
838
let resource: FiuuWebhooksResponse = if header == "application/x-www-form-urlencoded" {
839
+ parse_and_log_keys_in_url_encoded_response :: < FiuuWebhooksResponse > ( request. body ) ;
779
840
serde_urlencoded:: from_bytes :: < FiuuWebhooksResponse > ( request. body )
780
841
. change_context ( errors:: ConnectorError :: WebhookSourceVerificationFailed ) ?
781
842
} else {
@@ -833,6 +894,7 @@ impl webhooks::IncomingWebhook for Fiuu {
833
894
) -> CustomResult < api_models:: webhooks:: ObjectReferenceId , errors:: ConnectorError > {
834
895
let header = utils:: get_header_key_value ( "content-type" , request. headers ) ?;
835
896
let resource: FiuuWebhooksResponse = if header == "application/x-www-form-urlencoded" {
897
+ parse_and_log_keys_in_url_encoded_response :: < FiuuWebhooksResponse > ( request. body ) ;
836
898
serde_urlencoded:: from_bytes :: < FiuuWebhooksResponse > ( request. body )
837
899
. change_context ( errors:: ConnectorError :: WebhookReferenceIdNotFound ) ?
838
900
} else {
@@ -866,6 +928,7 @@ impl webhooks::IncomingWebhook for Fiuu {
866
928
) -> CustomResult < api_models:: webhooks:: IncomingWebhookEvent , errors:: ConnectorError > {
867
929
let header = utils:: get_header_key_value ( "content-type" , request. headers ) ?;
868
930
let resource: FiuuWebhooksResponse = if header == "application/x-www-form-urlencoded" {
931
+ parse_and_log_keys_in_url_encoded_response :: < FiuuWebhooksResponse > ( request. body ) ;
869
932
serde_urlencoded:: from_bytes :: < FiuuWebhooksResponse > ( request. body )
870
933
. change_context ( errors:: ConnectorError :: WebhookEventTypeNotFound ) ?
871
934
} else {
@@ -891,6 +954,7 @@ impl webhooks::IncomingWebhook for Fiuu {
891
954
) -> CustomResult < Box < dyn masking:: ErasedMaskSerialize > , errors:: ConnectorError > {
892
955
let header = utils:: get_header_key_value ( "content-type" , request. headers ) ?;
893
956
let payload: FiuuWebhooksResponse = if header == "application/x-www-form-urlencoded" {
957
+ parse_and_log_keys_in_url_encoded_response :: < FiuuWebhooksResponse > ( request. body ) ;
894
958
serde_urlencoded:: from_bytes :: < FiuuWebhooksResponse > ( request. body )
895
959
. change_context ( errors:: ConnectorError :: WebhookResourceObjectNotFound ) ?
896
960
} else {
@@ -921,6 +985,9 @@ impl webhooks::IncomingWebhook for Fiuu {
921
985
Option < hyperswitch_domain_models:: router_flow_types:: ConnectorMandateDetails > ,
922
986
errors:: ConnectorError ,
923
987
> {
988
+ parse_and_log_keys_in_url_encoded_response :: < transformers:: FiuuWebhooksPaymentResponse > (
989
+ request. body ,
990
+ ) ;
924
991
let webhook_payment_response: transformers:: FiuuWebhooksPaymentResponse =
925
992
serde_urlencoded:: from_bytes :: < transformers:: FiuuWebhooksPaymentResponse > ( request. body )
926
993
. change_context ( errors:: ConnectorError :: WebhookResourceObjectNotFound ) ?;
0 commit comments