Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): updated payments response with payment_method_id & payment_method_status #3883

Merged
merged 53 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
357839d
chore: updated payment's response with pm_id
prajjwalkumar17 Feb 29, 2024
4fbcbfe
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Feb 29, 2024
4caaa73
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Feb 29, 2024
eecca8f
chore: updated payment's response with pm_status
prajjwalkumar17 Feb 29, 2024
b9e4404
Merge branch 'feat/core_pm_id_in_response' of https://github.com/jusp…
prajjwalkumar17 Feb 29, 2024
bde1ef5
chore: run formatter
hyperswitch-bot[bot] Feb 29, 2024
a4b55c4
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Feb 29, 2024
4fe11d5
chore: updated payment's response with pm_status
prajjwalkumar17 Mar 1, 2024
56a7aeb
chore: updated payment's response with pm_status
prajjwalkumar17 Mar 1, 2024
2597535
chore: run formatter
hyperswitch-bot[bot] Mar 1, 2024
23c2b77
chore: updated openapi spec
prajjwalkumar17 Mar 1, 2024
29db657
chore: updated openapi spec
prajjwalkumar17 Mar 1, 2024
2bd0a61
chore: updated openapi spec
prajjwalkumar17 Mar 1, 2024
0a4ea1d
chore: updated openapi spec
prajjwalkumar17 Mar 1, 2024
8590483
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 1, 2024
cf16db5
Merge remote-tracking branch 'origin' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 4, 2024
32184cc
Merge branch 'feat/core_pm_id_in_response' of https://github.com/jusp…
prajjwalkumar17 Mar 4, 2024
d351c1f
chore: addressed the comments
prajjwalkumar17 Mar 4, 2024
09a601f
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 5, 2024
230c058
chore: removed the status failing check
prajjwalkumar17 Mar 5, 2024
e9f38fb
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 6, 2024
293be30
chore: restored connector file
prajjwalkumar17 Mar 6, 2024
8972f1a
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 6, 2024
287dc22
Merge branch 'feat/core_pm_id_in_response' of https://github.com/jusp…
prajjwalkumar17 Mar 6, 2024
5008df8
chore: resolve conflicts
prajjwalkumar17 Mar 7, 2024
20a0bce
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 7, 2024
06e28b1
chore: resolve conflicts
prajjwalkumar17 Mar 7, 2024
38e1474
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 7, 2024
cb4a025
chore: run formatter
hyperswitch-bot[bot] Mar 7, 2024
933db1a
chore: add pm_id and pm_status froom setup mandate flow
prajjwalkumar17 Mar 7, 2024
cdb8095
chore: resolved commits
prajjwalkumar17 Mar 7, 2024
d88003d
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 7, 2024
39c06dd
chore: run formatter
hyperswitch-bot[bot] Mar 7, 2024
d8e3202
chore: debug logs
prajjwalkumar17 Mar 7, 2024
37ea666
Merge branch 'feat/core_pm_id_in_response' of https://github.com/jusp…
prajjwalkumar17 Mar 7, 2024
9a8e0fb
chore: debug logs
prajjwalkumar17 Mar 7, 2024
56b8cc7
chore: removed trailing spaces
prajjwalkumar17 Mar 7, 2024
112e814
chore: updated development.toml
prajjwalkumar17 Mar 7, 2024
fe1ff87
chore: addressed the comments
prajjwalkumar17 Mar 7, 2024
eb24ecb
chore: run formatter
hyperswitch-bot[bot] Mar 7, 2024
d810874
chore: fixed tests
prajjwalkumar17 Mar 7, 2024
cc6e496
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 7, 2024
c109748
chore: resolved tests
prajjwalkumar17 Mar 7, 2024
3bf4876
Merge branch 'feat/core_pm_id_in_response' of https://github.com/jusp…
prajjwalkumar17 Mar 7, 2024
2d84eda
chore: resolved comments
prajjwalkumar17 Mar 8, 2024
ca65bc1
chore: run formatter
hyperswitch-bot[bot] Mar 8, 2024
a2b170e
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 8, 2024
d66a539
chore: resolved comments
prajjwalkumar17 Mar 8, 2024
7b61f63
chore: addressed comments
prajjwalkumar17 Mar 8, 2024
3d50758
chore: addressed comments
prajjwalkumar17 Mar 8, 2024
fcb0198
chore: tokio is back
prajjwalkumar17 Mar 8, 2024
d3a14c1
Merge branch 'main' into feat/core_pm_id_in_response
prajjwalkumar17 Mar 10, 2024
2f633dd
chore: fixed tests
prajjwalkumar17 Mar 10, 2024
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
7 changes: 7 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,13 @@ pub struct PaymentsResponse {

/// Payment Fingerprint
pub fingerprint: Option<String>,

/// Payment Method Id
pub payment_method_id: Option<String>,

/// Payment Method Status
#[schema(value_type = Option<PaymentMethodStatus>)]
pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
}

