refactor(payment_id): add payment id domain type (#5738)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-09-02 09:21:33 +05:30
committed by GitHub
parent 4b0564e0e8
commit 7296cceba3
150 changed files with 880 additions and 803 deletions

View File

@ -313,10 +313,11 @@ async fn payments_create_core() {
.await
.unwrap();
let payment_id =
id_type::PaymentId::try_from(Cow::Borrowed("pay_mbabizu24mvu3mela5njyhpit10")).unwrap();
let req = api::PaymentsRequest {
payment_id: Some(api::PaymentIdType::PaymentIntentId(
"pay_mbabizu24mvu3mela5njyhpit10".to_string(),
)),
payment_id: Some(api::PaymentIdType::PaymentIntentId(payment_id.clone())),
merchant_id: Some(merchant_id.clone()),
amount: Some(MinorUnit::new(6540).into()),
currency: Some(api_enums::Currency::USD),
@ -364,7 +365,7 @@ async fn payments_create_core() {
};
let expected_response = api::PaymentsResponse {
payment_id: "pay_mbabizu24mvu3mela5njyhpit10".to_string(),
payment_id,
status: api_enums::IntentStatus::Succeeded,
amount: MinorUnit::new(6540),
amount_capturable: MinorUnit::new(0),
@ -548,9 +549,11 @@ async fn payments_create_core_adyen_no_redirect() {
.get_session_state("public", || {})
.unwrap();
let payment_id =
id_type::PaymentId::try_from(Cow::Borrowed("pay_mbabizu24mvu3mela5njyhpit10")).unwrap();
let customer_id = format!("cust_{}", Uuid::new_v4());
let merchant_id = id_type::MerchantId::try_from(Cow::from("juspay_merchant")).unwrap();
let payment_id = "pay_mbabizu24mvu3mela5njyhpit10".to_string();
let key_manager_state = &(&state).into();
let key_store = state
.store

View File

@ -73,10 +73,11 @@ async fn payments_create_core() {
.await
.unwrap();
let payment_id =
id_type::PaymentId::try_from(Cow::Borrowed("pay_mbabizu24mvu3mela5njyhpit10")).unwrap();
let req = api::PaymentsRequest {
payment_id: Some(api::PaymentIdType::PaymentIntentId(
"pay_mbabizu24mvu3mela5njyhpit10".to_string(),
)),
payment_id: Some(api::PaymentIdType::PaymentIntentId(payment_id.clone())),
merchant_id: Some(merchant_id.clone()),
amount: Some(MinorUnit::new(6540).into()),
currency: Some(api_enums::Currency::USD),
@ -124,7 +125,7 @@ async fn payments_create_core() {
};
let expected_response = api::PaymentsResponse {
payment_id: "pay_mbabizu24mvu3mela5njyhpit10".to_string(),
payment_id,
status: api_enums::IntentStatus::Succeeded,
amount: MinorUnit::new(6540),
amount_capturable: MinorUnit::new(0),
@ -317,7 +318,9 @@ async fn payments_create_core_adyen_no_redirect() {
let customer_id = format!("cust_{}", Uuid::new_v4());
let merchant_id = id_type::MerchantId::try_from(Cow::from("juspay_merchant")).unwrap();
let payment_id = "pay_mbabizu24mvu3mela5njyhpit10".to_string();
let payment_id =
id_type::PaymentId::try_from(Cow::Borrowed("pay_mbabizu24mvu3mela5njyhpit10")).unwrap();
let key_manager_state = &(&state).into();
let key_store = state
.store

View File

@ -16,7 +16,7 @@ async fn refund_create_fail_stripe() {
let user_client = client.user("321");
let payment_id = format!("test_{}", uuid::Uuid::new_v4());
let payment_id = common_utils::id_type::PaymentId::generate_test_payment_id_for_sample_data();
let refund: serde_json::Value = user_client.create_refund(&app, &payment_id, 10).await;
assert_eq!(refund.get("error").unwrap().get("message").unwrap(), "Access forbidden, invalid API key was used. Please create your new API key from the Dashboard Settings section.");
@ -30,7 +30,7 @@ async fn refund_create_fail_adyen() {
let user_client = client.user("321");
let payment_id = format!("test_{}", uuid::Uuid::new_v4());
let payment_id = common_utils::id_type::PaymentId::generate_test_payment_id_for_sample_data();
let refund: serde_json::Value = user_client.create_refund(&app, &payment_id, 10).await;
assert_eq!(refund.get("error").unwrap().get("message").unwrap(), "Access forbidden, invalid API key was used. Please create your new API key from the Dashboard Settings section.");

View File

@ -146,7 +146,7 @@ impl AppClient<User> {
pub async fn create_refund<T: DeserializeOwned, S, B>(
&self,
app: &S,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
amount: usize,
) -> T
where
@ -337,7 +337,7 @@ fn _mk_payment_confirm() -> Value {
})
}
fn mk_refund(payment_id: &str, amount: usize) -> Value {
fn mk_refund(payment_id: &common_utils::id_type::PaymentId, amount: usize) -> Value {
let timestamp = common_utils::date_time::now().to_string();
json!({
@ -407,7 +407,7 @@ pub struct Message {
#[derive(Deserialize, Deref)]
pub struct PaymentId {
payment_id: String,
payment_id: common_utils::id_type::PaymentId,
}
#[derive(Deserialize, Deref)]