Skip to content

Commit 6281ae0

Browse files
feat(vsaas): add processor_merchant_id and created_by column in payment_intents and payments_attempts for v1 (#7768)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 8a68cc7 commit 6281ae0

30 files changed

+591
-105
lines changed

crates/common_utils/src/macros.rs

+384
Large diffs are not rendered by default.

crates/common_utils/src/types.rs

+20
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use crate::{
4949
},
5050
errors::{CustomResult, ParsingError, PercentageError, ValidationError},
5151
fp_utils::when,
52+
impl_enum_str,
5253
};
5354

5455
/// Represents Percentage Value between 0 and 100 both inclusive
@@ -1356,3 +1357,22 @@ where
13561357
self.0.to_sql(out)
13571358
}
13581359
}
1360+
1361+
impl_enum_str!(
1362+
tag_delimeter = ":",
1363+
/// CreatedBy conveys the information about the creator (identifier) as well as the origin or
1364+
/// trigger (Api, Jwt) of the record.
1365+
#[derive(Eq, PartialEq, Debug, Clone)]
1366+
pub enum CreatedBy {
1367+
/// Api variant
1368+
Api {
1369+
/// merchant id of creator.
1370+
merchant_id: String,
1371+
},
1372+
/// Jwt variant
1373+
Jwt {
1374+
/// user id of creator.
1375+
user_id: String,
1376+
},
1377+
}
1378+
);

crates/diesel_models/src/payment_attempt.rs

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct PaymentAttempt {
8989
pub capture_before: Option<PrimitiveDateTime>,
9090
pub card_discovery: Option<storage_enums::CardDiscovery>,
9191
pub charges: Option<common_types::payments::ConnectorChargeResponseData>,
92+
pub processor_merchant_id: Option<id_type::MerchantId>,
93+
pub created_by: Option<String>,
9294
pub payment_method_type_v2: storage_enums::PaymentMethod,
9395
pub connector_payment_id: Option<ConnectorTransactionId>,
9496
pub payment_method_subtype: storage_enums::PaymentMethodType,
@@ -197,6 +199,8 @@ pub struct PaymentAttempt {
197199
pub charges: Option<common_types::payments::ConnectorChargeResponseData>,
198200
pub issuer_error_code: Option<String>,
199201
pub issuer_error_message: Option<String>,
202+
pub processor_merchant_id: Option<id_type::MerchantId>,
203+
pub created_by: Option<String>,
200204
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
201205
}
202206

@@ -334,6 +338,8 @@ pub struct PaymentAttemptNew {
334338
pub network_decline_code: Option<String>,
335339
pub network_advice_code: Option<String>,
336340
pub network_error_message: Option<String>,
341+
pub processor_merchant_id: Option<id_type::MerchantId>,
342+
pub created_by: Option<String>,
337343
}
338344

339345
#[cfg(feature = "v1")]
@@ -411,6 +417,8 @@ pub struct PaymentAttemptNew {
411417
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
412418
pub capture_before: Option<PrimitiveDateTime>,
413419
pub card_discovery: Option<storage_enums::CardDiscovery>,
420+
pub processor_merchant_id: Option<id_type::MerchantId>,
421+
pub created_by: Option<String>,
414422
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
415423
}
416424

crates/diesel_models/src/payment_intent.rs

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub struct PaymentIntent {
6060
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
6161
pub force_3ds_challenge: Option<bool>,
6262
pub force_3ds_challenge_trigger: Option<bool>,
63+
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
64+
pub created_by: Option<String>,
6365
pub merchant_reference_id: Option<common_utils::id_type::PaymentReferenceId>,
6466
pub billing_address: Option<Encryption>,
6567
pub shipping_address: Option<Encryption>,
@@ -148,6 +150,8 @@ pub struct PaymentIntent {
148150
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
149151
pub force_3ds_challenge: Option<bool>,
150152
pub force_3ds_challenge_trigger: Option<bool>,
153+
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
154+
pub created_by: Option<String>,
151155
}
152156

153157
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression, PartialEq)]
@@ -337,6 +341,8 @@ pub struct PaymentIntentNew {
337341
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
338342
pub force_3ds_challenge: Option<bool>,
339343
pub force_3ds_challenge_trigger: Option<bool>,
344+
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
345+
pub created_by: Option<String>,
340346
}
341347

