Skip to content
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
085530a
execute workflow
Aprabhat19 Jan 27, 2025
42ac580
untracked files
Aprabhat19 Jan 27, 2025
d9d35d5
chore: run formatter
hyperswitch-bot[bot] Jan 28, 2025
f6f855b
Merge branch 'main' of https://github.com/juspay/hyperswitch into pt-…
Aprabhat19 Jan 28, 2025
c7c72f2
clippy changes
Aprabhat19 Jan 30, 2025
b2f16dd
Merge branch 'pt-workflow-pcr' of https://github.com/juspay/hyperswit…
Aprabhat19 Jan 30, 2025
eef3ab9
chore: run formatter
hyperswitch-bot[bot] Jan 30, 2025
4305866
Merge branch 'main' into pt-workflow-pcr
Aprabhat19 Jan 31, 2025
bd6e859
fix spell check
Aprabhat19 Jan 31, 2025
3656226
psync workflow implementation
Aprabhat19 Feb 3, 2025
38bd1d2
minor changes
Aprabhat19 Feb 4, 2025
aaeb0b5
minor refactors
Aprabhat19 Feb 4, 2025
c76c0bc
Merge branch 'main' of https://github.com/juspay/hyperswitch into pt-…
Aprabhat19 Feb 4, 2025
d51a5cc
chore: move all the relevant imports under v2 feature flag
Aprabhat19 Feb 4, 2025
1c73830
naming changes
Aprabhat19 Feb 4, 2025
b604528
resolve conflicts with base branch
Aprabhat19 Feb 4, 2025
b6b87bd
refactor code'
Aprabhat19 Feb 4, 2025
96bc623
chore: run formatter
hyperswitch-bot[bot] Feb 4, 2025
cf6c99b
chore: run formatter
hyperswitch-bot[bot] Feb 4, 2025
7ad8cf4
clippy errors
Aprabhat19 Feb 5, 2025
c21bcf4
resolved conflicts with base branch
Aprabhat19 Feb 5, 2025
37589b4
remve the commented lines
Aprabhat19 Feb 5, 2025
cd37b5e
Merge branch 'pt-workflow-pcr' into psyn-task-workflow
Aprabhat19 Feb 12, 2025
65ea681
naming changes
Aprabhat19 Feb 16, 2025
b71c704
naming changes
Aprabhat19 Feb 16, 2025
1da2d70
resolved conflicts with base branch
Aprabhat19 Feb 16, 2025
a362465
empty commit
Aprabhat19 Feb 17, 2025
2925df3
minor refactors
Aprabhat19 Feb 17, 2025
e78c137
resolved conflicts
Aprabhat19 Mar 27, 2025
78dc642
resolved conflicts
Aprabhat19 Mar 27, 2025
f220f1c
fix spell check
Aprabhat19 Mar 27, 2025
cb2d5e5
clippy error
Aprabhat19 Apr 4, 2025
f81061d
resolve conflicts with base branch:
Aprabhat19 Apr 7, 2025
9786392
chore: run formatter
hyperswitch-bot[bot] Apr 7, 2025
0fda546
naming changes
Aprabhat19 Apr 9, 2025
1ac64a9
resolve conflicts with base branch
Aprabhat19 Apr 9, 2025
472060b
Merge branch 'psyn-task-workflow' of https://github.com/juspay/hypers…
Aprabhat19 Apr 9, 2025
753632a
Merge branch 'main' of https://github.com/juspay/hyperswitch into psy…
Aprabhat19 Apr 15, 2025
bac4a61
perform a record back before calling the proxy
Aprabhat19 Apr 21, 2025
e3f2133
make connector reference id optional
Aprabhat19 Apr 21, 2025
a839363
resolve conflicts
Aprabhat19 Apr 21, 2025
5a932a7
Merge branch 'main' into psyn-task-workflow
Aprabhat19 Apr 22, 2025
9c29fdf
address comments
Aprabhat19 Apr 22, 2025
a8cd608
Merge branch 'psyn-task-workflow' of https://github.com/juspay/hypers…
Aprabhat19 Apr 22, 2025
443e5ca
chore: run formatter
hyperswitch-bot[bot] Apr 22, 2025
70db6be
Merge branch 'main' of https://github.com/juspay/hyperswitch into psy…
Aprabhat19 Apr 23, 2025
e706916
log errors
Aprabhat19 Apr 24, 2025
e084568
Merge branch 'psyn-task-workflow' of https://github.com/juspay/hypers…
Aprabhat19 Apr 24, 2025
7d1dc44
Merge branch 'main' into psyn-task-workflow
Aprabhat19 Apr 28, 2025
356d5f5
resolve conflicts
Aprabhat19 Apr 29, 2025
c017822
chore: run formatter
hyperswitch-bot[bot] Apr 29, 2025
284dea8
Merge branch 'main' into psyn-task-workflow
Aprabhat19 Apr 30, 2025
a0bc9a0
allow proxy for processing payment attempts
Aprabhat19 Apr 30, 2025
e65b6bf
Merge branch 'psyn-task-workflow' of https://github.com/juspay/hypers…
Aprabhat19 Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8677,6 +8677,10 @@ pub struct PaymentsAttemptRecordRequest {
#[schema(example = "2022-09-10T10:11:12Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub invoice_next_billing_time: Option<PrimitiveDateTime>,

/// source where the payment was triggered by
#[schema(value_type = TriggeredBy, example = "internal" )]
pub triggered_by: common_enums::TriggeredBy,
}

