Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/hyperswitch_connectors/src/connectors/jpmorgan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Jpmorga
fn get_url(
&self,
_req: &RefundsRouterData<Execute>,
_connectors: &Connectors,
connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
Err(errors::ConnectorError::NotImplemented("Refunds".to_string()).into())
Ok(format!("{}/refunds", self.base_url(connectors)))
}

fn get_request_body(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,10 @@ pub struct JpmorganPaymentsResponse {
#[serde(rename_all = "camelCase")]
pub struct Merchant {
merchant_id: Option<String>,
merchant_software: MerchantSoftware,
merchant_software: JpmorganMerchantSoftware,
merchant_category_code: Option<String>,
}

#[derive(Default, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MerchantSoftware {
company_name: Secret<String>,
product_name: Secret<String>,
version: Option<Secret<String>>,
}

#[derive(Default, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentMethodType {
Expand Down Expand Up @@ -522,18 +514,31 @@ pub struct TransactionData {
pub struct JpmorganRefundRequest {
pub merchant: MerchantRefundReq,
pub amount: MinorUnit,
pub currency: common_enums::Currency,
}

#[derive(Default, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MerchantRefundReq {
pub merchant_software: MerchantSoftware,
pub merchant_software: JpmorganMerchantSoftware,
}

impl<F> TryFrom<&JpmorganRouterData<&RefundsRouterData<F>>> for JpmorganRefundRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(_item: &JpmorganRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
Err(errors::ConnectorError::NotImplemented("Refunds".to_string()).into())
fn try_from(item: &JpmorganRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
let merchant_software = JpmorganMerchantSoftware {
company_name: String::from("JPMC").into(),
product_name: String::from("Hyperswitch").into(),
};
let merchant = MerchantRefundReq { merchant_software };
let amount = item.amount;
let currency = item.router_data.request.currency;

Ok(Self {
merchant,
amount,
currency,
})
}
}

Expand Down Expand Up @@ -571,25 +576,25 @@ impl From<RefundStatus> for common_enums::RefundStatus {
}
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct RefundResponse {
id: String,
status: RefundStatus,
}

pub fn refund_status_from_transaction_state(
response_status: JpmorganResponseStatus,
transaction_state: JpmorganTransactionState,
) -> common_enums::RefundStatus {
match transaction_state {
JpmorganTransactionState::Voided | JpmorganTransactionState::Closed => {
common_enums::RefundStatus::Success
}
JpmorganTransactionState::Declined | JpmorganTransactionState::Error => {
match response_status {
JpmorganResponseStatus::Success => match transaction_state {
JpmorganTransactionState::Voided | JpmorganTransactionState::Closed => {
common_enums::RefundStatus::Success
}
JpmorganTransactionState::Declined | JpmorganTransactionState::Error => {
common_enums::RefundStatus::Failure
}
JpmorganTransactionState::Pending | JpmorganTransactionState::Authorized => {
common_enums::RefundStatus::Pending
}
},
JpmorganResponseStatus::Denied | JpmorganResponseStatus::Error => {
common_enums::RefundStatus::Failure
}
JpmorganTransactionState::Pending | JpmorganTransactionState::Authorized => {
common_enums::RefundStatus::Pending
}
}
}

Expand All @@ -608,6 +613,7 @@ impl TryFrom<RefundsResponseRouterData<Execute, JpmorganRefundResponse>>
.clone()
.ok_or(errors::ConnectorError::ResponseHandlingFailed)?,
refund_status: refund_status_from_transaction_state(
item.response.response_status,
item.response.transaction_state,
),
}),
Expand Down Expand Up @@ -639,6 +645,7 @@ impl TryFrom<RefundsResponseRouterData<RSync, JpmorganRefundSyncResponse>>
response: Ok(RefundsResponseData {
connector_refund_id: item.response.transaction_id.clone(),
refund_status: refund_status_from_transaction_state(
item.response.response_status,
item.response.transaction_state,
),
}),
Expand Down
50 changes: 15 additions & 35 deletions cypress-tests/cypress/e2e/configs/Payment/Jpmorgan.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,79 +200,59 @@ export const connectorDetails = {
Void: voidCase,
VoidAfterConfirm: voidCase,
Refund: {
Configs: {
TRIGGER_SKIP: true,
},
Request: {
amount: 6000,
},
Response: {
status: 501,
status: 200,
body: {
type: "invalid_request",
message: "Refunds is not implemented",
code: "IR_00",
reason: "FRAUD",
status: "pending",
},
},
},
manualPaymentRefund: {
Configs: {
TRIGGER_SKIP: true,
},
Request: {
amount: 6000,
},
Response: {
status: 501,
status: 200,
body: {
type: "invalid_request",
message: "Refunds is not implemented",
code: "IR_00",
reason: "FRAUD",
status: "pending",
},
},
},
manualPaymentPartialRefund: {
Configs: {
TRIGGER_SKIP: true,
},
Request: {
amount: 2000,
},
Response: {
status: 501,
status: 200,
body: {
type: "invalid_request",
message: "Refunds is not implemented",
code: "IR_00",
reason: "FRAUD",
status: "pending",
},
},
},
PartialRefund: {
Configs: {
TRIGGER_SKIP: true,
},
Request: {
amount: 2000,
},
Response: {
status: 501,
status: 200,
body: {
type: "invalid_request",
message: "Refunds is not implemented",
code: "IR_00",
reason: "FRAUD",
status: "pending",
},
},
},
SyncRefund: {
Configs: {
TRIGGER_SKIP: true,
},
Response: {
status: 404,
status: 200,
body: {
type: "invalid_request",
message: "Refund does not exist in our records.",
code: "HE_02",
reason: "FRAUD",
status: "succeeded",
},
},
},
Expand Down
Loading