fix(router): associate parent payment token with payment_method_id as hyperswitch token for saved cards (#2130)

Co-authored-by: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com>
This commit is contained in:
Shanks
2023-11-20 16:12:06 +05:30
committed by GitHub
parent 644709d95f
commit efeebc0f23
6 changed files with 320 additions and 102 deletions

View File

@ -9,7 +9,11 @@ use super::app::AppState;
use crate::{
core::{api_locking, errors, payment_methods::cards},
services::{api, authentication as auth},
types::api::payment_methods::{self, PaymentMethodId},
types::{
api::payment_methods::{self, PaymentMethodId},
storage::payment_method::PaymentTokenData,
},
utils::Encode,
};
/// PaymentMethods - Create
@ -379,9 +383,12 @@ impl ParentPaymentMethodToken {
pub async fn insert(
&self,
intent_created_at: Option<PrimitiveDateTime>,
token: String,
token: PaymentTokenData,
state: &AppState,
) -> CustomResult<(), errors::ApiErrorResponse> {
let token_json_str = Encode::<PaymentTokenData>::encode_to_string_of_json(&token)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to serialize hyperswitch token to json")?;
let redis_conn = state
.store
.get_redis_conn()
@ -392,7 +399,7 @@ impl ParentPaymentMethodToken {
redis_conn
.set_key_with_expiry(
&self.key_for_token,
token,
token_json_str,
TOKEN_TTL - time_elapsed.whole_seconds(),
)
.await