1
1
pub mod transformers;
2
- use std:: convert:: TryFrom ;
3
-
4
2
use base64:: Engine ;
5
3
use common_enums:: enums;
6
4
use common_utils:: {
@@ -11,7 +9,7 @@ use common_utils::{
11
9
} ;
12
10
use error_stack:: { report, ResultExt } ;
13
11
use hyperswitch_domain_models:: {
14
- router_data:: { AccessToken , ConnectorAuthType , ErrorResponse , RouterData } ,
12
+ router_data:: { AccessToken , ErrorResponse , RouterData } ,
15
13
router_flow_types:: {
16
14
access_token_auth:: AccessTokenAuth ,
17
15
payments:: { Authorize , Capture , PSync , PaymentMethodToken , Session , SetupMandate , Void } ,
@@ -125,10 +123,6 @@ impl ConnectorCommon for Jpmorgan {
125
123
126
124
fn get_currency_unit ( & self ) -> api:: CurrencyUnit {
127
125
api:: CurrencyUnit :: Minor
128
- //todo!()
129
- // TODO! Check connector documentation, on which unit they are processing the currency.
130
- // If the connector accepts amount in lower unit ( i.e cents for USD) then return api::CurrencyUnit::Minor,
131
- // if connector accepts amount in base unit (i.e dollars for USD) then return api::CurrencyUnit::Base
132
126
}
133
127
134
128
fn common_get_content_type ( & self ) -> & ' static str {
@@ -139,18 +133,6 @@ impl ConnectorCommon for Jpmorgan {
139
133
connectors. jpmorgan . base_url . as_ref ( )
140
134
}
141
135
142
- fn get_auth_header (
143
- & self ,
144
- auth_type : & ConnectorAuthType ,
145
- ) -> CustomResult < Vec < ( String , Maskable < String > ) > , errors:: ConnectorError > {
146
- let auth = jpmorgan:: JpmorganAuthType :: try_from ( auth_type)
147
- . change_context ( errors:: ConnectorError :: FailedToObtainAuthType ) ?;
148
- Ok ( vec ! [ (
149
- headers:: AUTHORIZATION . to_string( ) ,
150
- auth. api_key. into_masked( ) ,
151
- ) ] )
152
- }
153
-
154
136
fn build_error_response (
155
137
& self ,
156
138
res : Response ,
@@ -181,7 +163,6 @@ impl ConnectorCommon for Jpmorgan {
181
163
}
182
164
183
165
impl ConnectorValidation for Jpmorgan {
184
- //TODO: implement functions when support enabled
185
166
fn validate_capture_method (
186
167
& self ,
187
168
capture_method : Option < enums:: CaptureMethod > ,
@@ -190,14 +171,13 @@ impl ConnectorValidation for Jpmorgan {
190
171
let capture_method = capture_method. unwrap_or_default ( ) ;
191
172
match capture_method {
192
173
enums:: CaptureMethod :: Automatic | enums:: CaptureMethod :: Manual => Ok ( ( ) ) ,
193
- //enums::CaptureMethod::ManualMultiple |
194
- enums:: CaptureMethod :: Scheduled | enums:: CaptureMethod :: SequentialAutomatic => Err (
195
- utils:: construct_not_implemented_error_report ( capture_method, self . id ( ) ) ,
196
- ) ,
197
- enums:: CaptureMethod :: ManualMultiple => Err ( errors:: ConnectorError :: NotImplemented (
198
- //ManualMultiple unimplemented
199
- utils:: get_unimplemented_payment_method_error_message ( "Jpmorgan" ) ,
200
- ) ) ?,
174
+ enums:: CaptureMethod :: ManualMultiple
175
+ | enums:: CaptureMethod :: Scheduled
176
+ | enums:: CaptureMethod :: SequentialAutomatic => {
177
+ Err ( errors:: ConnectorError :: NotImplemented (
178
+ utils:: get_unimplemented_payment_method_error_message ( "Jpmorgan" ) ,
179
+ ) ) ?
180
+ }
201
181
}
202
182
}
203
183
@@ -224,26 +204,7 @@ impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> fo
224
204
//TODO: implement sessions flow
225
205
}
226
206
227
- // use masking::Secret;
228
-
229
207
impl ConnectorIntegration < AccessTokenAuth , AccessTokenRequestData , AccessToken > for Jpmorgan {
230
- fn get_url (
231
- & self ,
232
- _req : & RefreshTokenRouterData ,
233
- connectors : & Connectors ,
234
- ) -> CustomResult < String , errors:: ConnectorError > {
235
- let access_token_url = connectors
236
- . jpmorgan
237
- . secondary_base_url
238
- . as_ref ( )
239
- . ok_or ( errors:: ConnectorError :: FailedToObtainIntegrationUrl ) ?;
240
- Ok ( access_token_url. to_string ( ) )
241
- }
242
-
243
- fn get_content_type ( & self ) -> & ' static str {
244
- "application/x-www-form-urlencoded"
245
- }
246
-
247
208
fn get_headers (
248
209
& self ,
249
210
req : & RefreshTokenRouterData ,
@@ -258,7 +219,6 @@ impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken>
258
219
client_id. peek( ) ,
259
220
client_secret. unwrap_or_default( ) . peek( )
260
221
) ;
261
- // let creds = format!("{}:{}", client_id.peek(), client_secret.unwrap_or_default().peek());
262
222
let encoded_creds = common_utils:: consts:: BASE64_ENGINE . encode ( creds) ;
263
223
264
224
let auth_string = format ! ( "Basic {}" , encoded_creds) ;
@@ -274,6 +234,23 @@ impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken>
274
234
] )
275
235
}
276
236
237
+ fn get_content_type ( & self ) -> & ' static str {
238
+ "application/x-www-form-urlencoded"
239
+ }
240
+
241
+ fn get_url (
242
+ & self ,
243
+ _req : & RefreshTokenRouterData ,
244
+ connectors : & Connectors ,
245
+ ) -> CustomResult < String , errors:: ConnectorError > {
246
+ let access_token_url = connectors
247
+ . jpmorgan
248
+ . secondary_base_url
249
+ . as_ref ( )
250
+ . ok_or ( errors:: ConnectorError :: FailedToObtainIntegrationUrl ) ?;
251
+ Ok ( access_token_url. to_string ( ) )
252
+ }
253
+
277
254
fn get_request_body (
278
255
& self ,
279
256
req : & RefreshTokenRouterData ,
@@ -353,8 +330,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
353
330
_req : & PaymentsAuthorizeRouterData ,
354
331
connectors : & Connectors ,
355
332
) -> CustomResult < String , errors:: ConnectorError > {
356
- let endpoint = self . base_url ( connectors) ;
357
- Ok ( format ! ( "{}/payments" , endpoint) )
333
+ Ok ( format ! ( "{}/payments" , self . base_url( connectors) ) )
358
334
}
359
335
360
336
fn get_request_body (
@@ -370,9 +346,6 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
370
346
371
347
let connector_router_data = jpmorgan:: JpmorganRouterData :: from ( ( amount, req) ) ;
372
348
let connector_req = jpmorgan:: JpmorganPaymentsRequest :: try_from ( & connector_router_data) ?;
373
- let _printrequest =
374
- common_utils:: ext_traits:: Encode :: encode_to_string_of_json ( & connector_req)
375
- . change_context ( errors:: ConnectorError :: RequestEncodingFailed ) ?;
376
349
Ok ( RequestContent :: Json ( Box :: new ( connector_req) ) )
377
350
}
378
351
@@ -444,10 +417,12 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
444
417
req : & PaymentsCaptureRouterData ,
445
418
connectors : & Connectors ,
446
419
) -> CustomResult < String , errors:: ConnectorError > {
447
- let endpoint = self . base_url ( connectors) ;
448
420
let tid = req. request . connector_transaction_id . clone ( ) ;
449
- Ok ( format ! ( "{}/payments/{}/captures" , endpoint, tid) )
450
- // Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
421
+ Ok ( format ! (
422
+ "{}/payments/{}/captures" ,
423
+ self . base_url( connectors) ,
424
+ tid
425
+ ) )
451
426
}
452
427
453
428
fn get_request_body (
@@ -463,9 +438,6 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
463
438
464
439
let connector_router_data = jpmorgan:: JpmorganRouterData :: from ( ( amount, req) ) ;
465
440
let connector_req = jpmorgan:: JpmorganCaptureRequest :: try_from ( & connector_router_data) ?;
466
- let _printrequest =
467
- common_utils:: ext_traits:: Encode :: encode_to_string_of_json ( & connector_req)
468
- . change_context ( errors:: ConnectorError :: RequestEncodingFailed ) ?;
469
441
Ok ( RequestContent :: Json ( Box :: new ( connector_req) ) )
470
442
}
471
443
@@ -540,8 +512,7 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Jpm
540
512
. connector_transaction_id
541
513
. get_connector_transaction_id ( )
542
514
. change_context ( errors:: ConnectorError :: MissingConnectorTransactionID ) ?;
543
- let endpoint = self . base_url ( connectors) ;
544
- Ok ( format ! ( "{}/payments/{}" , endpoint, tid) )
515
+ Ok ( format ! ( "{}/payments/{}" , self . base_url( connectors) , tid) )
545
516
}
546
517
547
518
fn build_request (
@@ -571,7 +542,6 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Jpm
571
542
. change_context ( errors:: ConnectorError :: ResponseDeserializationFailed ) ?;
572
543
event_builder. map ( |i| i. set_response_body ( & response) ) ;
573
544
router_env:: logger:: info!( connector_response=?response) ;
574
-
575
545
RouterData :: try_from ( ResponseRouterData {
576
546
response,
577
547
data : data. clone ( ) ,
@@ -606,9 +576,8 @@ impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Jp
606
576
req : & PaymentsCancelRouterData ,
607
577
connectors : & Connectors ,
608
578
) -> CustomResult < String , errors:: ConnectorError > {
609
- let endpoint = self . base_url ( connectors) ;
610
579
let tid = req. request . connector_transaction_id . clone ( ) ;
611
- Ok ( format ! ( "{}/payments/{}" , endpoint , tid) )
580
+ Ok ( format ! ( "{}/payments/{}" , self . base_url ( connectors ) , tid) )
612
581
}
613
582
614
583
fn get_request_body (
@@ -692,8 +661,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Jpmorga
692
661
_req : & RefundsRouterData < Execute > ,
693
662
connectors : & Connectors ,
694
663
) -> CustomResult < String , errors:: ConnectorError > {
695
- let endpoint = self . base_url ( connectors) ;
696
- Ok ( format ! ( "{}/refunds" , endpoint) )
664
+ Ok ( format ! ( "{}/refunds" , self . base_url( connectors) ) )
697
665
}
698
666
699
667
fn get_request_body (
@@ -776,9 +744,8 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Jpmorgan
776
744
req : & RefundSyncRouterData ,
777
745
connectors : & Connectors ,
778
746
) -> CustomResult < String , errors:: ConnectorError > {
779
- let endpoint = self . base_url ( connectors) ;
780
747
let tid = req. request . connector_transaction_id . clone ( ) ;
781
- Ok ( format ! ( "{}/refunds/{}" , endpoint , tid) )
748
+ Ok ( format ! ( "{}/refunds/{}" , self . base_url ( connectors ) , tid) )
782
749
}
783
750
fn build_request (
784
751
& self ,
0 commit comments