Skip to content

Commit

Permalink
feat(connector): worldpay - add dynamic fields and update terminal st…
Browse files Browse the repository at this point in the history
…atus mapping (#6468)
  • Loading branch information
kashif-m authored Nov 28, 2024
1 parent 707f48c commit 5a98ed6
Show file tree
Hide file tree
Showing 17 changed files with 564 additions and 176 deletions.
4 changes: 2 additions & 2 deletions crates/diesel_models/src/query/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ impl PaymentAttempt {
#[cfg(feature = "v1")]
pub async fn find_by_connector_transaction_id_payment_id_merchant_id(
conn: &PgPooledConn,
connector_transaction_id: &str,
connector_transaction_id: &common_utils::types::ConnectorTransactionId,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::connector_transaction_id
.eq(connector_transaction_id.to_owned())
.eq(connector_transaction_id.get_id().to_owned())
.and(dsl::payment_id.eq(payment_id.to_owned()))
.and(dsl::merchant_id.eq(merchant_id.to_owned())),
)
Expand Down
4 changes: 2 additions & 2 deletions crates/hyperswitch_connectors/src/connectors/worldpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
.map(|id| id.to_string())
});
Ok(PaymentsCaptureRouterData {
status: enums::AttemptStatus::Pending,
status: enums::AttemptStatus::from(response.outcome.clone()),
response: Ok(PaymentsResponseData::TransactionResponse {
resource_id: ResponseId::foreign_try_from((
response,
Expand Down Expand Up @@ -967,12 +967,12 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Worldpa
});
Ok(RefundExecuteRouterData {
response: Ok(RefundsResponseData {
refund_status: enums::RefundStatus::from(response.outcome.clone()),
connector_refund_id: ResponseIdStr::foreign_try_from((
response,
optional_correlation_id,
))?
.id,
refund_status: enums::RefundStatus::Pending,
}),
..data.clone()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl From<PaymentOutcome> for enums::AttemptStatus {
fn from(item: PaymentOutcome) -> Self {
match item {
PaymentOutcome::Authorized => Self::Authorized,
PaymentOutcome::SentForSettlement => Self::CaptureInitiated,
PaymentOutcome::SentForSettlement => Self::Charged,
PaymentOutcome::ThreeDsDeviceDataRequired => Self::DeviceDataCollectionPending,
PaymentOutcome::ThreeDsAuthenticationFailed => Self::AuthenticationFailed,
PaymentOutcome::ThreeDsChallenged => Self::AuthenticationPending,
Expand All @@ -574,20 +574,38 @@ impl From<PaymentOutcome> for enums::AttemptStatus {
}
}

impl From<PaymentOutcome> for enums::RefundStatus {
fn from(item: PaymentOutcome) -> Self {
match item {
PaymentOutcome::SentForPartialRefund | PaymentOutcome::SentForRefund => Self::Success,
PaymentOutcome::Refused
| PaymentOutcome::FraudHighRisk
| PaymentOutcome::Authorized
| PaymentOutcome::SentForSettlement
| PaymentOutcome::ThreeDsDeviceDataRequired
| PaymentOutcome::ThreeDsAuthenticationFailed
| PaymentOutcome::ThreeDsChallenged
| PaymentOutcome::SentForCancellation
| PaymentOutcome::ThreeDsUnavailable => Self::Failure,
}
}
}

impl From<&EventType> for enums::AttemptStatus {
fn from(value: &EventType) -> Self {
match value {
EventType::SentForAuthorization => Self::Authorizing,
EventType::SentForSettlement => Self::CaptureInitiated,
EventType::SentForSettlement => Self::Charged,
EventType::Settled => Self::Charged,
EventType::Authorized => Self::Authorized,
EventType::Refused | EventType::SettlementFailed => Self::Failure,
EventType::Cancelled
| EventType::SentForRefund
EventType::Refused
| EventType::SettlementFailed
| EventType::Expired
| EventType::Cancelled
| EventType::Error => Self::Failure,
EventType::SentForRefund
| EventType::RefundFailed
| EventType::Refunded
| EventType::Error
| EventType::Expired
| EventType::Unknown => Self::Pending,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub trait PaymentAttemptInterface {
#[cfg(feature = "v1")]
async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
&self,
connector_transaction_id: &str,
connector_transaction_id: &ConnectorTransactionId,
payment_id: &id_type::PaymentId,
merchant_id: &id_type::MerchantId,
storage_scheme: storage_enums::MerchantStorageScheme,
Expand Down
Loading

0 comments on commit 5a98ed6

Please sign in to comment.