Skip to content

Commit

Permalink
feat(router): make core changes in payments flow to support increment…
Browse files Browse the repository at this point in the history
…al authorization (#3009)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
sai-harsha-vardhan and hyperswitch-bot[bot] authored Nov 30, 2023
1 parent 1e60c71 commit 1ca2ba4
Show file tree
Hide file tree
Showing 88 changed files with 363 additions and 11 deletions.
1 change: 1 addition & 0 deletions connector-template/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl<F,T> TryFrom<types::ResponseRouterData<F, {{project-name | downcase | pasca
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
}),
..item.data
})
Expand Down
6 changes: 6 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ pub struct PaymentsRequest {
/// The type of the payment that differentiates between normal and various types of mandate payments
#[schema(value_type = Option<PaymentType>)]
pub payment_type: Option<api_enums::PaymentType>,

///Request for an incremental authorization
pub request_incremental_authorization: Option<bool>,
}

impl PaymentsRequest {
Expand Down Expand Up @@ -2210,6 +2213,9 @@ pub struct PaymentsResponse {

/// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
pub merchant_connector_id: Option<String>,

/// If true incremental authorization can be performed on this payment
pub incremental_authorization_allowed: Option<bool>,
}

#[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)]
Expand Down
24 changes: 24 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod diesel_exports {
DbFutureUsage as FutureUsage, DbIntentStatus as IntentStatus,
DbMandateStatus as MandateStatus, DbPaymentMethodIssuerCode as PaymentMethodIssuerCode,
DbPaymentType as PaymentType, DbRefundStatus as RefundStatus,
DbRequestIncrementalAuthorization as RequestIncrementalAuthorization,
};
}

Expand Down Expand Up @@ -1387,6 +1388,29 @@ pub enum CountryAlpha2 {
US
}

