@@ -469,6 +469,24 @@ pub fn parse_url_encoded_to_struct(
469
469
Ok ( response)
470
470
}
471
471
472
+ pub fn parse_url_encoded_to_capture_struct (
473
+ query_bytes : Bytes ,
474
+ ) -> Result < PayboxCaptureResponse , errors:: ConnectorError > {
475
+ let query_string = String :: from_utf8_lossy ( & query_bytes) ;
476
+ let parsed: std:: collections:: HashMap < String , String > =
477
+ url:: form_urlencoded:: parse ( query_string. as_bytes ( ) )
478
+ . map ( |( k, v) | ( k. to_string ( ) , v. to_string ( ) ) )
479
+ . collect ( ) ;
480
+
481
+ let json_string =
482
+ serde_json:: to_string ( & parsed) . map_err ( |_e| errors:: ConnectorError :: ParsingFailed ) ?;
483
+
484
+ let response: PayboxCaptureResponse =
485
+ serde_json:: from_str ( & json_string) . map_err ( |_e| errors:: ConnectorError :: ParsingFailed ) ?;
486
+
487
+ Ok ( response)
488
+ }
489
+
472
490
pub fn parse_url_encoded_to_syn_struct (
473
491
query_bytes : Bytes ,
474
492
) -> Result < PayboxSyncResponse , errors:: ConnectorError > {
@@ -524,6 +542,64 @@ pub struct PayboxSyncResponse {
524
542
pub status : PayboxStatus ,
525
543
}
526
544
545
+ #[ derive( Default , Debug , Clone , Serialize , Deserialize , PartialEq ) ]
546
+ pub struct PayboxCaptureResponse {
547
+ #[ serde( rename = "NUMTRANS" ) ]
548
+ pub transaction_number : String ,
549
+
550
+ #[ serde( rename = "NUMAPPEL" ) ]
551
+ pub call_number : String ,
552
+
553
+ #[ serde( rename = "CODEREPONSE" ) ]
554
+ pub response_code : String ,
555
+
556
+ #[ serde( rename = "COMMENTAIRE" ) ]
557
+ pub response_message : String ,
558
+ }
559
+
560
+ impl < F , T >
561
+ TryFrom < types:: ResponseRouterData < F , PayboxCaptureResponse , T , types:: PaymentsResponseData > >
562
+ for types:: RouterData < F , T , types:: PaymentsResponseData >
563
+ {
564
+ type Error = error_stack:: Report < errors:: ConnectorError > ;
565
+ fn try_from (
566
+ item : types:: ResponseRouterData < F , PayboxCaptureResponse , T , types:: PaymentsResponseData > ,
567
+ ) -> Result < Self , Self :: Error > {
568
+ let response = item. response . clone ( ) ;
569
+ let status = get_status_of_request ( response. response_code . clone ( ) ) ;
570
+ match status {
571
+ true => Ok ( Self {
572
+ status : enums:: AttemptStatus :: Pending ,
573
+ response : Ok ( types:: PaymentsResponseData :: TransactionResponse {
574
+ resource_id : types:: ResponseId :: ConnectorTransactionId ( response. call_number ) ,
575
+ redirection_data : None ,
576
+ mandate_reference : None ,
577
+ connector_metadata : Some ( serde_json:: json!( PayboxMeta {
578
+ connector_request_id: response. transaction_number. clone( )
579
+ } ) ) ,
580
+ network_txn_id : None ,
581
+ connector_response_reference_id : Some ( response. transaction_number ) ,
582
+ incremental_authorization_allowed : None ,
583
+ charge_id : None ,
584
+ } ) ,
585
+ amount_captured : None ,
586
+ ..item. data
587
+ } ) ,
588
+ false => Ok ( Self {
589
+ response : Err ( types:: ErrorResponse {
590
+ code : response. response_code . clone ( ) ,
591
+ message : response. response_message . clone ( ) ,
592
+ reason : Some ( response. response_message ) ,
593
+ status_code : item. http_code ,
594
+ attempt_status : None ,
595
+ connector_transaction_id : Some ( item. response . transaction_number ) ,
596
+ } ) ,
597
+ ..item. data
598
+ } ) ,
599
+ }
600
+ }
601
+ }
602
+
527
603
impl < F , T > TryFrom < types:: ResponseRouterData < F , PayboxResponse , T , types:: PaymentsResponseData > >
528
604
for types:: RouterData < F , T , types:: PaymentsResponseData >
529
605
{
0 commit comments