342348
#[cfg(feature = "v1")]
@@ -408,6 +414,8 @@ pub struct PaymentIntentNew {
408414
pub platform_merchant_id: Option<common_utils::id_type::MerchantId>,
409415
pub force_3ds_challenge: Option<bool>,
410416
pub force_3ds_challenge_trigger: Option<bool>,
417+
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
418+
pub created_by: Option<String>,
411419
}
412420

413421
#[cfg(feature = "v2")]

crates/diesel_models/src/schema.rs

+8
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ diesel::table! {
933933
#[max_length = 64]
934934
issuer_error_code -> Nullable<Varchar>,
935935
issuer_error_message -> Nullable<Text>,
936+
#[max_length = 64]
937+
processor_merchant_id -> Nullable<Varchar>,
938+
#[max_length = 255]
939+
created_by -> Nullable<Varchar>,
936940
setup_future_usage_applied -> Nullable<FutureUsage>,
937941
}
938942
}
@@ -1021,6 +1025,10 @@ diesel::table! {
10211025
platform_merchant_id -> Nullable<Varchar>,
10221026
force_3ds_challenge -> Nullable<Bool>,
10231027
force_3ds_challenge_trigger -> Nullable<Bool>,
1028+
#[max_length = 64]
1029+
processor_merchant_id -> Nullable<Varchar>,
1030+
#[max_length = 255]
1031+
created_by -> Nullable<Varchar>,
10241032
}
10251033
}
10261034

crates/diesel_models/src/schema_v2.rs

+8
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,10 @@ diesel::table! {
874874
capture_before -> Nullable<Timestamp>,
875875
card_discovery -> Nullable<CardDiscovery>,
876876
charges -> Nullable<Jsonb>,
877+
#[max_length = 64]
878+
processor_merchant_id -> Nullable<Varchar>,
879+
#[max_length = 255]
880+
created_by -> Nullable<Varchar>,
877881
payment_method_type_v2 -> Varchar,
878882
#[max_length = 128]
879883
connector_payment_id -> Nullable<Varchar>,
@@ -954,6 +958,10 @@ diesel::table! {
954958
force_3ds_challenge -> Nullable<Bool>,
955959
force_3ds_challenge_trigger -> Nullable<Bool>,
956960
#[max_length = 64]
961+
processor_merchant_id -> Nullable<Varchar>,
962+
#[max_length = 255]
963+
created_by -> Nullable<Varchar>,
964+
#[max_length = 64]
957965
merchant_reference_id -> Nullable<Varchar>,
958966
billing_address -> Nullable<Bytea>,
959967
shipping_address -> Nullable<Bytea>,

crates/diesel_models/src/user/sample_data.rs

+4
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ pub struct PaymentAttemptBatchNew {
210210
pub extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,
211211
pub capture_before: Option<PrimitiveDateTime>,
212212
pub card_discovery: Option<common_enums::CardDiscovery>,
213+
pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
214+
pub created_by: Option<String>,
213215
pub setup_future_usage_applied: Option<common_enums::FutureUsage>,
214216
}
215217

@@ -293,6 +295,8 @@ impl PaymentAttemptBatchNew {
293295
extended_authorization_applied: self.extended_authorization_applied,
294296
capture_before: self.capture_before,
295297
card_discovery: self.card_discovery,
298+
processor_merchant_id: self.processor_merchant_id,
299+
created_by: self.created_by,
296300
setup_future_usage_applied: self.setup_future_usage_applied,
297301
}
298302
}

crates/hyperswitch_domain_models/src/payments.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use common_utils::{
1515
errors::CustomResult,
1616
ext_traits::ValueExt,
1717
id_type, pii,
18-
types::{keymanager::ToEncryptable, MinorUnit},
18+
types::{keymanager::ToEncryptable, CreatedBy, MinorUnit},
1919
};
2020
use diesel_models::payment_intent::TaxDetails;
2121
#[cfg(feature = "v2")]
@@ -115,7 +115,8 @@ pub struct PaymentIntent {
115115
pub skip_external_tax_calculation: Option<bool>,
116116
pub request_extended_authorization: Option<RequestExtendedAuthorizationBool>,
117117
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
118-
pub platform_merchant_id: Option<id_type::MerchantId>,
118+
pub processor_merchant_id: id_type::MerchantId,
119+
pub created_by: Option<CreatedBy>,
119120
pub force_3ds_challenge: Option<bool>,
120121
pub force_3ds_challenge_trigger: Option<bool>,
121122
}
@@ -493,13 +494,15 @@ pub struct PaymentIntent {
493494
pub payment_link_config: Option<diesel_models::PaymentLinkConfigRequestForPayments>,
494495
/// The straight through routing algorithm id that is used for this payment. This overrides the default routing algorithm that is configured in business profile.
495496
pub routing_algorithm_id: Option<id_type::RoutingId>,
496-
/// Identifier for the platform merchant.
497-
pub platform_merchant_id: Option<id_type::MerchantId>,
498497
/// Split Payment Data
499498
pub split_payments: Option<common_types::payments::SplitPaymentsRequest>,
500499

501500
pub force_3ds_challenge: Option<bool>,
502501
pub force_3ds_challenge_trigger: Option<bool>,
502+
/// merchant who owns the credentials of the processor, i.e. processor owner
503+
pub processor_merchant_id: id_type::MerchantId,
504+
/// merchantwho invoked the resource based api (identifier) and through what source (Api, Jwt(Dashboard))
505+
pub created_by: Option<CreatedBy>,
503506
}
504507

505508
#[cfg(feature = "v2")]
@@ -655,11 +658,11 @@ impl PaymentIntent {
655658
.payment_link_config
656659
.map(ApiModelToDieselModelConvertor::convert_from),
657660
routing_algorithm_id: request.routing_algorithm_id,
658-
platform_merchant_id: platform_merchant_id
659-
.map(|merchant_account| merchant_account.get_id().to_owned()),
660661
split_payments: None,
661662
force_3ds_challenge: None,
662663
force_3ds_challenge_trigger: None,
664+
processor_merchant_id: merchant_account.get_id().clone(),
665+
created_by: None,
663666
})
664667
}
665668

