Skip to content

Commit 44132c8

Browse files
committed
feat: add an api for retrieving the extended card info from redis
1 parent c3a1db1 commit 44132c8

File tree

13 files changed

+92
-5
lines changed

13 files changed

+92
-5
lines changed

crates/api_models/src/events/payment.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use crate::{
88
PaymentMethodResponse, PaymentMethodUpdate,
99
},
1010
payments::{
11-
PaymentIdType, PaymentListConstraints, PaymentListFilterConstraints, PaymentListFilters,
12-
PaymentListFiltersV2, PaymentListResponse, PaymentListResponseV2, PaymentsApproveRequest,
13-
PaymentsCancelRequest, PaymentsCaptureRequest, PaymentsExternalAuthenticationRequest,
11+
ExtendedCardInfoResponse, PaymentIdType, PaymentListConstraints,
12+
PaymentListFilterConstraints, PaymentListFilters, PaymentListFiltersV2,
13+
PaymentListResponse, PaymentListResponseV2, PaymentsApproveRequest, PaymentsCancelRequest,
14+
PaymentsCaptureRequest, PaymentsExternalAuthenticationRequest,
1415
PaymentsExternalAuthenticationResponse, PaymentsIncrementalAuthorizationRequest,
1516
PaymentsRejectRequest, PaymentsRequest, PaymentsResponse, PaymentsRetrieveRequest,
1617
PaymentsStartRequest, RedirectionResponse,
@@ -201,3 +202,5 @@ impl ApiEventMetric for PaymentsExternalAuthenticationRequest {
201202
})
202203
}
203204
}
205+
206+
impl ApiEventMetric for ExtendedCardInfoResponse {}

crates/api_models/src/payments.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4622,6 +4622,12 @@ pub enum PaymentLinkStatusWrap {
46224622
IntentStatus(api_enums::IntentStatus),
46234623
}
46244624

4625+
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
4626+
pub struct ExtendedCardInfoResponse {
4627+
// Encrypted customer payment method data
4628+
pub payload: String,
4629+
}
4630+
46254631
#[cfg(test)]
46264632
mod payments_request_api_contract {
46274633
#![allow(clippy::unwrap_used)]

crates/openapi/src/openapi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ Never share your secret api keys. Keep them guarded and secure.
470470
api_models::payments::PaymentLinkResponse,
471471
api_models::payments::RetrievePaymentLinkResponse,
472472
api_models::payments::PaymentLinkInitiateRequest,
473+
api_models::payments::ExtendedCardInfoResponse,
473474
api_models::routing::RoutingConfigRequest,
474475
api_models::routing::RoutingDictionaryRecord,
475476
api_models::routing::RoutingKind,

crates/router/src/compatibility/stripe/errors.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ pub enum StripeErrorCode {
262262
CurrencyConversionFailed,
263263
#[error(error_type = StripeErrorType::InvalidRequestError, code = "IR_25", message = "Cannot delete the default payment method")]
264264
PaymentMethodDeleteFailed,
265+
#[error(error_type = StripeErrorType::InvalidRequestError, code = "", message = "Extended card info does not exist")]
266+
ExtendedCardInfoNotFound,
265267
// [#216]: https://github.com/juspay/hyperswitch/issues/216
266268
// Implement the remaining stripe error codes
267269

@@ -643,6 +645,7 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
643645
errors::ApiErrorResponse::InvalidWalletToken { wallet_name } => {
644646
Self::InvalidWalletToken { wallet_name }
645647
}
648+
errors::ApiErrorResponse::ExtendedCardInfoNotFound => Self::ExtendedCardInfoNotFound,
646649
}
647650
}
648651
}
@@ -714,7 +717,8 @@ impl actix_web::ResponseError for StripeErrorCode {
714717
| Self::PaymentMethodUnactivated
715718
| Self::InvalidConnectorConfiguration { .. }
716719
| Self::CurrencyConversionFailed
717-
| Self::PaymentMethodDeleteFailed => StatusCode::BAD_REQUEST,
720+
| Self::PaymentMethodDeleteFailed
721+
| Self::ExtendedCardInfoNotFound => StatusCode::BAD_REQUEST,
718722
Self::RefundFailed
719723
| Self::PayoutFailed
720724
| Self::PaymentLinkNotFound

crates/router/src/core/errors/api_error_response.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ pub enum ApiErrorResponse {
269269
message = "Invalid Cookie"
270270
)]
271271
InvalidCookie,
272+
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_27", message = "Extended card info does not exist")]
273+
ExtendedCardInfoNotFound,
272274
}
273275

274276
impl PTError for ApiErrorResponse {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
301301
Self::InvalidCookie => {
302302
AER::BadRequest(ApiError::new("IR", 26, "Invalid Cookie", None))
303303
}
304+
Self::ExtendedCardInfoNotFound => {
305+
AER::NotFound(ApiError::new("IR", 27, "Extended card info does not exist", None))
306+
}
304307
}
305308
}
306309
}

crates/router/src/core/payments.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,3 +3992,26 @@ pub async fn payment_external_authentication(
39923992
},
39933993
))
39943994
}
3995+
3996+
#[instrument(skip_all)]
3997+
pub async fn get_extended_card_info(
3998+
state: AppState,
3999+
merchant_id: String,
4000+
payment_id: String,
4001+
) -> RouterResponse<payments_api::ExtendedCardInfoResponse> {
4002+
let redis_conn = state
4003+
.store
4004+
.get_redis_conn()
4005+
.change_context(errors::ApiErrorResponse::InternalServerError)
4006+
.attach_printable("Failed to get redis connection")?;
4007+
4008+
let key = helpers::get_redis_key_for_extended_card_info(&merchant_id, &payment_id);
4009+
let payload = redis_conn
4010+
.get_key::<String>(&key)
4011+
.await
4012+
.change_context(errors::ApiErrorResponse::ExtendedCardInfoNotFound)?;
4013+
4014+
Ok(services::ApplicationResponse::Json(
4015+
payments_api::ExtendedCardInfoResponse { payload },
4016+
))
4017+
}

crates/router/src/core/payments/helpers.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4320,3 +4320,7 @@ pub fn validate_mandate_data_and_future_usage(
43204320
Ok(())
43214321
}
43224322
}
4323+
4324+
pub fn get_redis_key_for_extended_card_info(merchant_id: &str, payment_id: &str) -> String {
4325+
format!("{merchant_id}_{payment_id}_extended_card_info")
4326+
}

crates/router/src/routes/app.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ impl Payments {
382382
)
383383
.service(
384384
web::resource("/{payment_id}/3ds/authentication").route(web::post().to(payments_external_authentication)),
385+
)
386+
.service(
387+
web::resource("/{payment_id}/extended_card_info").route(web::get().to(retrieve_extended_card_info)),
385388
);
386389
}
387390
route

crates/router/src/routes/lock_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ impl From<Flow> for ApiIdentifier {
120120
| Flow::PaymentsRedirect
121121
| Flow::PaymentsIncrementalAuthorization
122122
| Flow::PaymentsExternalAuthentication
123-
| Flow::PaymentsAuthorize => Self::Payments,
123+
| Flow::PaymentsAuthorize
124+
| Flow::GetExtendedCardInfo => Self::Payments,
124125

125126
Flow::PayoutsCreate
126127
| Flow::PayoutsRetrieve

0 commit comments

Comments
 (0)