Skip to content

Commit fa28b59

Browse files
Sayak BhattacharyaSayak Bhattacharya
authored andcommitted
requested changes made
1 parent a818e57 commit fa28b59

File tree

4 files changed

+91
-213
lines changed

4 files changed

+91
-213
lines changed

crates/connector_configs/toml/development.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,8 @@ key2="Certificate Key"
17691769
[[jpmorgan.debit]]
17701770
payment_method_type = "Visa"
17711771
[jpmorgan.connector_auth.BodyKey]
1772-
api_key="Access Token"
1772+
api_key="Client ID"
1773+
key1="Client Secret"
17731774

17741775
[klarna]
17751776
[[klarna.pay_later]]

crates/hyperswitch_connectors/src/connectors/jpmorgan.rs

Lines changed: 35 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
pub mod transformers;
2-
use std::convert::TryFrom;
3-
42
use base64::Engine;
53
use common_enums::enums;
64
use common_utils::{
@@ -11,7 +9,7 @@ use common_utils::{
119
};
1210
use error_stack::{report, ResultExt};
1311
use hyperswitch_domain_models::{
14-
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
12+
router_data::{AccessToken, ErrorResponse, RouterData},
1513
router_flow_types::{
1614
access_token_auth::AccessTokenAuth,
1715
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
@@ -125,10 +123,6 @@ impl ConnectorCommon for Jpmorgan {
125123

126124
fn get_currency_unit(&self) -> api::CurrencyUnit {
127125
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
132126
}
133127

134128
fn common_get_content_type(&self) -> &'static str {
@@ -139,18 +133,6 @@ impl ConnectorCommon for Jpmorgan {
139133
connectors.jpmorgan.base_url.as_ref()
140134
}
141135

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-
154136
fn build_error_response(
155137
&self,
156138
res: Response,
@@ -181,7 +163,6 @@ impl ConnectorCommon for Jpmorgan {
181163
}
182164

183165
impl ConnectorValidation for Jpmorgan {
184-
//TODO: implement functions when support enabled
185166
fn validate_capture_method(
186167
&self,
187168
capture_method: Option<enums::CaptureMethod>,
@@ -190,14 +171,13 @@ impl ConnectorValidation for Jpmorgan {
190171
let capture_method = capture_method.unwrap_or_default();
191172
match capture_method {
192173
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+
}
201181
}
202182
}
203183

@@ -224,26 +204,7 @@ impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> fo
224204
//TODO: implement sessions flow
225205
}
226206

227-
// use masking::Secret;
228-
229207
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-
247208
fn get_headers(
248209
&self,
249210
req: &RefreshTokenRouterData,
@@ -258,7 +219,6 @@ impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken>
258219
client_id.peek(),
259220
client_secret.unwrap_or_default().peek()
260221
);
261-
// let creds = format!("{}:{}", client_id.peek(), client_secret.unwrap_or_default().peek());
262222
let encoded_creds = common_utils::consts::BASE64_ENGINE.encode(creds);
263223

264224
let auth_string = format!("Basic {}", encoded_creds);
@@ -274,6 +234,23 @@ impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken>
274234
])
275235
}
276236

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+
277254
fn get_request_body(
278255
&self,
279256
req: &RefreshTokenRouterData,
@@ -353,8 +330,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
353330
_req: &PaymentsAuthorizeRouterData,
354331
connectors: &Connectors,
355332
) -> CustomResult<String, errors::ConnectorError> {
356-
let endpoint = self.base_url(connectors);
357-
Ok(format!("{}/payments", endpoint))
333+
Ok(format!("{}/payments", self.base_url(connectors)))
358334
}
359335

360336
fn get_request_body(
@@ -370,9 +346,6 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
370346

371347
let connector_router_data = jpmorgan::JpmorganRouterData::from((amount, req));
372348
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)?;
376349
Ok(RequestContent::Json(Box::new(connector_req)))
377350
}
378351

@@ -444,10 +417,12 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
444417
req: &PaymentsCaptureRouterData,
445418
connectors: &Connectors,
446419
) -> CustomResult<String, errors::ConnectorError> {
447-
let endpoint = self.base_url(connectors);
448420
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+
))
451426
}
452427

453428
fn get_request_body(
@@ -463,9 +438,6 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
463438

464439
let connector_router_data = jpmorgan::JpmorganRouterData::from((amount, req));
465440
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)?;
469441
Ok(RequestContent::Json(Box::new(connector_req)))
470442
}
471443

@@ -540,8 +512,7 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Jpm
540512
.connector_transaction_id
541513
.get_connector_transaction_id()
542514
.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))
545516
}
546517

547518
fn build_request(
@@ -571,7 +542,6 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Jpm
571542
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
572543
event_builder.map(|i| i.set_response_body(&response));
573544
router_env::logger::info!(connector_response=?response);
574-
575545
RouterData::try_from(ResponseRouterData {
576546
response,
577547
data: data.clone(),
@@ -606,9 +576,8 @@ impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Jp
606576
req: &PaymentsCancelRouterData,
607577
connectors: &Connectors,
608578
) -> CustomResult<String, errors::ConnectorError> {
609-
let endpoint = self.base_url(connectors);
610579
let tid = req.request.connector_transaction_id.clone();
611-
Ok(format!("{}/payments/{}", endpoint, tid))
580+
Ok(format!("{}/payments/{}", self.base_url(connectors), tid))
612581
}
613582

614583
fn get_request_body(
@@ -692,8 +661,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Jpmorga
692661
_req: &RefundsRouterData<Execute>,
693662
connectors: &Connectors,
694663
) -> CustomResult<String, errors::ConnectorError> {
695-
let endpoint = self.base_url(connectors);
696-
Ok(format!("{}/refunds", endpoint))
664+
Ok(format!("{}/refunds", self.base_url(connectors)))
697665
}
698666

699667
fn get_request_body(
@@ -776,9 +744,8 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Jpmorgan
776744
req: &RefundSyncRouterData,
777745
connectors: &Connectors,
778746
) -> CustomResult<String, errors::ConnectorError> {
779-
let endpoint = self.base_url(connectors);
780747
let tid = req.request.connector_transaction_id.clone();
781-
Ok(format!("{}/refunds/{}", endpoint, tid))
748+
Ok(format!("{}/refunds/{}", self.base_url(connectors), tid))
782749
}
783750
fn build_request(
784751
&self,

0 commit comments

Comments
 (0)