crates/hyperswitch_domain_models/src/payments/payment_attempt.rs

+45-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use common_utils::{
1515
id_type, pii,
1616
types::{
1717
keymanager::{self, KeyManagerState},
18-
ConnectorTransactionId, ConnectorTransactionIdTrait, MinorUnit,
18+
ConnectorTransactionId, ConnectorTransactionIdTrait, CreatedBy, MinorUnit,
1919
},
2020
};
2121
use diesel_models::{
@@ -463,6 +463,10 @@ pub struct PaymentAttempt {
463463
pub charges: Option<common_types::payments::ConnectorChargeResponseData>,
464464
/// Additional data that might be required by hyperswitch, to enable some specific features.
465465
pub feature_metadata: Option<PaymentAttemptFeatureMetadata>,
466+
/// merchant who owns the credentials of the processor, i.e. processor owner
467+
pub processor_merchant_id: id_type::MerchantId,
468+
/// merchantwho invoked the resource based api (identifier) and through what source (Api, Jwt(Dashboard))
469+
pub created_by: Option<CreatedBy>,
466470
}
467471

468472
impl PaymentAttempt {
@@ -592,6 +596,8 @@ impl PaymentAttempt {
592596
id,
593597
card_discovery: None,
594598
feature_metadata: None,
599+
processor_merchant_id: payment_intent.merchant_id.clone(),
600+
created_by: None,
595601
})
596602
}
597603

@@ -679,6 +685,8 @@ impl PaymentAttempt {
679685
feature_metadata: None,
680686
id,
681687
card_discovery: None,
688+
processor_merchant_id: payment_intent.merchant_id.clone(),
689+
created_by: None,
682690
})
683691
}
684692

@@ -776,6 +784,8 @@ impl PaymentAttempt {
776784
}),
777785
card_discovery: None,
778786
charges: None,
787+
processor_merchant_id: payment_intent.merchant_id.clone(),
788+
created_by: None,
779789
})
780790
}
781791

@@ -868,6 +878,10 @@ pub struct PaymentAttempt {
868878
pub charges: Option<common_types::payments::ConnectorChargeResponseData>,
869879
pub issuer_error_code: Option<String>,
870880
pub issuer_error_message: Option<String>,
881+
/// merchant who owns the credentials of the processor, i.e. processor owner
882+
pub processor_merchant_id: id_type::MerchantId,
883+
/// merchantwho invoked the resource based api (identifier) and through what source (Api, Jwt(Dashboard))
884+
pub created_by: Option<CreatedBy>,
871885
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
872886
}
873887

@@ -1118,6 +1132,10 @@ pub struct PaymentAttemptNew {
11181132
pub extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,
11191133
pub capture_before: Option<PrimitiveDateTime>,
11201134
pub card_discovery: Option<common_enums::CardDiscovery>,
1135+
/// merchant who owns the credentials of the processor, i.e. processor owner
1136+
pub processor_merchant_id: id_type::MerchantId,
1137+
/// merchantwho invoked the resource based api (identifier) and through what source (Api, Jwt(Dashboard))
1138+
pub created_by: Option<CreatedBy>,
11211139
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
11221140
}
11231141

