@@ -20,21 +20,25 @@ use hyperswitch_domain_models::{
2020 router_data:: { AccessToken , ConnectorAuthType , ErrorResponse , RouterData } ,
2121 router_flow_types:: {
2222 access_token_auth:: AccessTokenAuth ,
23- payments:: { Authorize , Capture , PSync , PaymentMethodToken , Session , SetupMandate , Void } ,
23+ payments:: {
24+ Authorize , Capture , CreateConnectorCustomer , PSync , PaymentMethodToken , Session ,
25+ SetupMandate , Void ,
26+ } ,
2427 refunds:: { Execute , RSync } ,
2528 } ,
2629 router_request_types:: {
27- AccessTokenRequestData , PaymentMethodTokenizationData , PaymentsAuthorizeData ,
28- PaymentsCancelData , PaymentsCaptureData , PaymentsSessionData , PaymentsSyncData ,
29- RefundsData , SetupMandateRequestData ,
30+ AccessTokenRequestData , ConnectorCustomerData , PaymentMethodTokenizationData ,
31+ PaymentsAuthorizeData , PaymentsCancelData , PaymentsCaptureData , PaymentsSessionData ,
32+ PaymentsSyncData , RefundsData , SetupMandateRequestData ,
3033 } ,
3134 router_response_types:: {
3235 ConnectorInfo , PaymentMethodDetails , PaymentsResponseData , RefundsResponseData ,
3336 SupportedPaymentMethods , SupportedPaymentMethodsExt ,
3437 } ,
3538 types:: {
36- PaymentsAuthorizeRouterData , PaymentsCancelRouterData , PaymentsCaptureRouterData ,
37- PaymentsSyncRouterData , RefundSyncRouterData , RefundsRouterData , SetupMandateRouterData ,
39+ ConnectorCustomerRouterData , PaymentsAuthorizeRouterData , PaymentsCancelRouterData ,
40+ PaymentsCaptureRouterData , PaymentsSyncRouterData , RefundSyncRouterData , RefundsRouterData ,
41+ SetupMandateRouterData ,
3842 } ,
3943} ;
4044use hyperswitch_interfaces:: {
@@ -45,7 +49,7 @@ use hyperswitch_interfaces::{
4549 configs:: Connectors ,
4650 errors,
4751 events:: connector_api_logs:: ConnectorEvent ,
48- types:: { self , PaymentsVoidType , Response , SetupMandateType } ,
52+ types:: { self , ConnectorCustomerType , PaymentsVoidType , Response , SetupMandateType } ,
4953 webhooks,
5054} ;
5155use masking:: { ExposeInterface , Mask } ;
@@ -78,6 +82,88 @@ impl api::Refund for Payload {}
7882impl api:: RefundExecute for Payload { }
7983impl api:: RefundSync for Payload { }
8084impl api:: PaymentToken for Payload { }
85+ impl api:: ConnectorCustomer for Payload { }
86+
87+ impl ConnectorIntegration < CreateConnectorCustomer , ConnectorCustomerData , PaymentsResponseData >
88+ for Payload
89+ {
90+ fn get_headers (
91+ & self ,
92+ req : & ConnectorCustomerRouterData ,
93+ _connectors : & Connectors ,
94+ ) -> CustomResult < Vec < ( String , masking:: Maskable < String > ) > , errors:: ConnectorError > {
95+ let mut header = vec ! [ (
96+ headers:: CONTENT_TYPE . to_string( ) ,
97+ "application/json" . to_string( ) . into( ) ,
98+ ) ] ;
99+ let mut api_key = self . get_auth_header ( & req. connector_auth_type ) ?;
100+ header. append ( & mut api_key) ;
101+ Ok ( header)
102+ }
103+ fn get_url (
104+ & self ,
105+ _req : & ConnectorCustomerRouterData ,
106+ connectors : & Connectors ,
107+ ) -> CustomResult < String , errors:: ConnectorError > {
108+ Ok ( format ! ( "{}/customers" , self . base_url( connectors) , ) )
109+ }
110+
111+ fn get_request_body (
112+ & self ,
113+ req : & ConnectorCustomerRouterData ,
114+ _connectors : & Connectors ,
115+ ) -> CustomResult < RequestContent , errors:: ConnectorError > {
116+ let connector_req = requests:: CustomerRequest :: try_from ( req) ?;
117+ Ok ( RequestContent :: Json ( Box :: new ( connector_req) ) )
118+ }
119+
120+ fn build_request (
121+ & self ,
122+ req : & ConnectorCustomerRouterData ,
123+ connectors : & Connectors ,
124+ ) -> CustomResult < Option < Request > , errors:: ConnectorError > {
125+ Ok ( Some (
126+ RequestBuilder :: new ( )
127+ . method ( Method :: Post )
128+ . url ( & ConnectorCustomerType :: get_url ( self , req, connectors) ?)
129+ . attach_default_headers ( )
130+ . headers ( ConnectorCustomerType :: get_headers ( self , req, connectors) ?)
131+ . set_body ( ConnectorCustomerType :: get_request_body (
132+ self , req, connectors,
133+ ) ?)
134+ . build ( ) ,
135+ ) )
136+ }
137+
138+ fn handle_response (
139+ & self ,
140+ data : & ConnectorCustomerRouterData ,
141+ event_builder : Option < & mut ConnectorEvent > ,
142+ res : Response ,
143+ ) -> CustomResult < ConnectorCustomerRouterData , errors:: ConnectorError > {
144+ let response: responses:: CustomerResponse =
145+ res. response
146+ . parse_struct ( "CustomerResponse" )
147+ . change_context ( errors:: ConnectorError :: ResponseDeserializationFailed ) ?;
148+
149+ event_builder. map ( |i| i. set_response_body ( & response) ) ;
150+ router_env:: logger:: info!( connector_response=?response) ;
151+
152+ RouterData :: try_from ( ResponseRouterData {
153+ response,
154+ data : data. clone ( ) ,
155+ http_code : res. status_code ,
156+ } )
157+ }
158+
159+ fn get_error_response (
160+ & self ,
161+ res : Response ,
162+ event_builder : Option < & mut ConnectorEvent > ,
163+ ) -> CustomResult < ErrorResponse , errors:: ConnectorError > {
164+ self . build_error_response ( res, event_builder)
165+ }
166+ }
81167
82168impl ConnectorIntegration < PaymentMethodToken , PaymentMethodTokenizationData , PaymentsResponseData >
83169 for Payload
@@ -962,4 +1048,14 @@ impl ConnectorSpecifications for Payload {
9621048 fn get_supported_webhook_flows ( & self ) -> Option < & ' static [ enums:: EventClass ] > {
9631049 Some ( & PAYLOAD_SUPPORTED_WEBHOOK_FLOWS )
9641050 }
1051+ fn should_call_connector_customer (
1052+ & self ,
1053+ payment_attempt : & hyperswitch_domain_models:: payments:: payment_attempt:: PaymentAttempt ,
1054+ ) -> bool {
1055+ #[ cfg( feature = "v1" ) ]
1056+ return payment_attempt. customer_acceptance . is_some ( )
1057+ && payment_attempt. setup_future_usage_applied == Some ( enums:: FutureUsage :: OffSession ) ;
1058+ #[ cfg( feature = "v2" ) ]
1059+ return false ;
1060+ }
9651061}
0 commit comments