feat(worldpay): migrate to v7 (#6109)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Kashif
2024-10-17 15:51:59 +05:30
committed by GitHub
parent df2501ceaf
commit 962afbd084
66 changed files with 1492 additions and 752 deletions

View File

@ -97,13 +97,13 @@ impl<T: DatabaseStore> ReverseLookupInterface for KVRouterStore<T> {
},
};
match kv_wrapper::<DieselReverseLookup, _, _>(
match Box::pin(kv_wrapper::<DieselReverseLookup, _, _>(
self,
KvOperation::SetNx(&created_rev_lookup, redis_entry),
PartitionKey::CombinationKey {
combination: &format!("reverse_lookup_{}", &created_rev_lookup.lookup_id),
},
)
))
.await
.map_err(|err| err.to_redis_failed_response(&created_rev_lookup.lookup_id))?
.try_into_setnx()
@ -140,13 +140,13 @@ impl<T: DatabaseStore> ReverseLookupInterface for KVRouterStore<T> {
storage_enums::MerchantStorageScheme::PostgresOnly => database_call().await,
storage_enums::MerchantStorageScheme::RedisKv => {
let redis_fut = async {
kv_wrapper(
Box::pin(kv_wrapper(
self,
KvOperation::<DieselReverseLookup>::Get,
PartitionKey::CombinationKey {
combination: &format!("reverse_lookup_{id}"),
},
)
))
.await?
.try_into_get()
};

View File

@ -1,6 +1,10 @@
#[cfg(feature = "v2")]
use common_utils::types::keymanager::KeyManagerState;
use common_utils::{errors::CustomResult, fallback_reverse_lookup_not_found};
use common_utils::{
errors::CustomResult,
fallback_reverse_lookup_not_found,
types::{ConnectorTransactionId, ConnectorTransactionIdTrait},
};
use diesel_models::{
enums::{
MandateAmountData as DieselMandateAmountData, MandateDataType as DieselMandateType,
@ -554,7 +558,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
self.insert_reverse_lookup(reverse_lookup, storage_scheme)
.await?;
match kv_wrapper::<PaymentAttempt, _, _>(
match Box::pin(kv_wrapper::<PaymentAttempt, _, _>(
self,
KvOperation::HSetNx(
&field,
@ -562,7 +566,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
redis_entry,
),
key,
)
))
.await
.map_err(|err| err.to_redis_failed_response(&key_str))?
.try_into_hsetnx()
@ -626,7 +630,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
}
MerchantStorageScheme::RedisKv => {
let key_str = key.to_string();
let old_connector_transaction_id = &this.connector_transaction_id;
let old_connector_transaction_id = &this.get_connector_payment_id();
let old_preprocessing_id = &this.preprocessing_step_id;
let updated_attempt = PaymentAttempt::from_storage_model(
payment_attempt
@ -651,7 +655,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
match (
old_connector_transaction_id,
&updated_attempt.connector_transaction_id,
&updated_attempt.get_connector_payment_id(),
) {
(None, Some(connector_transaction_id)) => {
add_connector_txn_id_to_reverse_lookup(
@ -659,7 +663,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
key_str.as_str(),
&this.merchant_id,
updated_attempt.attempt_id.as_str(),
connector_transaction_id.as_str(),
connector_transaction_id,
storage_scheme,
)
.await?;
@ -671,7 +675,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
key_str.as_str(),
&this.merchant_id,
updated_attempt.attempt_id.as_str(),
connector_transaction_id.as_str(),
connector_transaction_id,
storage_scheme,
)
.await?;
@ -708,11 +712,11 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
(_, _) => {}
}
kv_wrapper::<(), _, _>(
Box::pin(kv_wrapper::<(), _, _>(
self,
KvOperation::Hset::<DieselPaymentAttempt>((&field, redis_value), redis_entry),
key,
)
))
.await
.change_context(errors::StorageError::KVError)?
.try_into_hset()
@ -796,7 +800,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
Box::pin(try_redis_get_else_try_database_get(
async {
kv_wrapper(self, KvOperation::<DieselPaymentAttempt>::HGet(&lookup.sk_id), key).await?.try_into_hget()
Box::pin(kv_wrapper(self, KvOperation::<DieselPaymentAttempt>::HGet(&lookup.sk_id), key)).await?.try_into_hget()
},
|| async {self.router_store.find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(connector_transaction_id, payment_id, merchant_id, storage_scheme).await},
))
@ -837,11 +841,11 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
let pattern = "pa_*";
let redis_fut = async {
let kv_result = kv_wrapper::<PaymentAttempt, _, _>(
let kv_result = Box::pin(kv_wrapper::<PaymentAttempt, _, _>(
self,
KvOperation::<DieselPaymentAttempt>::Scan(pattern),
key,
)
))
.await?
.try_into_scan();
kv_result.and_then(|mut payment_attempts| {
@ -896,11 +900,11 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
let pattern = "pa_*";
let redis_fut = async {
let kv_result = kv_wrapper::<PaymentAttempt, _, _>(
let kv_result = Box::pin(kv_wrapper::<PaymentAttempt, _, _>(
self,
KvOperation::<DieselPaymentAttempt>::Scan(pattern),
key,
)
))
.await?
.try_into_scan();
kv_result.and_then(|mut payment_attempts| {
@ -972,11 +976,11 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
};
Box::pin(try_redis_get_else_try_database_get(
async {
kv_wrapper(
Box::pin(kv_wrapper(
self,
KvOperation::<DieselPaymentAttempt>::HGet(&lookup.sk_id),
key,
)
))
.await?
.try_into_hget()
},
@ -1029,9 +1033,13 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
let field = format!("pa_{attempt_id}");
Box::pin(try_redis_get_else_try_database_get(
async {
kv_wrapper(self, KvOperation::<DieselPaymentAttempt>::HGet(&field), key)
.await?
.try_into_hget()
Box::pin(kv_wrapper(
self,
KvOperation::<DieselPaymentAttempt>::HGet(&field),
key,
))
.await?
.try_into_hget()
},
|| async {
self.router_store
@ -1092,11 +1100,11 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
};
Box::pin(try_redis_get_else_try_database_get(
async {
kv_wrapper(
Box::pin(kv_wrapper(
self,
KvOperation::<DieselPaymentAttempt>::HGet(&lookup.sk_id),
key,
)
))
.await?
.try_into_hget()
},
@ -1181,11 +1189,11 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
Box::pin(try_redis_get_else_try_database_get(
async {
kv_wrapper(
Box::pin(kv_wrapper(
self,
KvOperation::<DieselPaymentAttempt>::HGet(&lookup.sk_id),
key,
)
))
.await?
.try_into_hget()
},
@ -1235,9 +1243,13 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
};
Box::pin(try_redis_get_else_try_database_get(
async {
kv_wrapper(self, KvOperation::<DieselPaymentAttempt>::Scan("pa_*"), key)
.await?
.try_into_scan()
Box::pin(kv_wrapper(
self,
KvOperation::<DieselPaymentAttempt>::Scan("pa_*"),
key,
))
.await?
.try_into_scan()
},
|| async {
self.router_store
@ -1363,6 +1375,11 @@ impl DataModelExt for PaymentAttempt {
type StorageModel = DieselPaymentAttempt;
fn to_storage_model(self) -> Self::StorageModel {
let (connector_transaction_id, connector_transaction_data) = self
.connector_transaction_id
.map(ConnectorTransactionId::form_id_and_data)
.map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
.unwrap_or((None, None));
DieselPaymentAttempt {
payment_id: self.payment_id,
merchant_id: self.merchant_id,
@ -1379,7 +1396,7 @@ impl DataModelExt for PaymentAttempt {
tax_amount: self.net_amount.get_tax_on_surcharge(),
payment_method_id: self.payment_method_id,
payment_method: self.payment_method,
connector_transaction_id: self.connector_transaction_id,
connector_transaction_id,
capture_method: self.capture_method,
capture_on: self.capture_on,
confirm: self.confirm,
@ -1433,12 +1450,16 @@ impl DataModelExt for PaymentAttempt {
customer_acceptance: self.customer_acceptance,
organization_id: self.organization_id,
profile_id: self.profile_id,
connector_transaction_data,
shipping_cost: self.net_amount.get_shipping_cost(),
order_tax_amount: self.net_amount.get_order_tax_amount(),
}
}
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
let connector_transaction_id = storage_model
.get_optional_connector_transaction_id()
.cloned();
Self {
net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
storage_model.amount,
@ -1458,7 +1479,7 @@ impl DataModelExt for PaymentAttempt {
offer_amount: storage_model.offer_amount,
payment_method_id: storage_model.payment_method_id,
payment_method: storage_model.payment_method,
connector_transaction_id: storage_model.connector_transaction_id,
connector_transaction_id,
capture_method: storage_model.capture_method,
capture_on: storage_model.capture_on,
confirm: storage_model.confirm,

View File

@ -113,7 +113,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
.await
.change_context(StorageError::EncryptionError)?;
match kv_wrapper::<DieselPaymentIntent, _, _>(
match Box::pin(kv_wrapper::<DieselPaymentIntent, _, _>(
self,
KvOperation::<DieselPaymentIntent>::HSetNx(
&field,
@ -121,7 +121,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
redis_entry,
),
key,
)
))
.await
.map_err(|err| err.to_redis_failed_response(&key_str))?
.try_into_hsetnx()
@ -228,11 +228,11 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
},
};
kv_wrapper::<(), _, _>(
Box::pin(kv_wrapper::<(), _, _>(
self,
KvOperation::<DieselPaymentIntent>::Hset((&field, redis_value), redis_entry),
key,
)
))
.await
.map_err(|err| err.to_redis_failed_response(&key_str))?
.try_into_hset()
@ -316,11 +316,11 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
let field = payment_id.get_hash_key_for_kv_store();
Box::pin(utils::try_redis_get_else_try_database_get(
async {
kv_wrapper::<DieselPaymentIntent, _, _>(
Box::pin(kv_wrapper::<DieselPaymentIntent, _, _>(
self,
KvOperation::<DieselPaymentIntent>::HGet(&field),
key,
)
))
.await?
.try_into_hget()
},

View File

@ -115,7 +115,7 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
self.insert_reverse_lookup(reverse_lookup, storage_scheme)
.await?;
match kv_wrapper::<DieselPayoutAttempt, _, _>(
match Box::pin(kv_wrapper::<DieselPayoutAttempt, _, _>(
self,
KvOperation::<DieselPayoutAttempt>::HSetNx(
&field,
@ -123,7 +123,7 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
redis_entry,
),
key,
)
))
.await
.map_err(|err| err.to_redis_failed_response(&key_str))?
.try_into_hsetnx()
@ -227,11 +227,11 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
_ => {}
}
kv_wrapper::<(), _, _>(
Box::pin(kv_wrapper::<(), _, _>(
self,
KvOperation::<DieselPayoutAttempt>::Hset((&field, redis_value), redis_entry),
key,
)
))
.await
.map_err(|err| err.to_redis_failed_response(&key_str))?
.try_into_hset()
@ -284,11 +284,11 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
};
Box::pin(utils::try_redis_get_else_try_database_get(
async {
kv_wrapper(
Box::pin(kv_wrapper(
self,
KvOperation::<DieselPayoutAttempt>::HGet(&lookup.sk_id),
key,
)
))
.await?
.try_into_hget()
},
@ -345,11 +345,11 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
};
Box::pin(utils::try_redis_get_else_try_database_get(
async {
kv_wrapper(
Box::pin(kv_wrapper(
self,
KvOperation::<DieselPayoutAttempt>::HGet(&lookup.sk_id),
key,
)
))
.await?
.try_into_hget()
},

View File

@ -134,7 +134,7 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
},
};
match kv_wrapper::<DieselPayouts, _, _>(
match Box::pin(kv_wrapper::<DieselPayouts, _, _>(
self,
KvOperation::<DieselPayouts>::HSetNx(
&field,
@ -142,7 +142,7 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
redis_entry,
),
key,
)
))
.await
.map_err(|err| err.to_redis_failed_response(&key_str))?
.try_into_hsetnx()
@ -208,11 +208,11 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
},
};
kv_wrapper::<(), _, _>(
Box::pin(kv_wrapper::<(), _, _>(
self,
KvOperation::<DieselPayouts>::Hset((&field, redis_value), redis_entry),
key,
)
))
.await
.map_err(|err| err.to_redis_failed_response(&key_str))?
.try_into_hset()
@ -255,11 +255,11 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
let field = format!("po_{payout_id}");
Box::pin(utils::try_redis_get_else_try_database_get(
async {
kv_wrapper::<DieselPayouts, _, _>(
Box::pin(kv_wrapper::<DieselPayouts, _, _>(
self,
KvOperation::<DieselPayouts>::HGet(&field),
key,
)
))
.await?
.try_into_hget()
},
@ -312,11 +312,11 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
let field = format!("po_{payout_id}");
Box::pin(utils::try_redis_get_else_try_database_get(
async {
kv_wrapper::<DieselPayouts, _, _>(
Box::pin(kv_wrapper::<DieselPayouts, _, _>(
self,
KvOperation::<DieselPayouts>::HGet(&field),
key,
)
))
.await?
.try_into_hget()
.map(Some)

View File

@ -312,8 +312,12 @@ where
Op::Find => MerchantStorageScheme::RedisKv,
Op::Update(_, _, Some("postgres_only")) => MerchantStorageScheme::PostgresOnly,
Op::Update(partition_key, field, Some(_updated_by)) => {
match kv_wrapper::<D, _, _>(store, KvOperation::<D>::HGet(field), partition_key)
.await
match Box::pin(kv_wrapper::<D, _, _>(
store,
KvOperation::<D>::HGet(field),
partition_key,
))
.await
{
Ok(_) => {
metrics::KV_SOFT_KILL_ACTIVE_UPDATE.add(&metrics::CONTEXT, 1, &[]);