@@ -41,9 +41,10 @@ pub mod transformers;
4141pub const BASE64_ENGINE : base64:: engine:: GeneralPurpose = base64:: engine:: general_purpose:: STANDARD ;
4242
4343use transformers:: {
44- self as trustpay, TrustpayAuthUpdateRequest , TrustpayAuthUpdateResponse , TrustpayErrorResponse ,
44+ self as trustpay, RefundResponse , RefundResponse as RefundSyncResponse ,
45+ TrustpayAuthUpdateRequest , TrustpayAuthUpdateResponse , TrustpayErrorResponse ,
4546 TrustpayPaymentsRequest , TrustpayPaymentsResponse as TrustpayPaymentsSyncResponse ,
46- TrustpayPaymentsResponse ,
47+ TrustpayPaymentsResponse , TrustpayRefundRequest ,
4748} ;
4849
4950use super :: macros:: { self , ContentTypeSelector } ;
@@ -184,6 +185,17 @@ macros::create_all_prerequisites!(
184185 request_body: TrustpayPaymentsRequest <T >,
185186 response_body: TrustpayPaymentsResponse ,
186187 router_data: RouterDataV2 <Authorize , PaymentFlowData , PaymentsAuthorizeData <T >, PaymentsResponseData >,
188+ ) ,
189+ (
190+ flow: Refund ,
191+ request_body: TrustpayRefundRequest ,
192+ response_body: RefundResponse ,
193+ router_data: RouterDataV2 <Refund , RefundFlowData , RefundsData , RefundsResponseData >,
194+ ) ,
195+ (
196+ flow: RSync ,
197+ response_body: RefundSyncResponse ,
198+ router_data: RouterDataV2 <RSync , RefundFlowData , RefundSyncData , RefundsResponseData >,
187199 )
188200 ] ,
189201 amount_converters: [
@@ -229,6 +241,44 @@ macros::create_all_prerequisites!(
229241 }
230242 }
231243
244+ pub fn build_headers_for_refunds<F , Req , Res >(
245+ & self ,
246+ req: & RouterDataV2 <F , RefundFlowData , Req , Res >,
247+ ) -> CustomResult <Vec <( String , Maskable <String >) >, errors:: ConnectorError >
248+ where
249+ Self : ConnectorIntegrationV2 <F , RefundFlowData , Req , Res >,
250+ {
251+ match req. resource_common_data. payment_method {
252+ Some ( common_enums:: PaymentMethod :: BankRedirect ) | Some ( common_enums:: PaymentMethod :: BankTransfer ) => {
253+ let token = req
254+ . resource_common_data
255+ . get_access_token( )
256+ . change_context( errors:: ConnectorError :: MissingRequiredField {
257+ field_name: "access_token" ,
258+ } ) ?;
259+ Ok ( vec![
260+ (
261+ headers:: CONTENT_TYPE . to_string( ) ,
262+ "application/json" . to_owned( ) . into( ) ,
263+ ) ,
264+ (
265+ headers:: AUTHORIZATION . to_string( ) ,
266+ format!( "Bearer {token}" ) . into_masked( ) ,
267+ ) ,
268+ ] )
269+ }
270+ _ => {
271+ let mut header = vec![ (
272+ headers:: CONTENT_TYPE . to_string( ) ,
273+ self . get_content_type( ) . to_string( ) . into( ) ,
274+ ) ] ;
275+ let mut api_key = self . get_auth_header( & req. connector_auth_type) ?;
276+ header. append( & mut api_key) ;
277+ Ok ( header)
278+ }
279+ }
280+ }
281+
232282 pub fn connector_base_url_payments<' a, F , Req , Res >(
233283 & self ,
234284 req: & ' a RouterDataV2 <F , PaymentFlowData , Req , Res >,
@@ -243,6 +293,20 @@ macros::create_all_prerequisites!(
243293 & req. resource_common_data. connectors. trustpay. base_url_bank_redirects
244294 }
245295
296+ pub fn connector_base_url_bank_redirects_refunds<' a, F , Req , Res >(
297+ & self ,
298+ req: & ' a RouterDataV2 <F , RefundFlowData , Req , Res >,
299+ ) -> & ' a str {
300+ & req. resource_common_data. connectors. trustpay. base_url_bank_redirects
301+ }
302+
303+ pub fn connector_base_url_refunds<' a, F , Req , Res >(
304+ & self ,
305+ req: & ' a RouterDataV2 <F , RefundFlowData , Req , Res >,
306+ ) -> & ' a str {
307+ & req. resource_common_data. connectors. trustpay. base_url
308+ }
309+
246310 pub fn get_auth_header(
247311 & self ,
248312 auth_type: & ConnectorAuthType ,
@@ -547,19 +611,105 @@ macros::macro_connector_implementation!(
547611 }
548612) ;
549613
550- // Implementation for empty stubs - these will need to be properly implemented later
551-
552614impl < T : PaymentMethodDataTypes + Debug + Sync + Send + ' static + Serialize >
553- ConnectorIntegrationV2 < RSync , RefundFlowData , RefundSyncData , RefundsResponseData >
554- for Trustpay < T >
615+ ContentTypeSelector < Refund , RefundFlowData , RefundsData , RefundsResponseData > for Trustpay < T >
555616{
617+ fn get_dynamic_content_type (
618+ & self ,
619+ req : & RouterDataV2 < Refund , RefundFlowData , RefundsData , RefundsResponseData > ,
620+ ) -> CustomResult < common_enums:: DynamicContentType , errors:: ConnectorError > {
621+ match req. resource_common_data . payment_method {
622+ Some ( common_enums:: PaymentMethod :: BankRedirect )
623+ | Some ( common_enums:: PaymentMethod :: BankTransfer ) => {
624+ Ok ( common_enums:: DynamicContentType :: Json )
625+ }
626+ _ => Ok ( common_enums:: DynamicContentType :: FormUrlEncoded ) ,
627+ }
628+ }
556629}
557630
558- impl < T : PaymentMethodDataTypes + Debug + Sync + Send + ' static + Serialize >
559- ConnectorIntegrationV2 < Refund , RefundFlowData , RefundsData , RefundsResponseData >
560- for Trustpay < T >
561- {
562- }
631+ macros:: macro_connector_implementation!(
632+ connector_default_implementations: [ get_content_type, get_error_response_v2] ,
633+ connector: Trustpay ,
634+ curl_request: Dynamic ( TrustpayRefundRequest ) ,
635+ curl_response: RefundResponse ,
636+ flow_name: Refund ,
637+ resource_common_data: RefundFlowData ,
638+ flow_request: RefundsData ,
639+ flow_response: RefundsResponseData ,
640+ http_method: Post ,
641+ generic_type: T ,
642+ [ PaymentMethodDataTypes + Debug + Sync + Send + ' static + Serialize ] ,
643+ other_functions: {
644+ fn get_headers(
645+ & self ,
646+ req: & RouterDataV2 <Refund , RefundFlowData , RefundsData , RefundsResponseData >,
647+ ) -> CustomResult <Vec <( String , Maskable <String >) >, errors:: ConnectorError > {
648+ self . build_headers_for_refunds( req)
649+ }
650+
651+ fn get_url(
652+ & self ,
653+ req: & RouterDataV2 <Refund , RefundFlowData , RefundsData , RefundsResponseData >,
654+ ) -> CustomResult <String , errors:: ConnectorError > {
655+ match req. resource_common_data. payment_method {
656+ Some ( common_enums:: PaymentMethod :: BankRedirect ) | Some ( common_enums:: PaymentMethod :: BankTransfer ) => Ok ( format!(
657+ "{}{}{}{}" ,
658+ self . connector_base_url_bank_redirects_refunds( req) ,
659+ "api/Payments/Payment/" ,
660+ req. request. connector_transaction_id,
661+ "/Refund"
662+ ) ) ,
663+ _ => Ok ( format!( "{}{}" , self . connector_base_url_refunds( req) , "api/v1/Refund" ) ) ,
664+ }
665+ }
666+ }
667+ ) ;
668+
669+ macros:: macro_connector_implementation!(
670+ connector_default_implementations: [ get_content_type, get_error_response_v2] ,
671+ connector: Trustpay ,
672+ curl_response: RefundSyncResponse ,
673+ flow_name: RSync ,
674+ resource_common_data: RefundFlowData ,
675+ flow_request: RefundSyncData ,
676+ flow_response: RefundsResponseData ,
677+ http_method: Get ,
678+ generic_type: T ,
679+ [ PaymentMethodDataTypes + Debug + Sync + Send + ' static + Serialize ] ,
680+ other_functions: {
681+ fn get_headers(
682+ & self ,
683+ req: & RouterDataV2 <RSync , RefundFlowData , RefundSyncData , RefundsResponseData >,
684+ ) -> CustomResult <Vec <( String , Maskable <String >) >, errors:: ConnectorError > {
685+ self . build_headers_for_refunds( req)
686+ }
687+
688+ fn get_url(
689+ & self ,
690+ req: & RouterDataV2 <RSync , RefundFlowData , RefundSyncData , RefundsResponseData >,
691+ ) -> CustomResult <String , errors:: ConnectorError > {
692+ let id = req
693+ . request
694+ . connector_refund_id
695+ . clone( ) ;
696+ match req. resource_common_data. payment_method {
697+ Some ( common_enums:: PaymentMethod :: BankRedirect ) | Some ( common_enums:: PaymentMethod :: BankTransfer ) => Ok ( format!(
698+ "{}{}/{}" ,
699+ self . connector_base_url_bank_redirects_refunds( req) , "api/Payments/Payment" , id
700+ ) ) ,
701+ _ => Ok ( format!(
702+ "{}{}/{}" ,
703+ self . connector_base_url_refunds( req) ,
704+ "api/v1/instance" ,
705+ id
706+ ) ) ,
707+ }
708+ }
709+ }
710+ ) ;
711+
712+ // Implementation for empty stubs - these will need to be properly implemented later
563713
564714impl < T : PaymentMethodDataTypes + Debug + Sync + Send + ' static + Serialize >
565715 ConnectorIntegrationV2 <
@@ -634,7 +784,6 @@ impl<
634784 + std:: marker:: Sync
635785 + std:: marker:: Send
636786 + ' static
637- + Serialize
638787 + Serialize ,
639788 > ConnectorIntegrationV2 < Capture , PaymentFlowData , PaymentsCaptureData , PaymentsResponseData >
640789 for Trustpay < T >
0 commit comments