Skip to content

Commit

Permalink
feat: fetch merchant key store only once per session (#1400)
Browse files Browse the repository at this point in the history
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
  • Loading branch information
dracarys18 and SanchithHegde committed Jun 22, 2023
1 parent 957d5e0 commit d321aa1
Show file tree
Hide file tree
Showing 65 changed files with 979 additions and 498 deletions.
13 changes: 12 additions & 1 deletion crates/common_utils/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,25 @@ impl<T: Clone, S: masking::Strategy<T>> Encryptable<Secret<T, S>> {

impl<T: Clone> Encryptable<T> {
///
/// Get the inner data while consumping self
/// Get the inner data while consuming self
///
#[inline]
pub fn into_inner(self) -> T {
self.inner
}

///
/// Get the reference to inner value
///
#[inline]
pub fn get_inner(&self) -> &T {
&self.inner
}

///
/// Get the inner encrypted data while consuming self
///
#[inline]
pub fn into_encrypted(self) -> Secret<Vec<u8>, EncryptionStratergy> {
self.encrypted
}
Expand Down
20 changes: 12 additions & 8 deletions crates/router/src/compatibility/stripe/customers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub async fn customer_create(
state.get_ref(),
&req,
create_cust_req,
|state, merchant_account, req| {
customers::create_customer(&*state.store, merchant_account, req)
|state, auth, req| {
customers::create_customer(&*state.store, auth.merchant_account, auth.key_store, req)
},
&auth::ApiKeyAuth,
)
Expand Down Expand Up @@ -78,8 +78,8 @@ pub async fn customer_retrieve(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
customers::retrieve_customer(&*state.store, merchant_account, req)
|state, auth, req| {
customers::retrieve_customer(&*state.store, auth.merchant_account, auth.key_store, req)
},
&auth::ApiKeyAuth,
)
Expand Down Expand Up @@ -121,8 +121,8 @@ pub async fn customer_update(
state.get_ref(),
&req,
cust_update_req,
|state, merchant_account, req| {
customers::update_customer(&*state.store, merchant_account, req)
|state, auth, req| {
customers::update_customer(&*state.store, auth.merchant_account, req, auth.key_store)
},
&auth::ApiKeyAuth,
)
Expand Down Expand Up @@ -155,7 +155,9 @@ pub async fn customer_delete(
state.get_ref(),
&req,
payload,
customers::delete_customer,
|state, auth, req| {
customers::delete_customer(state, auth.merchant_account, req, auth.key_store)
},
&auth::ApiKeyAuth,
)
.await
Expand Down Expand Up @@ -185,7 +187,9 @@ pub async fn list_customer_payment_method_api(
state.get_ref(),
&req,
customer_id.as_ref(),
cards::list_customer_payment_method,
|state, auth, req| {
cards::list_customer_payment_method(state, auth.merchant_account, auth.key_store, req)
},
&auth::ApiKeyAuth,
)
.await
Expand Down
39 changes: 22 additions & 17 deletions crates/router/src/compatibility/stripe/payment_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ pub async fn payment_intents_create(
state.get_ref(),
&req,
create_payment_req,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::Authorize, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentCreate,
req,
api::AuthFlow::Merchant,
Expand Down Expand Up @@ -100,10 +101,11 @@ pub async fn payment_intents_retrieve(
state.get_ref(),
&req,
payload,
|state, merchant_account, payload| {
|state, auth, payload| {
payments::payments_core::<api_types::PSync, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentStatus,
payload,
auth_flow,
Expand Down Expand Up @@ -160,10 +162,11 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::PSync, payment_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentStatus,
req,
api::AuthFlow::Merchant,
Expand Down Expand Up @@ -221,10 +224,11 @@ pub async fn payment_intents_update(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::Authorize, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentUpdate,
req,
auth_flow,
Expand Down Expand Up @@ -284,10 +288,11 @@ pub async fn payment_intents_confirm(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::Authorize, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentConfirm,
req,
auth_flow,
Expand Down Expand Up @@ -337,10 +342,11 @@ pub async fn payment_intents_capture(
state.get_ref(),
&req,
capture_payload,
|state, merchant_account, payload| {
|state, auth, payload| {
payments::payments_core::<api_types::Capture, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentCapture,
payload,
api::AuthFlow::Merchant,
Expand Down Expand Up @@ -394,10 +400,11 @@ pub async fn payment_intents_cancel(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::Void, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentCancel,
req,
auth_flow,
Expand Down Expand Up @@ -437,9 +444,7 @@ pub async fn payment_intent_list(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
payments::list_payments(&*state.store, merchant_account, req)
},
|state, auth, req| payments::list_payments(&*state.store, auth.merchant_account, req),
&auth::ApiKeyAuth,
)
.await
Expand Down
18 changes: 11 additions & 7 deletions crates/router/src/compatibility/stripe/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ pub async fn refund_create(
state.get_ref(),
&req,
create_refund_req,
refunds::refund_create_core,
|state, auth, req| {
refunds::refund_create_core(state, auth.merchant_account, auth.key_store, req)
},
&auth::ApiKeyAuth,
)
.await
Expand Down Expand Up @@ -82,10 +84,11 @@ pub async fn refund_retrieve_with_gateway_creds(
state.get_ref(),
&req,
refund_request,
|state, merchant_account, refund_request| {
|state, auth, refund_request| {
refunds::refund_response_wrapper(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
refund_request,
refunds::refund_retrieve_core,
)
Expand Down Expand Up @@ -123,10 +126,11 @@ pub async fn refund_retrieve(
state.get_ref(),
&req,
refund_request,
|state, merchant_account, refund_request| {
|state, auth, refund_request| {
refunds::refund_response_wrapper(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
refund_request,
refunds::refund_retrieve_core,
)
Expand Down Expand Up @@ -162,8 +166,8 @@ pub async fn refund_update(
state.get_ref(),
&req,
create_refund_update_req,
|state, merchant_account, req| {
refunds::refund_update_core(&*state.store, merchant_account, &refund_id, req)
|state, auth, req| {
refunds::refund_update_core(&*state.store, auth.merchant_account, &refund_id, req)
},
&auth::ApiKeyAuth,
)
Expand Down
20 changes: 12 additions & 8 deletions crates/router/src/compatibility/stripe/setup_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ pub async fn setup_intents_create(
state.get_ref(),
&req,
create_payment_req,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::Verify, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentCreate,
req,
api::AuthFlow::Merchant,
Expand Down Expand Up @@ -101,10 +102,11 @@ pub async fn setup_intents_retrieve(
state.get_ref(),
&req,
payload,
|state, merchant_account, payload| {
|state, auth, payload| {
payments::payments_core::<api_types::PSync, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentStatus,
payload,
auth_flow,
Expand Down Expand Up @@ -163,10 +165,11 @@ pub async fn setup_intents_update(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::Verify, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentUpdate,
req,
auth_flow,
Expand Down Expand Up @@ -226,10 +229,11 @@ pub async fn setup_intents_confirm(
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
|state, auth, req| {
payments::payments_core::<api_types::Verify, api_types::PaymentsResponse, _, _, _>(
state,
merchant_account,
auth.merchant_account,
auth.key_store,
payments::PaymentConfirm,
req,
auth_flow,
Expand Down
Loading

0 comments on commit d321aa1

Please sign in to comment.