@@ -1868,6 +1886,8 @@ impl behaviour::Conversion for PaymentAttempt {
18681886
setup_future_usage_applied: self.setup_future_usage_applied,
18691887
// Below fields are deprecated. Please add any new fields above this line.
18701888
connector_transaction_data: None,
1889+
processor_merchant_id: Some(self.processor_merchant_id),
1890+
created_by: self.created_by.map(|cb| cb.to_string()),
18711891
})
18721892
}
18731893

@@ -1886,7 +1906,7 @@ impl behaviour::Conversion for PaymentAttempt {
18861906
.cloned();
18871907
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
18881908
payment_id: storage_model.payment_id,
1889-
merchant_id: storage_model.merchant_id,
1909+
merchant_id: storage_model.merchant_id.clone(),
18901910
attempt_id: storage_model.attempt_id,
18911911
status: storage_model.status,
18921912
net_amount: NetAmount::new(
@@ -1956,6 +1976,12 @@ impl behaviour::Conversion for PaymentAttempt {
19561976
charges: storage_model.charges,
19571977
issuer_error_code: storage_model.issuer_error_code,
19581978
issuer_error_message: storage_model.issuer_error_message,
1979+
processor_merchant_id: storage_model
1980+
.processor_merchant_id
1981+
.unwrap_or(storage_model.merchant_id),
1982+
created_by: storage_model
1983+
.created_by
1984+
.and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
19591985
setup_future_usage_applied: storage_model.setup_future_usage_applied,
19601986
})
19611987
}
@@ -2042,6 +2068,8 @@ impl behaviour::Conversion for PaymentAttempt {
20422068
extended_authorization_applied: self.extended_authorization_applied,
20432069
capture_before: self.capture_before,
20442070
card_discovery: self.card_discovery,
2071+
processor_merchant_id: Some(self.processor_merchant_id),
2072+
created_by: self.created_by.map(|cb| cb.to_string()),
20452073
setup_future_usage_applied: self.setup_future_usage_applied,
20462074
})
20472075
}
@@ -2112,6 +2140,8 @@ impl behaviour::Conversion for PaymentAttempt {
21122140
card_discovery,
21132141
charges,
21142142
feature_metadata,
2143+
processor_merchant_id,
2144+
created_by,
21152145
} = self;
21162146

21172147
let AttemptAmountDetails {
@@ -2204,6 +2234,8 @@ impl behaviour::Conversion for PaymentAttempt {
22042234
network_error_message: error
22052235
.as_ref()
22062236
.and_then(|details| details.network_error_message.clone()),
2237+
processor_merchant_id: Some(processor_merchant_id),
2238+
created_by: created_by.map(|cb| cb.to_string()),
22072239
})
22082240
}
22092241

@@ -2275,7 +2307,7 @@ impl behaviour::Conversion for PaymentAttempt {
22752307

22762308
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
22772309
payment_id: storage_model.payment_id,
2278-
merchant_id: storage_model.merchant_id,
2310+
merchant_id: storage_model.merchant_id.clone(),
22792311
id: storage_model.id,
22802312
status: storage_model.status,
22812313
amount_details,
@@ -2320,6 +2352,12 @@ impl behaviour::Conversion for PaymentAttempt {
23202352
connector_token_details: storage_model.connector_token_details,
23212353
card_discovery: storage_model.card_discovery,
23222354
feature_metadata: storage_model.feature_metadata.map(From::from),
2355+
processor_merchant_id: storage_model
2356+
.processor_merchant_id
2357+
.unwrap_or(storage_model.merchant_id),
2358+
created_by: storage_model
2359+
.created_by
2360+
.and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
23232361
})
23242362
}
23252363
.await
@@ -2376,6 +2414,8 @@ impl behaviour::Conversion for PaymentAttempt {
23762414
card_discovery,
23772415
charges,
23782416
feature_metadata,
2417+
processor_merchant_id,
2418+
created_by,
23792419
} = self;
23802420

23812421
let card_network = payment_method_data
@@ -2465,6 +2505,8 @@ impl behaviour::Conversion for PaymentAttempt {
24652505
network_error_message: error_details
24662506
.as_ref()
24672507
.and_then(|details| details.network_error_message.clone()),
2508+
processor_merchant_id: Some(processor_merchant_id),
2509+
created_by: created_by.map(|cb| cb.to_string()),
24682510
})
24692511
}
24702512
}

0 commit comments

Comments
 (0)