/// Error details for the payment
Expand Down
12 changes: 12 additions & 0 deletions crates/diesel_models/src/process_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ pub mod business_status {
pub const EXECUTE_WORKFLOW_COMPLETE_FOR_REVIEW: &str =
"COMPLETED_EXECUTE_TASK_TO_TRIGGER_REVIEW";

/// This status indicates that the requeue was triggered for execute task
pub const EXECUTE_WORKFLOW_REQUEUE: &str = "TRIGGER_REQUEUE_FOR_EXECUTE_WORKFLOW";

/// This status indicates the completion of a psync task
pub const PSYNC_WORKFLOW_COMPLETE: &str = "COMPLETED_PSYNC_TASK";

/// This status indicates that the psync task was completed to trigger the review task
pub const PSYNC_WORKFLOW_COMPLETE_FOR_REVIEW: &str = "COMPLETED_PSYNC_TASK_TO_TRIGGER_REVIEW";

/// This status indicates that the requeue was triggered for psync task
pub const PSYNC_WORKFLOW_REQUEUE: &str = "TRIGGER_REQUEUE_FOR_PSYNC_WORKFLOW";

/// This status indicates the completion of a review task
pub const REVIEW_WORKFLOW_COMPLETE: &str = "COMPLETED_REVIEW_TASK";
}
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,13 @@ impl TryFrom<ChargebeeWebhookBody> for revenue_recovery::RevenueRecoveryAttemptD
Ok(Self {
amount,
currency,
merchant_reference_id,
merchant_reference_ids: Some(merchant_reference_id),
connector_transaction_id,
error_code,
error_message,
processor_payment_method_token: connector_mandate_details.mandate_id,
connector_customer_id: connector_mandate_details.customer_id,
connector_account_reference_id,
connector_account_reference_ids: Some(connector_account_reference_id),
transaction_created_at,
status,
payment_method_type,
Expand Down
16 changes: 16 additions & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,22 @@ impl From<&api_models::payments::PaymentAttemptAmountDetails>
}
}
#[cfg(feature = "v2")]
impl From<&payments::payment_attempt::AttemptAmountDetailsSetter>
for api_models::payments::PaymentAttemptAmountDetails
{
fn from(amount: &payments::payment_attempt::AttemptAmountDetailsSetter) -> Self {
Self {
net_amount: amount.net_amount,
amount_to_capture: amount.amount_to_capture,
surcharge_amount: amount.surcharge_amount,
tax_on_surcharge: amount.tax_on_surcharge,
amount_capturable: amount.amount_capturable,
shipping_cost: amount.shipping_cost,
order_tax_amount: amount.order_tax_amount,
}
}
}
#[cfg(feature = "v2")]
impl From<&api_models::payments::RecordAttemptErrorDetails>
for payments::payment_attempt::ErrorDetails
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,20 @@ impl MerchantConnectorAccount {

pub fn get_payment_merchant_connector_account_id_using_account_reference_id(
&self,
account_reference_id: String,
account_reference_id: Option<String>,
) -> Option<id_type::MerchantConnectorAccountId> {
self.feature_metadata.as_ref().and_then(|metadata| {
metadata.revenue_recovery.as_ref().and_then(|recovery| {
recovery
.mca_reference
.billing_to_recovery
.get(&account_reference_id)
.cloned()
})
metadata
.revenue_recovery
.as_ref()
.zip(account_reference_id)
.and_then(|(recovery, account_reference_id)| {
recovery
.mca_reference
.billing_to_recovery
.get(&account_reference_id)
.cloned()
})
})
}
}
Expand Down
38 changes: 37 additions & 1 deletion crates/hyperswitch_domain_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use self::payment_attempt::PaymentAttempt;
#[cfg(feature = "v2")]
use crate::{
address::Address, business_profile, customer, errors, merchant_account,
merchant_connector_account, payment_address, payment_method_data, routing,
merchant_connector_account, payment_address, payment_method_data, revenue_recovery, routing,
ApiModelToDieselModelConvertor,
};
#[cfg(feature = "v1")]
Expand Down Expand Up @@ -675,6 +675,41 @@ impl PaymentIntent {
self.feature_metadata.clone()
}