#[derive(
Clone,
Debug,
Copy,
Default,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
)]
#[router_derive::diesel_enum(storage_type = "db_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum RequestIncrementalAuthorization {
True,
False,
#[default]
Default,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[rustfmt::skip]
pub enum CountryAlpha3 {
Expand Down
2 changes: 2 additions & 0 deletions crates/data_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ pub struct PaymentIntent {

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
pub request_incremental_authorization: storage_enums::RequestIncrementalAuthorization,
pub incremental_authorization_allowed: Option<bool>,
}
14 changes: 13 additions & 1 deletion crates/data_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub struct PaymentIntentNew {

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
pub request_incremental_authorization: storage_enums::RequestIncrementalAuthorization,
pub incremental_authorization_allowed: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -116,6 +118,7 @@ pub enum PaymentIntentUpdate {
amount_captured: Option<i64>,
return_url: Option<String>,
updated_by: String,
incremental_authorization_allowed: Option<bool>,
},
MetadataUpdate {
metadata: pii::SecretSerdeValue,
Expand All @@ -137,6 +140,7 @@ pub enum PaymentIntentUpdate {
},
PGStatusUpdate {
status: storage_enums::IntentStatus,
incremental_authorization_allowed: Option<bool>,
updated_by: String,
},
Update {
Expand Down Expand Up @@ -213,6 +217,7 @@ pub struct PaymentIntentUpdateInternal {

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
pub incremental_authorization_allowed: Option<bool>,
}

impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
Expand Down Expand Up @@ -283,10 +288,15 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
updated_by,
..Default::default()
},
PaymentIntentUpdate::PGStatusUpdate { status, updated_by } => Self {
PaymentIntentUpdate::PGStatusUpdate {
status,
updated_by,
incremental_authorization_allowed,
} => Self {
status: Some(status),
modified_at: Some(common_utils::date_time::now()),
updated_by,
incremental_authorization_allowed,
..Default::default()
},
PaymentIntentUpdate::MerchantStatusUpdate {
Expand All @@ -310,6 +320,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
// customer_id,
return_url,
updated_by,
incremental_authorization_allowed,
} => Self {
// amount,
// currency: Some(currency),
Expand All @@ -319,6 +330,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
return_url,
modified_at: Some(common_utils::date_time::now()),
updated_by,
incremental_authorization_allowed,
..Default::default()
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod diesel_exports {
DbPaymentType as PaymentType, DbPayoutStatus as PayoutStatus, DbPayoutType as PayoutType,
DbProcessTrackerStatus as ProcessTrackerStatus, DbReconStatus as ReconStatus,
DbRefundStatus as RefundStatus, DbRefundType as RefundType,
DbRequestIncrementalAuthorization as RequestIncrementalAuthorization,
DbRoutingAlgorithmKind as RoutingAlgorithmKind,
};
}
Expand Down
20 changes: 19 additions & 1 deletion crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use common_enums::RequestIncrementalAuthorization;
use common_utils::pii;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -51,6 +52,8 @@ pub struct PaymentIntent {

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
pub request_incremental_authorization: RequestIncrementalAuthorization,
pub incremental_authorization_allowed: Option<bool>,
}

#[derive(
Expand Down Expand Up @@ -106,6 +109,8 @@ pub struct PaymentIntentNew {

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
pub request_incremental_authorization: RequestIncrementalAuthorization,
pub incremental_authorization_allowed: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -115,6 +120,7 @@ pub enum PaymentIntentUpdate {
amount_captured: Option<i64>,
return_url: Option<String>,
updated_by: String,
incremental_authorization_allowed: Option<bool>,
},
MetadataUpdate {
metadata: pii::SecretSerdeValue,
Expand All @@ -137,6 +143,7 @@ pub enum PaymentIntentUpdate {
PGStatusUpdate {
status: storage_enums::IntentStatus,
updated_by: String,
incremental_authorization_allowed: Option<bool>,
},
Update {
amount: i64,
Expand Down Expand Up @@ -213,6 +220,7 @@ pub struct PaymentIntentUpdateInternal {

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
pub incremental_authorization_allowed: Option<bool>,
}

impl PaymentIntentUpdate {
Expand Down Expand Up @@ -243,6 +251,7 @@ impl PaymentIntentUpdate {
payment_confirm_source,
updated_by,
surcharge_applicable,
incremental_authorization_allowed,
} = self.into();
PaymentIntent {
amount: amount.unwrap_or(source.amount),
Expand Down Expand Up @@ -272,6 +281,8 @@ impl PaymentIntentUpdate {
payment_confirm_source: payment_confirm_source.or(source.payment_confirm_source),
updated_by,
surcharge_applicable: surcharge_applicable.or(source.surcharge_applicable),

incremental_authorization_allowed,
..source
}
}
Expand Down Expand Up @@ -345,10 +356,15 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
updated_by,
..Default::default()
},
PaymentIntentUpdate::PGStatusUpdate { status, updated_by } => Self {
PaymentIntentUpdate::PGStatusUpdate {
status,
updated_by,
incremental_authorization_allowed,
} => Self {
status: Some(status),
modified_at: Some(common_utils::date_time::now()),
updated_by,
incremental_authorization_allowed,
..Default::default()
},
PaymentIntentUpdate::MerchantStatusUpdate {
Expand All @@ -372,6 +388,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
// customer_id,
return_url,
updated_by,
incremental_authorization_allowed,
} => Self {
// amount,
// currency: Some(currency),
Expand All @@ -381,6 +398,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
return_url,
modified_at: Some(common_utils::date_time::now()),
updated_by,
incremental_authorization_allowed,
..Default::default()
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ diesel::table! {
#[max_length = 32]
updated_by -> Varchar,
surcharge_applicable -> Nullable<Bool>,
request_incremental_authorization -> RequestIncrementalAuthorization,
incremental_authorization_allowed -> Nullable<Bool>,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/aci/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ impl<F, T>
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: Some(item.response.id),
incremental_authorization_allowed: None,
}),
..item.data
})
Expand Down
8 changes: 8 additions & 0 deletions crates/router/src/connector/adyen/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2978,6 +2978,7 @@ impl TryFrom<types::PaymentsCancelResponseRouterData<AdyenCancelResponse>>
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
}),
..item.data
})
Expand Down Expand Up @@ -3011,6 +3012,7 @@ impl<F>
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
}),
payment_method_balance: Some(types::PaymentMethodBalance {
amount: item.response.balance.value,
Expand Down Expand Up @@ -3072,6 +3074,7 @@ pub fn get_adyen_response(
connector_metadata: None,
network_txn_id,
connector_response_reference_id: Some(response.merchant_reference),
incremental_authorization_allowed: None,
};
Ok((status, error, payments_response_data))
}
Expand Down Expand Up @@ -3171,6 +3174,7 @@ pub fn get_redirection_response(
connector_metadata,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
};
Ok((status, error, payments_response_data))
}
Expand Down Expand Up @@ -3222,6 +3226,7 @@ pub fn get_present_to_shopper_response(
connector_metadata,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
};
Ok((status, error, payments_response_data))
}
Expand Down Expand Up @@ -3270,6 +3275,7 @@ pub fn get_qr_code_response(
connector_metadata,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
};
Ok((status, error, payments_response_data))
}
Expand Down Expand Up @@ -3304,6 +3310,7 @@ pub fn get_redirection_error_response(
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
};

Ok((status, error, payments_response_data))
Expand Down Expand Up @@ -3638,6 +3645,7 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>>
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
}),
amount_captured: Some(item.response.amount.value),
..item.data
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/connector/airwallex/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ impl<F, T>
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
}),
..item.data
})
Expand Down Expand Up @@ -596,6 +597,7 @@ impl
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
}),
..item.data
})
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/connector/authorizedotnet/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ impl<F, T>
connector_response_reference_id: Some(
transaction_response.transaction_id.clone(),
),
incremental_authorization_allowed: None,
}),
},
..item.data
Expand Down Expand Up @@ -680,6 +681,7 @@ impl<F, T>
connector_response_reference_id: Some(
transaction_response.transaction_id.clone(),
),
incremental_authorization_allowed: None,
}),
},
..item.data
Expand Down Expand Up @@ -977,6 +979,7 @@ impl<F, Req>
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: Some(transaction.transaction_id.clone()),
incremental_authorization_allowed: None,
}),
status: payment_status,
..item.data
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/connector/bambora/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<F, T>
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: Some(pg_response.order_number.to_string()),
incremental_authorization_allowed: None,
}),
..item.data
}),
Expand All @@ -241,6 +242,7 @@ impl<F, T>
connector_response_reference_id: Some(
item.data.connector_request_reference_id.to_string(),
),
incremental_authorization_allowed: None,
}),
..item.data
})
Expand Down
Loading

0 comments on commit 1ca2ba4

Please sign in to comment.