-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into use-card-bin
- Loading branch information
Showing
32 changed files
with
1,663 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use common_enums::{AuthenticationType, CountryAlpha2}; | ||
use common_utils::{self}; | ||
use time::PrimitiveDateTime; | ||
|
||
use crate::enums::Connector; | ||
|
||
#[derive(serde::Deserialize, Debug, serde::Serialize)] | ||
pub struct SampleDataRequest { | ||
pub record: Option<usize>, | ||
pub connector: Option<Vec<Connector>>, | ||
#[serde(default, with = "common_utils::custom_serde::iso8601::option")] | ||
pub start_time: Option<PrimitiveDateTime>, | ||
#[serde(default, with = "common_utils::custom_serde::iso8601::option")] | ||
pub end_time: Option<PrimitiveDateTime>, | ||
// The amount for each sample will be between min_amount and max_amount (in dollars) | ||
pub min_amount: Option<i64>, | ||
pub max_amount: Option<i64>, | ||
pub currency: Option<Vec<common_enums::Currency>>, | ||
pub auth_type: Option<Vec<AuthenticationType>>, | ||
pub business_country: Option<CountryAlpha2>, | ||
pub business_label: Option<String>, | ||
pub profile_id: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
use async_bb8_diesel::AsyncRunQueryDsl; | ||
use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; | ||
use error_stack::{IntoReport, ResultExt}; | ||
use router_env::logger; | ||
|
||
use crate::{ | ||
errors, | ||
schema::{ | ||
payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, | ||
refund::dsl as refund_dsl, | ||
}, | ||
user::sample_data::PaymentAttemptBatchNew, | ||
PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, | ||
StorageResult, | ||
}; | ||
|
||
pub async fn insert_payment_intents( | ||
conn: &PgPooledConn, | ||
batch: Vec<PaymentIntentNew>, | ||
) -> StorageResult<Vec<PaymentIntent>> { | ||
let query = diesel::insert_into(<PaymentIntent>::table()).values(batch); | ||
|
||
logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string()); | ||
|
||
query | ||
.get_results_async(conn) | ||
.await | ||
.into_report() | ||
.change_context(errors::DatabaseError::Others) | ||
.attach_printable("Error while inserting payment intents") | ||
} | ||
pub async fn insert_payment_attempts( | ||
conn: &PgPooledConn, | ||
batch: Vec<PaymentAttemptBatchNew>, | ||
) -> StorageResult<Vec<PaymentAttempt>> { | ||
let query = diesel::insert_into(<PaymentAttempt>::table()).values(batch); | ||
|
||
logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string()); | ||
|
||
query | ||
.get_results_async(conn) | ||
.await | ||
.into_report() | ||
.change_context(errors::DatabaseError::Others) | ||
.attach_printable("Error while inserting payment attempts") | ||
} | ||
|
||
pub async fn insert_refunds( | ||
conn: &PgPooledConn, | ||
batch: Vec<RefundNew>, | ||
) -> StorageResult<Vec<Refund>> { | ||
let query = diesel::insert_into(<Refund>::table()).values(batch); | ||
|
||
logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string()); | ||
|
||
query | ||
.get_results_async(conn) | ||
.await | ||
.into_report() | ||
.change_context(errors::DatabaseError::Others) | ||
.attach_printable("Error while inserting refunds") | ||
} | ||
|
||
pub async fn delete_payment_intents( | ||
conn: &PgPooledConn, | ||
merchant_id: &str, | ||
) -> StorageResult<Vec<PaymentIntent>> { | ||
let query = diesel::delete(<PaymentIntent>::table()) | ||
.filter(payment_intent_dsl::merchant_id.eq(merchant_id.to_owned())) | ||
.filter(payment_intent_dsl::payment_id.like("test_%")); | ||
|
||
logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string()); | ||
|
||
query | ||
.get_results_async(conn) | ||
.await | ||
.into_report() | ||
.change_context(errors::DatabaseError::Others) | ||
.attach_printable("Error while deleting payment intents") | ||
.and_then(|result| match result.len() { | ||
n if n > 0 => { | ||
logger::debug!("{n} records deleted"); | ||
Ok(result) | ||
} | ||
0 => Err(error_stack::report!(errors::DatabaseError::NotFound) | ||
.attach_printable("No records deleted")), | ||
_ => Ok(result), | ||
}) | ||
} | ||
pub async fn delete_payment_attempts( | ||
conn: &PgPooledConn, | ||
merchant_id: &str, | ||
) -> StorageResult<Vec<PaymentAttempt>> { | ||
let query = diesel::delete(<PaymentAttempt>::table()) | ||
.filter(payment_attempt_dsl::merchant_id.eq(merchant_id.to_owned())) | ||
.filter(payment_attempt_dsl::payment_id.like("test_%")); | ||
|
||
logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string()); | ||
|
||
query | ||
.get_results_async(conn) | ||
.await | ||
.into_report() | ||
.change_context(errors::DatabaseError::Others) | ||
.attach_printable("Error while deleting payment attempts") | ||
.and_then(|result| match result.len() { | ||
n if n > 0 => { | ||
logger::debug!("{n} records deleted"); | ||
Ok(result) | ||
} | ||
0 => Err(error_stack::report!(errors::DatabaseError::NotFound) | ||
.attach_printable("No records deleted")), | ||
_ => Ok(result), | ||
}) | ||
} | ||
|
||
pub async fn delete_refunds(conn: &PgPooledConn, merchant_id: &str) -> StorageResult<Vec<Refund>> { | ||
let query = diesel::delete(<Refund>::table()) | ||
.filter(refund_dsl::merchant_id.eq(merchant_id.to_owned())) | ||
.filter(refund_dsl::payment_id.like("test_%")); | ||
|
||
logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string()); | ||
|
||
query | ||
.get_results_async(conn) | ||
.await | ||
.into_report() | ||
.change_context(errors::DatabaseError::Others) | ||
.attach_printable("Error while deleting refunds") | ||
.and_then(|result| match result.len() { | ||
n if n > 0 => { | ||
logger::debug!("{n} records deleted"); | ||
Ok(result) | ||
} | ||
0 => Err(error_stack::report!(errors::DatabaseError::NotFound) | ||
.attach_printable("No records deleted")), | ||
_ => Ok(result), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.