pub fn create_revenue_recovery_attempt_data(
&self,
revenue_recovery_metadata: api_models::payments::PaymentRevenueRecoveryMetadata,
billing_connector_account: &merchant_connector_account::MerchantConnectorAccount,
) -> revenue_recovery::RevenueRecoveryAttemptData {
revenue_recovery::RevenueRecoveryAttemptData {
amount: self.amount_details.order_amount,
currency: self.amount_details.currency,
merchant_reference_ids: self.merchant_reference_id.clone(), // is the intent id
connector_transaction_id: None, // No connector id
error_code: None,
error_message: None,
processor_payment_method_token: revenue_recovery_metadata
.billing_connector_payment_details
.payment_processor_token,
connector_customer_id: revenue_recovery_metadata
.billing_connector_payment_details
.connector_customer_id,
connector_account_reference_ids: None,
transaction_created_at: None, // would unwrap or as now
status: common_enums::AttemptStatus::Started,
payment_method_type: self
.get_payment_method_type()
.unwrap_or(revenue_recovery_metadata.payment_method_type),
payment_method_sub_type: self
.get_payment_method_sub_type()
.unwrap_or(revenue_recovery_metadata.payment_method_subtype),
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
retry_count: None,
invoice_next_billing_time: None,
}
}

pub fn get_optional_customer_id(
&self,
) -> CustomResult<Option<id_type::CustomerId>, common_utils::errors::ValidationError> {
Expand Down Expand Up @@ -855,6 +890,7 @@ pub struct RevenueRecoveryData {
pub connector_customer_id: String,
pub retry_count: Option<u16>,
pub invoice_next_billing_time: Option<PrimitiveDateTime>,
pub triggered_by: storage_enums::enums::TriggeredBy,
}

#[cfg(feature = "v2")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ impl PaymentAttempt {
let feature_metadata = PaymentAttemptFeatureMetadata {
revenue_recovery: Some({
PaymentAttemptRevenueRecoveryData {
attempt_triggered_by: common_enums::TriggeredBy::External,
attempt_triggered_by: request.triggered_by,
}
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ pub enum PaymentIntentUpdate {
status: common_enums::IntentStatus,
feature_metadata: Box<Option<diesel_models::types::FeatureMetadata>>,
updated_by: String,
active_attempt_id: Option<id_type::GlobalAttemptId>,
},
/// UpdateIntent
UpdateIntent(Box<PaymentIntentUpdateFields>),
Expand Down Expand Up @@ -717,10 +718,11 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternal
status,
feature_metadata,
updated_by,
active_attempt_id,
} => Ok(Self {
status: Some(status),
amount_captured: None,
active_attempt_id: None,
active_attempt_id: Some(active_attempt_id),
modified_at: common_utils::date_time::now(),
amount: None,
currency: None,
Expand Down
8 changes: 4 additions & 4 deletions crates/hyperswitch_domain_models/src/revenue_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct RevenueRecoveryAttemptData {
/// currency of the transaction
pub currency: common_enums::Currency,
/// merchant reference id at billing connector. ex: invoice_id
pub merchant_reference_id: id_type::PaymentReferenceId,
pub merchant_reference_ids: Option<id_type::PaymentReferenceId>,
/// transaction id reference at payment connector
pub connector_transaction_id: Option<util_types::ConnectorTransactionId>,
/// error code sent by billing connector.
Expand All @@ -25,7 +25,7 @@ pub struct RevenueRecoveryAttemptData {
/// customer id at payment connector for which mandate is attached.
pub connector_customer_id: String,
/// Payment gateway identifier id at billing processor.
pub connector_account_reference_id: String,
pub connector_account_reference_ids: Option<String>,
/// timestamp at which transaction has been created at billing connector
pub transaction_created_at: Option<PrimitiveDateTime>,
/// transaction status at billing connector equivalent to payment attempt status.
Expand Down Expand Up @@ -225,13 +225,13 @@ impl From<&BillingConnectorPaymentsSyncResponse> for RevenueRecoveryAttemptData
Self {
amount: data.amount,
currency: data.currency,
merchant_reference_id: data.merchant_reference_id.clone(),
merchant_reference_ids: Some(data.merchant_reference_id.clone()),
connector_transaction_id: data.connector_transaction_id.clone(),
error_code: data.error_code.clone(),
error_message: data.error_message.clone(),
processor_payment_method_token: data.processor_payment_method_token.clone(),
connector_customer_id: data.connector_customer_id.clone(),
connector_account_reference_id: data.connector_account_reference_id.clone(),
connector_account_reference_ids: Some(data.connector_account_reference_id.clone()),
transaction_created_at: data.transaction_created_at,
status: data.status,
payment_method_type: data.payment_method_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl<F: Send + Clone + Sync>
connector_customer_id: request.connector_customer_id.clone(),
retry_count: request.retry_count,
invoice_next_billing_time: request.invoice_next_billing_time,
triggered_by: request.triggered_by,
};

let payment_data = PaymentAttemptRecordData {
Expand Down Expand Up @@ -233,12 +234,20 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentAttemptRecordData<F>, PaymentsAtte
F: 'b + Send,
{
let feature_metadata = payment_data.get_updated_feature_metadata()?;
let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::RecordUpdate
let active_attempt_id = match payment_data.revenue_recovery_data.triggered_by {
common_enums::TriggeredBy::Internal => Some(payment_data.payment_attempt.id.clone()),
common_enums::TriggeredBy::External => None,
};
let payment_intent_update =

hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::RecordUpdate
{
status: common_enums::IntentStatus::from(payment_data.payment_attempt.status),
feature_metadata: Box::new(feature_metadata),
updated_by: storage_scheme.to_string(),
};
active_attempt_id
}
;
payment_data.payment_intent = state
.store
.update_payment_intent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,40 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentConfirmData<F>, ProxyPaymentsR
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while encrypting payment intent details")?;

let payment_attempt_domain_model: hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt =
hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt::proxy_create_domain_model(
&payment_intent,
cell_id,
storage_scheme,
request,
encrypted_data
)
.await?;
let payment_attempt = match payment_intent.active_attempt_id.clone() {
Some(ref active_attempt_id) => db
.find_payment_attempt_by_id(
key_manager_state,
key_store,
active_attempt_id,
storage_scheme,
)
.await
.change_context(errors::ApiErrorResponse::PaymentNotFound)
.attach_printable("Could not find payment attempt")?,

None => {
let payment_attempt_domain_model: hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt =
hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt::proxy_create_domain_model(
&payment_intent,
cell_id,
storage_scheme,
request,
encrypted_data
)
.await?;
db.insert_payment_attempt(
key_manager_state,
key_store,
payment_attempt_domain_model,
storage_scheme,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Could not insert payment attempt")?
}
};

let payment_attempt = db
.insert_payment_attempt(
key_manager_state,
key_store,
payment_attempt_domain_model,
storage_scheme,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Could not insert payment attempt")?;
let processor_payment_token = request.recurring_details.processor_payment_token.clone();

let payment_address = hyperswitch_domain_models::payment_address::PaymentAddress::new(
Expand Down
Loading
Loading