@@ -27,6 +27,13 @@ use hyperswitch_domain_models::{
27
27
RefundSyncRouterData , RefundsRouterData ,
28
28
} ,
29
29
} ;
30
+ #[ cfg( all( feature = "v2" , feature = "revenue_recovery" ) ) ]
31
+ use hyperswitch_domain_models:: {
32
+ router_flow_types:: RecoveryRecordBack ,
33
+ router_request_types:: revenue_recovery:: RevenueRecoveryRecordBackRequest ,
34
+ router_response_types:: revenue_recovery:: RevenueRecoveryRecordBackResponse ,
35
+ types:: RevenueRecoveryRecordBackRouterData ,
36
+ } ;
30
37
use hyperswitch_interfaces:: {
31
38
api:: {
32
39
self , ConnectorCommon , ConnectorCommonExt , ConnectorIntegration , ConnectorSpecifications ,
@@ -68,6 +75,8 @@ impl api::Refund for Stripebilling {}
68
75
impl api:: RefundExecute for Stripebilling { }
69
76
impl api:: RefundSync for Stripebilling { }
70
77
impl api:: PaymentToken for Stripebilling { }
78
+ #[ cfg( all( feature = "revenue_recovery" , feature = "v2" ) ) ]
79
+ impl api:: revenue_recovery:: RevenueRecoveryRecordBack for Stripebilling { }
71
80
72
81
impl ConnectorIntegration < PaymentMethodToken , PaymentMethodTokenizationData , PaymentsResponseData >
73
82
for Stripebilling
@@ -550,6 +559,98 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Stripebil
550
559
}
551
560
}
552
561
562
+ #[ cfg( all( feature = "v2" , feature = "revenue_recovery" ) ) ]
563
+ impl
564
+ ConnectorIntegration <
565
+ RecoveryRecordBack ,
566
+ RevenueRecoveryRecordBackRequest ,
567
+ RevenueRecoveryRecordBackResponse ,
568
+ > for Stripebilling
569
+ {
570
+ fn get_headers (
571
+ & self ,
572
+ req : & RevenueRecoveryRecordBackRouterData ,
573
+ connectors : & Connectors ,
574
+ ) -> CustomResult < Vec < ( String , masking:: Maskable < String > ) > , errors:: ConnectorError > {
575
+ self . build_headers ( req, connectors)
576
+ }
577
+
578
+ fn get_content_type ( & self ) -> & ' static str {
579
+ self . common_get_content_type ( )
580
+ }
581
+
582
+ fn get_url (
583
+ & self ,
584
+ req : & RevenueRecoveryRecordBackRouterData ,
585
+ connectors : & Connectors ,
586
+ ) -> CustomResult < String , errors:: ConnectorError > {
587
+ let invoice_id = req
588
+ . request
589
+ . merchant_reference_id
590
+ . get_string_repr ( )
591
+ . to_string ( ) ;
592
+ match req. request . attempt_status {
593
+ common_enums:: AttemptStatus :: Charged => Ok ( format ! (
594
+ "{}/v1/invoices/{invoice_id}/pay?paid_out_of_band=true" ,
595
+ self . base_url( connectors) ,
596
+ ) ) ,
597
+ common_enums:: AttemptStatus :: Failure => Ok ( format ! (
598
+ "{}/v1/invoices/{invoice_id}/void" ,
599
+ self . base_url( connectors) ,
600
+ ) ) ,
601
+ _ => Err ( errors:: ConnectorError :: FailedToObtainIntegrationUrl . into ( ) ) ,
602
+ }
603
+ }
604
+
605
+ fn build_request (
606
+ & self ,
607
+ req : & RevenueRecoveryRecordBackRouterData ,
608
+ connectors : & Connectors ,
609
+ ) -> CustomResult < Option < Request > , errors:: ConnectorError > {
610
+ Ok ( Some (
611
+ RequestBuilder :: new ( )
612
+ . method ( Method :: Post )
613
+ . url ( & types:: RevenueRecoveryRecordBackType :: get_url (
614
+ self , req, connectors,
615
+ ) ?)
616
+ . attach_default_headers ( )
617
+ . headers ( types:: RevenueRecoveryRecordBackType :: get_headers (
618
+ self , req, connectors,
619
+ ) ?)
620
+ . build ( ) ,
621
+ ) )
622
+ }
623
+
624
+ fn handle_response (
625
+ & self ,
626
+ data : & RevenueRecoveryRecordBackRouterData ,
627
+ event_builder : Option < & mut ConnectorEvent > ,
628
+ res : Response ,
629
+ ) -> CustomResult < RevenueRecoveryRecordBackRouterData , errors:: ConnectorError > {
630
+ let response = res
631
+ . response
632
+ . parse_struct :: < stripebilling:: StripebillingRecordBackResponse > (
633
+ "StripebillingRecordBackResponse" ,
634
+ )
635
+ . change_context ( errors:: ConnectorError :: ResponseDeserializationFailed ) ?;
636
+ event_builder. map ( |i| i. set_response_body ( & response) ) ;
637
+ router_env:: logger:: info!( connector_response=?response) ;
638
+ RevenueRecoveryRecordBackRouterData :: try_from ( ResponseRouterData {
639
+ response,
640
+ data : data. clone ( ) ,
641
+ http_code : res. status_code ,
642
+ } )
643
+ }
644
+
645
+ fn get_error_response (
646
+ & self ,
647
+ res : Response ,
648
+ event_builder : Option < & mut ConnectorEvent > ,
649
+ ) -> CustomResult < ErrorResponse , errors:: ConnectorError > {
650
+ self . build_error_response ( res, event_builder)
651
+ }
652
+ }
653
+
553
654
#[ async_trait:: async_trait]
554
655
impl webhooks:: IncomingWebhook for Stripebilling {
555
656
fn get_webhook_source_verification_algorithm (
0 commit comments