Skip to content

Commit 7391416

Browse files
refactor(core): updated payments response with payment_method_id & payment_method_status (#3883)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 614182a commit 7391416

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+277
-65
lines changed

crates/api_models/src/payments.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,13 @@ pub struct PaymentsResponse {
27172717

27182718
/// Payment Fingerprint
27192719
pub fingerprint: Option<String>,
2720+
2721+
/// Payment Method Id
2722+
pub payment_method_id: Option<String>,
2723+
2724+
/// Payment Method Status
2725+
#[schema(value_type = Option<PaymentMethodStatus>)]
2726+
pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
27202727
}
27212728

27222729
#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]

crates/common_enums/src/enums.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,36 @@ pub enum PaymentMethodStatus {
12051205
Processing,
12061206
}
12071207

1208+
impl From<AttemptStatus> for PaymentMethodStatus {
1209+
fn from(attempt_status: AttemptStatus) -> Self {
1210+
match attempt_status {
1211+
AttemptStatus::Charged | AttemptStatus::Authorized => Self::Active,
1212+
AttemptStatus::Failure => Self::Inactive,
1213+
AttemptStatus::Voided
1214+
| AttemptStatus::Started
1215+
| AttemptStatus::Pending
1216+
| AttemptStatus::Unresolved
1217+
| AttemptStatus::CodInitiated
1218+
| AttemptStatus::Authorizing
1219+
| AttemptStatus::VoidInitiated
1220+
| AttemptStatus::AuthorizationFailed
1221+
| AttemptStatus::RouterDeclined
1222+
| AttemptStatus::AuthenticationSuccessful
1223+
| AttemptStatus::PaymentMethodAwaited
1224+
| AttemptStatus::AuthenticationFailed
1225+
| AttemptStatus::AuthenticationPending
1226+
| AttemptStatus::CaptureInitiated
1227+
| AttemptStatus::CaptureFailed
1228+
| AttemptStatus::VoidFailed
1229+
| AttemptStatus::AutoRefunded
1230+
| AttemptStatus::PartialCharged
1231+
| AttemptStatus::PartialChargedAndChargeable
1232+
| AttemptStatus::ConfirmationAwaited
1233+
| AttemptStatus::DeviceDataCollectionPending => Self::Processing,
1234+
}
1235+
}
1236+
}
1237+
12081238
/// To indicate the type of payment experience that the customer would go through
12091239
#[derive(
12101240
Eq,

crates/data_models/src/payments/payment_attempt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ pub enum PaymentAttemptUpdate {
323323
authentication_id: Option<String>,
324324
payment_method_billing_address_id: Option<String>,
325325
fingerprint_id: Option<String>,
326+
payment_method_id: Option<String>,
326327
},
327328
RejectUpdate {
328329
status: storage_enums::AttemptStatus,

crates/diesel_models/src/payment_attempt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub enum PaymentAttemptUpdate {
226226
fingerprint_id: Option<String>,
227227
updated_by: String,
228228
merchant_connector_id: Option<String>,
229+
payment_method_id: Option<String>,
229230
external_three_ds_authentication_attempted: Option<bool>,
230231
authentication_connector: Option<String>,
231232
authentication_id: Option<String>,
@@ -574,6 +575,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
574575
authentication_id,
575576
payment_method_billing_address_id,
576577
fingerprint_id,
578+
payment_method_id,
577579
} => Self {
578580
amount: Some(amount),
579581
currency: Some(currency),
@@ -601,6 +603,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
601603
authentication_id,
602604
payment_method_billing_address_id,
603605
fingerprint_id,
606+
payment_method_id: payment_method_id.map(Some),
604607
..Default::default()
605608
},
606609
PaymentAttemptUpdate::VoidUpdate {

crates/openapi/src/openapi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ Never share your secret api keys. Keep them guarded and secure.
229229
api_models::enums::ReconStatus,
230230
api_models::enums::ConnectorStatus,
231231
api_models::enums::AuthorizationStatus,
232+
api_models::enums::PaymentMethodStatus,
232233
api_models::admin::MerchantConnectorCreate,
233234
api_models::admin::MerchantConnectorUpdate,
234235
api_models::admin::PrimaryBusinessDetails,

crates/router/src/core/authentication/transformers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub fn construct_router_data<F: Clone, Req, Res>(
170170
frm_metadata: None,
171171
dispute_id: None,
172172
refund_id: None,
173+
payment_method_status: None,
173174
})
174175
}
175176

crates/router/src/core/fraud_check/flows/checkout_flow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
6464
description: None,
6565
return_url: None,
6666
payment_method_id: None,
67+
payment_method_status: None,
6768
address: self.address.clone(),
6869
auth_type: storage_enums::AuthenticationType::NoThreeDs,
6970
connector_meta_data: None,

crates/router/src/core/fraud_check/flows/fulfillment_flow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub async fn construct_fulfillment_router_data<'a>(
7676
auth_type: payment_attempt.authentication_type.unwrap_or_default(),
7777
connector_meta_data: merchant_connector_account.get_metadata(),
7878
amount_captured: payment_intent.amount_captured,
79+
payment_method_status: None,
7980
request: FraudCheckFulfillmentData {
8081
amount: payment_attempt.amount,
8182
order_details: payment_intent.order_details.clone(),

crates/router/src/core/fraud_check/flows/record_return.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
8484
payment_method_token: None,
8585
connector_customer: None,
8686
preprocessing_id: None,
87+
payment_method_status: None,
8788
connector_request_reference_id: uuid::Uuid::new_v4().to_string(),
8889
test_mode: None,
8990
recurring_mandate_payment_data: None,

crates/router/src/core/fraud_check/flows/sale_flow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
8080
payment_method_token: None,
8181
connector_customer: None,
8282
preprocessing_id: None,
83+
payment_method_status: None,
8384
connector_request_reference_id: uuid::Uuid::new_v4().to_string(),
8485
test_mode: None,
8586
recurring_mandate_payment_data: None,

0 commit comments

Comments
 (0)