#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
Expand Down
30 changes: 30 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,36 @@ pub enum PaymentMethodStatus {
Processing,
}

impl From<AttemptStatus> for PaymentMethodStatus {
fn from(attempt_status: AttemptStatus) -> Self {
match attempt_status {
AttemptStatus::Charged | AttemptStatus::Authorized => Self::Active,
AttemptStatus::Failure => Self::Inactive,
AttemptStatus::Voided
| AttemptStatus::Started
| AttemptStatus::Pending
| AttemptStatus::Unresolved
| AttemptStatus::CodInitiated
| AttemptStatus::Authorizing
| AttemptStatus::VoidInitiated
| AttemptStatus::AuthorizationFailed
| AttemptStatus::RouterDeclined
| AttemptStatus::AuthenticationSuccessful
| AttemptStatus::PaymentMethodAwaited
| AttemptStatus::AuthenticationFailed
| AttemptStatus::AuthenticationPending
| AttemptStatus::CaptureInitiated
| AttemptStatus::CaptureFailed
| AttemptStatus::VoidFailed
| AttemptStatus::AutoRefunded
| AttemptStatus::PartialCharged
| AttemptStatus::PartialChargedAndChargeable
| AttemptStatus::ConfirmationAwaited
| AttemptStatus::DeviceDataCollectionPending => Self::Processing,
}
}
}

