Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/juspay/hyperswitch into sig…
Browse files Browse the repository at this point in the history
…nup-signin
  • Loading branch information
ThisIsMani committed Nov 20, 2023
2 parents a03cb5f + 44deeb7 commit 3dc72f6
Show file tree
Hide file tree
Showing 38 changed files with 1,334 additions and 726 deletions.
6 changes: 6 additions & 0 deletions crates/api_models/src/gsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub struct GsmCreateRequest {
pub router_error: Option<String>,
pub decision: GsmDecision,
pub step_up_possible: bool,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -57,6 +59,8 @@ pub struct GsmUpdateRequest {
pub router_error: Option<String>,
pub decision: Option<GsmDecision>,
pub step_up_possible: Option<bool>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -88,4 +92,6 @@ pub struct GsmResponse {
pub router_error: Option<String>,
pub decision: String,
pub step_up_possible: bool,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}
10 changes: 10 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ pub struct PaymentAttemptResponse {
/// reference to the payment at connector side
#[schema(value_type = Option<String>, example = "993672945374576J")]
pub reference_id: Option<String>,
/// error code unified across the connectors is received here if there was an error while calling connector
pub unified_code: Option<String>,
/// error message unified across the connectors is received here if there was an error while calling connector
pub unified_message: Option<String>,
}

#[derive(
Expand Down Expand Up @@ -2089,6 +2093,12 @@ pub struct PaymentsResponse {
#[schema(example = "Failed while verifying the card")]
pub error_message: Option<String>,

/// error code unified across the connectors is received here if there was an error while calling connector
pub unified_code: Option<String>,

/// error message unified across the connectors is received here if there was an error while calling connector
pub unified_message: Option<String>,

/// Payment Experience for the current payment
#[schema(value_type = Option<PaymentExperience>, example = "redirect_to_url")]
pub payment_experience: Option<api_enums::PaymentExperience>,
Expand Down
8 changes: 8 additions & 0 deletions crates/data_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ pub struct PaymentAttempt {
pub authentication_data: Option<serde_json::Value>,
pub encoded_data: Option<String>,
pub merchant_connector_id: Option<String>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -207,6 +209,8 @@ pub struct PaymentAttemptNew {
pub authentication_data: Option<serde_json::Value>,
pub encoded_data: Option<String>,
pub merchant_connector_id: Option<String>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -292,6 +296,8 @@ pub enum PaymentAttemptUpdate {
updated_by: String,
authentication_data: Option<serde_json::Value>,
encoded_data: Option<String>,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
},
UnresolvedResponseUpdate {
status: storage_enums::AttemptStatus,
Expand All @@ -316,6 +322,8 @@ pub enum PaymentAttemptUpdate {
error_reason: Option<Option<String>>,
amount_capturable: Option<i64>,
updated_by: String,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
},
MultipleCaptureCountUpdate {
multiple_capture_count: i16,
Expand Down
12 changes: 12 additions & 0 deletions crates/diesel_models/src/gsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct GatewayStatusMap {
#[serde(with = "custom_serde::iso8601")]
pub last_modified: PrimitiveDateTime,
pub step_up_possible: bool,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq, Insertable)]
Expand All @@ -48,6 +50,8 @@ pub struct GatewayStatusMappingNew {
pub router_error: Option<String>,
pub decision: String,
pub step_up_possible: bool,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(
Expand All @@ -71,6 +75,8 @@ pub struct GatewayStatusMapperUpdateInternal {
pub router_error: Option<Option<String>>,
pub decision: Option<String>,
pub step_up_possible: Option<bool>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Debug)]
Expand All @@ -79,6 +85,8 @@ pub struct GatewayStatusMappingUpdate {
pub router_error: Option<Option<String>>,
pub decision: Option<String>,
pub step_up_possible: Option<bool>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal {
Expand All @@ -88,12 +96,16 @@ impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal {
status,
router_error,
step_up_possible,
unified_code,
unified_message,
} = value;
Self {
status,
router_error,
decision,
step_up_possible,
unified_code,
unified_message,
..Default::default()
}
}
Expand Down
20 changes: 20 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct PaymentAttempt {
pub merchant_connector_id: Option<String>,
pub authentication_data: Option<serde_json::Value>,
pub encoded_data: Option<String>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq, Queryable, Serialize, Deserialize)]
Expand Down Expand Up @@ -124,6 +126,8 @@ pub struct PaymentAttemptNew {
pub merchant_connector_id: Option<String>,
pub authentication_data: Option<serde_json::Value>,
pub encoded_data: Option<String>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -209,6 +213,8 @@ pub enum PaymentAttemptUpdate {
updated_by: String,
authentication_data: Option<serde_json::Value>,
encoded_data: Option<String>,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
},
UnresolvedResponseUpdate {
status: storage_enums::AttemptStatus,
Expand All @@ -233,6 +239,8 @@ pub enum PaymentAttemptUpdate {
error_reason: Option<Option<String>>,
amount_capturable: Option<i64>,
updated_by: String,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
},
MultipleCaptureCountUpdate {
multiple_capture_count: i16,
Expand Down Expand Up @@ -298,6 +306,8 @@ pub struct PaymentAttemptUpdateInternal {
merchant_connector_id: Option<String>,
authentication_data: Option<serde_json::Value>,
encoded_data: Option<String>,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
}

impl PaymentAttemptUpdate {
Expand Down Expand Up @@ -352,6 +362,8 @@ impl PaymentAttemptUpdate {
merchant_connector_id: pa_update.merchant_connector_id,
authentication_data: pa_update.authentication_data.or(source.authentication_data),
encoded_data: pa_update.encoded_data.or(source.encoded_data),
unified_code: pa_update.unified_code.unwrap_or(source.unified_code),
unified_message: pa_update.unified_message.unwrap_or(source.unified_message),
..source
}
}
Expand Down Expand Up @@ -488,6 +500,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
updated_by,
authentication_data,
encoded_data,
unified_code,
unified_message,
} => Self {
status: Some(status),
connector,
Expand All @@ -508,6 +522,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
tax_amount,
authentication_data,
encoded_data,
unified_code,
unified_message,
..Default::default()
},
PaymentAttemptUpdate::ErrorUpdate {
Expand All @@ -518,6 +534,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
error_reason,
amount_capturable,
updated_by,
unified_code,
unified_message,
} => Self {
connector,
status: Some(status),
Expand All @@ -527,6 +545,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
error_reason,
amount_capturable,
updated_by,
unified_code,
unified_message,
..Default::default()
},
PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self {
Expand Down
8 changes: 8 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ diesel::table! {
created_at -> Timestamp,
last_modified -> Timestamp,
step_up_possible -> Bool,
#[max_length = 255]
unified_code -> Nullable<Varchar>,
#[max_length = 1024]
unified_message -> Nullable<Varchar>,
}
}

Expand Down Expand Up @@ -585,6 +589,10 @@ diesel::table! {
merchant_connector_id -> Nullable<Varchar>,
authentication_data -> Nullable<Json>,
encoded_data -> Nullable<Text>,
#[max_length = 255]
unified_code -> Nullable<Varchar>,
#[max_length = 1024]
unified_message -> Nullable<Varchar>,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use storage_impl::errors as storage_impl_errors;
pub use user::*;

pub use self::{
api_error_response::ApiErrorResponse,
api_error_response::{ApiErrorResponse, NotImplementedMessage},
customers_error_response::CustomersErrorResponse,
sch_errors::*,
storage_errors::*,
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/core/gsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub async fn update_gsm_rule(
status,
router_error,
step_up_possible,
unified_code,
unified_message,
} = gsm_request;
GsmInterface::update_gsm_rule(
db,
Expand All @@ -78,6 +80,8 @@ pub async fn update_gsm_rule(
status,
router_error: Some(router_error),
step_up_possible,
unified_code,
unified_message,
},
)
.await
Expand Down
77 changes: 75 additions & 2 deletions crates/router/src/core/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ pub use api_models::{
pub use common_utils::request::RequestBody;
use data_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent};
use diesel_models::enums;
use error_stack::IntoReport;

use crate::{
core::{errors::RouterResult, payments::helpers},
core::{
errors::{self, RouterResult},
payments::helpers,
},
routes::AppState,
types::{
api::{self, payments},
domain,
domain, storage,
},
};

Expand All @@ -30,6 +34,14 @@ pub trait PaymentMethodRetrieve {
payment_attempt: &PaymentAttempt,
merchant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(Option<payments::PaymentMethodData>, Option<String>)>;

async fn retrieve_payment_method_with_token(
state: &AppState,
key_store: &domain::MerchantKeyStore,
token: &storage::PaymentTokenData,
payment_intent: &PaymentIntent,
card_cvc: Option<masking::Secret<String>>,
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -105,4 +117,65 @@ impl PaymentMethodRetrieve for Oss {
_ => Ok((None, None)),
}
}

async fn retrieve_payment_method_with_token(
state: &AppState,
merchant_key_store: &domain::MerchantKeyStore,
token_data: &storage::PaymentTokenData,
payment_intent: &PaymentIntent,
card_cvc: Option<masking::Secret<String>>,
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>> {
match token_data {
storage::PaymentTokenData::TemporaryGeneric(generic_token) => {
helpers::retrieve_payment_method_with_temporary_token(
state,
&generic_token.token,
payment_intent,
card_cvc,
merchant_key_store,
)
.await
}

storage::PaymentTokenData::Temporary(generic_token) => {
helpers::retrieve_payment_method_with_temporary_token(
state,
&generic_token.token,
payment_intent,
card_cvc,
merchant_key_store,
)
.await
}

storage::PaymentTokenData::Permanent(card_token) => {
helpers::retrieve_card_with_permanent_token(
state,
&card_token.token,
payment_intent,
card_cvc,
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card)))
}

storage::PaymentTokenData::PermanentCard(card_token) => {
helpers::retrieve_card_with_permanent_token(
state,
&card_token.token,
payment_intent,
card_cvc,
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card)))
}

storage::PaymentTokenData::AuthBankDebit(_) => {
Err(errors::ApiErrorResponse::NotImplemented {
message: errors::NotImplementedMessage::Default,
})
.into_report()
}
}
}
}
Loading

0 comments on commit 3dc72f6

Please sign in to comment.