/// To indicate the type of payment experience that the customer would go through
#[derive(
Eq,
Expand Down
1 change: 1 addition & 0 deletions crates/data_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ pub enum PaymentAttemptUpdate {
authentication_id: Option<String>,
payment_method_billing_address_id: Option<String>,
fingerprint_id: Option<String>,
payment_method_id: Option<String>,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ pub enum PaymentAttemptUpdate {
fingerprint_id: Option<String>,
updated_by: String,
merchant_connector_id: Option<String>,
payment_method_id: Option<String>,
external_three_ds_authentication_attempted: Option<bool>,
authentication_connector: Option<String>,
authentication_id: Option<String>,
Expand Down Expand Up @@ -574,6 +575,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
authentication_id,
payment_method_billing_address_id,
fingerprint_id,
payment_method_id,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand Down Expand Up @@ -601,6 +603,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
authentication_id,
payment_method_billing_address_id,
fingerprint_id,
payment_method_id: payment_method_id.map(Some),
..Default::default()
},
PaymentAttemptUpdate::VoidUpdate {
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::enums::ReconStatus,
api_models::enums::ConnectorStatus,
api_models::enums::AuthorizationStatus,
api_models::enums::PaymentMethodStatus,
api_models::admin::MerchantConnectorCreate,
api_models::admin::MerchantConnectorUpdate,
api_models::admin::PrimaryBusinessDetails,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/authentication/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub fn construct_router_data<F: Clone, Req, Res>(
frm_metadata: None,
dispute_id: None,
refund_id: None,
payment_method_status: None,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
description: None,
return_url: None,
payment_method_id: None,
payment_method_status: None,
address: self.address.clone(),
auth_type: storage_enums::AuthenticationType::NoThreeDs,
connector_meta_data: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub async fn construct_fulfillment_router_data<'a>(
auth_type: payment_attempt.authentication_type.unwrap_or_default(),
connector_meta_data: merchant_connector_account.get_metadata(),
amount_captured: payment_intent.amount_captured,
payment_method_status: None,
request: FraudCheckFulfillmentData {
amount: payment_attempt.amount,
order_details: payment_intent.order_details.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
payment_method_token: None,
connector_customer: None,
preprocessing_id: None,
payment_method_status: None,
connector_request_reference_id: uuid::Uuid::new_v4().to_string(),
test_mode: None,
recurring_mandate_payment_data: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/fraud_check/flows/sale_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
payment_method_token: None,
connector_customer: None,
preprocessing_id: None,
payment_method_status: None,
connector_request_reference_id: uuid::Uuid::new_v4().to_string(),
test_mode: None,
recurring_mandate_payment_data: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl
connector_http_status_code: None,
external_latency: None,
connector_api_version: None,
payment_method_status: None,
apple_pay_flow: None,
frm_metadata: None,
refund_id: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/mandate/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub async fn construct_mandate_revoke_router_data(
preprocessing_id: None,
payment_method_balance: None,
connector_api_version: None,
payment_method_status: None,
request: types::MandateRevokeRequestData {
mandate_id: mandate.mandate_id,
connector_mandate_id: mandate.connector_mandate_id,
Expand Down
83 changes: 68 additions & 15 deletions crates/router/src/core/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ use data_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent};
use diesel_models::enums;

use crate::{
core::{
errors::RouterResult,
payments::helpers,
pm_auth::{self as core_pm_auth},
},
core::{errors::RouterResult, payments::helpers, pm_auth as core_pm_auth},
routes::AppState,
types::{
api::{self, payments},
Expand All @@ -44,7 +40,7 @@ pub trait PaymentMethodRetrieve {
payment_intent: &PaymentIntent,
card_token_data: Option<&CardToken>,
customer: &Option<domain::Customer>,
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>>;
) -> RouterResult<storage::PaymentMethodDataWithId>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -128,8 +124,8 @@ impl PaymentMethodRetrieve for Oss {
payment_intent: &PaymentIntent,
card_token_data: Option<&CardToken>,
customer: &Option<domain::Customer>,
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>> {
match token_data {
) -> RouterResult<storage::PaymentMethodDataWithId> {
let token = match token_data {
storage::PaymentTokenData::TemporaryGeneric(generic_token) => {
helpers::retrieve_payment_method_with_temporary_token(
state,
Expand All @@ -138,7 +134,15 @@ impl PaymentMethodRetrieve for Oss {
merchant_key_store,
card_token_data,
)
.await
.await?
.map(
|(payment_method_data, payment_method)| storage::PaymentMethodDataWithId {
payment_method_data: Some(payment_method_data),
payment_method: Some(payment_method),
payment_method_id: None,
},
)
.unwrap_or_default()
}

storage::PaymentTokenData::Temporary(generic_token) => {
Expand All @@ -149,7 +153,15 @@ impl PaymentMethodRetrieve for Oss {
merchant_key_store,
card_token_data,
)
.await
.await?
.map(
|(payment_method_data, payment_method)| storage::PaymentMethodDataWithId {
payment_method_data: Some(payment_method_data),
payment_method: Some(payment_method),
payment_method_id: None,
},
)
.unwrap_or_default()
}

storage::PaymentTokenData::Permanent(card_token) => {
Expand All @@ -164,7 +176,21 @@ impl PaymentMethodRetrieve for Oss {
card_token_data,
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card)))
.map(|card| Some((card, enums::PaymentMethod::Card)))?
.map(
|(payment_method_data, payment_method)| storage::PaymentMethodDataWithId {
payment_method_data: Some(payment_method_data),
payment_method: Some(payment_method),
payment_method_id: Some(
card_token
.payment_method_id
.as_ref()
.unwrap_or(&card_token.token)
.to_string(),
),
},
)
.unwrap_or_default()
}

storage::PaymentTokenData::PermanentCard(card_token) => {
Expand All @@ -179,7 +205,21 @@ impl PaymentMethodRetrieve for Oss {
card_token_data,
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card)))
.map(|card| Some((card, enums::PaymentMethod::Card)))?
.map(
|(payment_method_data, payment_method)| storage::PaymentMethodDataWithId {
payment_method_data: Some(payment_method_data),
payment_method: Some(payment_method),
payment_method_id: Some(
card_token
.payment_method_id
.as_ref()
.unwrap_or(&card_token.token)
.to_string(),
),
},
)
.unwrap_or_default()
}

storage::PaymentTokenData::AuthBankDebit(auth_token) => {
Expand All @@ -190,10 +230,23 @@ impl PaymentMethodRetrieve for Oss {
payment_intent,
customer,
)
.await
.await?
.map(
|(payment_method_data, payment_method)| storage::PaymentMethodDataWithId {
payment_method_data: Some(payment_method_data),
payment_method: Some(payment_method),
payment_method_id: None,
},
)
.unwrap_or_default()
}

storage::PaymentTokenData::WalletToken(_) => Ok(None),
}
storage::PaymentTokenData::WalletToken(_) => storage::PaymentMethodDataWithId {
payment_method: None,
payment_method_data: None,
payment_method_id: None,
},
};
Ok(token)
}
}
12 changes: 9 additions & 3 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ where
None,
)
.await?;

let operation = Box::new(PaymentResponse);

connector_http_status_code = router_data.connector_http_status_code;
Expand Down Expand Up @@ -1927,7 +1928,7 @@ where

let connector_tokenization_action = match payment_method_action {
TokenizationAction::TokenizeInRouter => {
let (_operation, payment_method_data) = operation
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
.make_pm_data(
state,
Expand All @@ -1938,12 +1939,14 @@ where
)
.await?;
payment_data.payment_method_data = payment_method_data;
payment_data.payment_attempt.payment_method_id = pm_id;

TokenizationAction::SkipConnectorTokenization
}

TokenizationAction::TokenizeInConnector => TokenizationAction::TokenizeInConnector,
TokenizationAction::TokenizeInConnectorAndRouter => {
let (_operation, payment_method_data) = operation
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
.make_pm_data(
state,
Expand All @@ -1955,6 +1958,7 @@ where
.await?;

payment_data.payment_method_data = payment_method_data;
payment_data.payment_attempt.payment_method_id = pm_id;
TokenizationAction::TokenizeInConnector
}
TokenizationAction::ConnectorToken(token) => {
Expand Down Expand Up @@ -1996,7 +2000,7 @@ where
{
// On confirm is false and only router related
let payment_data = if !is_operation_confirm(operation) {
let (_operation, payment_method_data) = operation
let (_operation, payment_method_data, pm_id) = operation
prajjwalkumar17 marked this conversation as resolved.
Show resolved Hide resolved
.to_domain()?
.make_pm_data(
state,
Expand All @@ -2007,6 +2011,7 @@ where
)
.await?;
payment_data.payment_method_data = payment_method_data;
payment_data.payment_attempt.payment_method_id = pm_id;
payment_data
} else {
payment_data
Expand Down Expand Up @@ -2078,6 +2083,7 @@ where
pub authorizations: Vec<diesel_models::authorization::Authorization>,
pub authentication: Option<(storage::Authentication, AuthenticationData)>,
pub frm_metadata: Option<serde_json::Value>,
pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
}

#[derive(Debug, Default, Clone)]
Expand Down
Loading
Loading