mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor: make NextAction as enum (#1234)
This commit is contained in:
committed by
GitHub
parent
48e537568d
commit
a359b76d09
@ -1067,21 +1067,20 @@ pub enum NextActionType {
|
|||||||
TriggerApi,
|
TriggerApi,
|
||||||
DisplayBankTransferInformation,
|
DisplayBankTransferInformation,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, ToSchema)]
|
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, ToSchema)]
|
||||||
pub struct NextAction {
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
/// Specifying the action type to be performed next
|
pub enum NextActionData {
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub next_action_type: NextActionType,
|
|
||||||
//TODO: Make an enum having redirect_to_url and bank_transfer_steps_and_charges_details and use here
|
|
||||||
/// Contains the url for redirection flow
|
/// Contains the url for redirection flow
|
||||||
#[schema(example = "https://router.juspay.io/redirect/fakushdfjlksdfasklhdfj")]
|
RedirectToUrl { redirect_to_url: String },
|
||||||
pub redirect_to_url: Option<String>,
|
|
||||||
/// Informs the next steps for bank transfer and also contains the charges details (ex: amount received, amount charged etc)
|
/// Informs the next steps for bank transfer and also contains the charges details (ex: amount received, amount charged etc)
|
||||||
pub bank_transfer_steps_and_charges_details: Option<NextStepsRequirements>,
|
DisplayBankTransferInformation {
|
||||||
|
bank_transfer_steps_and_charges_details: BankTransferNextStepsData,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct NextStepsRequirements {
|
pub struct BankTransferNextStepsData {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub bank_transfer_instructions: BankTransferInstructions,
|
pub bank_transfer_instructions: BankTransferInstructions,
|
||||||
pub receiver: ReceiverDetails,
|
pub receiver: ReceiverDetails,
|
||||||
@ -1268,7 +1267,7 @@ pub struct PaymentsResponse {
|
|||||||
pub statement_descriptor_suffix: Option<String>,
|
pub statement_descriptor_suffix: Option<String>,
|
||||||
|
|
||||||
/// Additional information required for redirection
|
/// Additional information required for redirection
|
||||||
pub next_action: Option<NextAction>,
|
pub next_action: Option<NextActionData>,
|
||||||
|
|
||||||
/// If the payment was cancelled the reason provided here
|
/// If the payment was cancelled the reason provided here
|
||||||
pub cancellation_reason: Option<String>,
|
pub cancellation_reason: Option<String>,
|
||||||
|
|||||||
@ -610,22 +610,34 @@ pub struct RedirectUrl {
|
|||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Serialize, Debug)]
|
#[derive(Eq, PartialEq, serde::Serialize, Debug)]
|
||||||
pub struct StripeNextAction {
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
#[serde(rename = "type")]
|
pub enum StripeNextAction {
|
||||||
stype: payments::NextActionType,
|
RedirectToUrl {
|
||||||
redirect_to_url: RedirectUrl,
|
redirect_to_url: RedirectUrl,
|
||||||
|
},
|
||||||
|
DisplayBankTransferInformation {
|
||||||
|
bank_transfer_steps_and_charges_details: payments::BankTransferNextStepsData,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_stripe_next_action(
|
pub(crate) fn into_stripe_next_action(
|
||||||
next_action: Option<payments::NextAction>,
|
next_action: Option<payments::NextActionData>,
|
||||||
return_url: Option<String>,
|
return_url: Option<String>,
|
||||||
) -> Option<StripeNextAction> {
|
) -> Option<StripeNextAction> {
|
||||||
next_action.map(|n| StripeNextAction {
|
next_action.map(|next_action_data| match next_action_data {
|
||||||
stype: n.next_action_type,
|
payments::NextActionData::RedirectToUrl { redirect_to_url } => {
|
||||||
|
StripeNextAction::RedirectToUrl {
|
||||||
redirect_to_url: RedirectUrl {
|
redirect_to_url: RedirectUrl {
|
||||||
return_url,
|
return_url,
|
||||||
url: n.redirect_to_url,
|
url: Some(redirect_to_url),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
payments::NextActionData::DisplayBankTransferInformation {
|
||||||
|
bank_transfer_steps_and_charges_details,
|
||||||
|
} => StripeNextAction::DisplayBankTransferInformation {
|
||||||
|
bank_transfer_steps_and_charges_details,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -284,22 +284,34 @@ pub struct RedirectUrl {
|
|||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Serialize)]
|
#[derive(Eq, PartialEq, serde::Serialize)]
|
||||||
pub struct StripeNextAction {
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
#[serde(rename = "type")]
|
pub enum StripeNextAction {
|
||||||
stype: payments::NextActionType,
|
RedirectToUrl {
|
||||||
redirect_to_url: RedirectUrl,
|
redirect_to_url: RedirectUrl,
|
||||||
|
},
|
||||||
|
DisplayBankTransferInformation {
|
||||||
|
bank_transfer_steps_and_charges_details: payments::BankTransferNextStepsData,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn into_stripe_next_action(
|
pub(crate) fn into_stripe_next_action(
|
||||||
next_action: Option<payments::NextAction>,
|
next_action: Option<payments::NextActionData>,
|
||||||
return_url: Option<String>,
|
return_url: Option<String>,
|
||||||
) -> Option<StripeNextAction> {
|
) -> Option<StripeNextAction> {
|
||||||
next_action.map(|n| StripeNextAction {
|
next_action.map(|next_action_data| match next_action_data {
|
||||||
stype: n.next_action_type,
|
payments::NextActionData::RedirectToUrl { redirect_to_url } => {
|
||||||
|
StripeNextAction::RedirectToUrl {
|
||||||
redirect_to_url: RedirectUrl {
|
redirect_to_url: RedirectUrl {
|
||||||
return_url,
|
return_url,
|
||||||
url: n.redirect_to_url,
|
url: Some(redirect_to_url),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
payments::NextActionData::DisplayBankTransferInformation {
|
||||||
|
bank_transfer_steps_and_charges_details,
|
||||||
|
} => StripeNextAction::DisplayBankTransferInformation {
|
||||||
|
bank_transfer_steps_and_charges_details,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1603,6 +1603,9 @@ impl<F, T>
|
|||||||
// Or we identify the mandate txns before hand and always call SetupIntent in case of mandate payment call
|
// Or we identify the mandate txns before hand and always call SetupIntent in case of mandate payment call
|
||||||
let network_txn_id = Option::foreign_from(item.response.latest_attempt);
|
let network_txn_id = Option::foreign_from(item.response.latest_attempt);
|
||||||
|
|
||||||
|
let connector_metadata =
|
||||||
|
get_connector_metadata(item.response.next_action.as_ref(), item.response.amount)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
status: enums::AttemptStatus::from(item.response.status),
|
status: enums::AttemptStatus::from(item.response.status),
|
||||||
// client_secret: Some(item.response.client_secret.clone().as_str()),
|
// client_secret: Some(item.response.client_secret.clone().as_str()),
|
||||||
@ -1613,7 +1616,7 @@ impl<F, T>
|
|||||||
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),
|
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),
|
||||||
redirection_data,
|
redirection_data,
|
||||||
mandate_reference,
|
mandate_reference,
|
||||||
connector_metadata: None,
|
connector_metadata,
|
||||||
network_txn_id,
|
network_txn_id,
|
||||||
}),
|
}),
|
||||||
amount_captured: Some(item.response.amount_received),
|
amount_captured: Some(item.response.amount_received),
|
||||||
|
|||||||
@ -380,7 +380,10 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
|
|||||||
api_models::enums::IntentStatus::RequiresCustomerAction => {
|
api_models::enums::IntentStatus::RequiresCustomerAction => {
|
||||||
let startpay_url = payments_response
|
let startpay_url = payments_response
|
||||||
.next_action
|
.next_action
|
||||||
.and_then(|next_action| next_action.redirect_to_url)
|
.and_then(|next_action_data| match next_action_data {
|
||||||
|
api_models::payments::NextActionData::RedirectToUrl { redirect_to_url } => Some(redirect_to_url),
|
||||||
|
api_models::payments::NextActionData::DisplayBankTransferInformation { .. } => None,
|
||||||
|
})
|
||||||
.ok_or(errors::ApiErrorResponse::InternalServerError)
|
.ok_or(errors::ApiErrorResponse::InternalServerError)
|
||||||
.into_report()
|
.into_report()
|
||||||
.attach_printable(
|
.attach_printable(
|
||||||
|
|||||||
@ -309,20 +309,19 @@ where
|
|||||||
if payment_intent.status == enums::IntentStatus::RequiresCustomerAction
|
if payment_intent.status == enums::IntentStatus::RequiresCustomerAction
|
||||||
|| bank_transfer_next_steps.is_some()
|
|| bank_transfer_next_steps.is_some()
|
||||||
{
|
{
|
||||||
let next_action_type = if bank_transfer_next_steps.is_some() {
|
next_action_response = bank_transfer_next_steps
|
||||||
api::NextActionType::DisplayBankTransferInformation
|
.map(|bank_transfer| {
|
||||||
} else {
|
api_models::payments::NextActionData::DisplayBankTransferInformation {
|
||||||
api::NextActionType::RedirectToUrl
|
bank_transfer_steps_and_charges_details: bank_transfer,
|
||||||
};
|
}
|
||||||
next_action_response = Some(api::NextAction {
|
})
|
||||||
next_action_type,
|
.or(Some(api_models::payments::NextActionData::RedirectToUrl {
|
||||||
redirect_to_url: Some(helpers::create_startpay_url(
|
redirect_to_url: helpers::create_startpay_url(
|
||||||
server,
|
server,
|
||||||
&payment_attempt,
|
&payment_attempt,
|
||||||
&payment_intent,
|
&payment_intent,
|
||||||
)),
|
),
|
||||||
bank_transfer_steps_and_charges_details: bank_transfer_next_steps,
|
}));
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut response: api::PaymentsResponse = Default::default();
|
let mut response: api::PaymentsResponse = Default::default();
|
||||||
@ -520,11 +519,11 @@ impl ForeignFrom<ephemeral_key::EphemeralKey> for api::ephemeral_key::EphemeralK
|
|||||||
|
|
||||||
pub fn bank_transfer_next_steps_check(
|
pub fn bank_transfer_next_steps_check(
|
||||||
payment_attempt: storage::PaymentAttempt,
|
payment_attempt: storage::PaymentAttempt,
|
||||||
) -> RouterResult<Option<api_models::payments::NextStepsRequirements>> {
|
) -> RouterResult<Option<api_models::payments::BankTransferNextStepsData>> {
|
||||||
let bank_transfer_next_step = if let Some(storage_models::enums::PaymentMethod::BankTransfer) =
|
let bank_transfer_next_step = if let Some(storage_models::enums::PaymentMethod::BankTransfer) =
|
||||||
payment_attempt.payment_method
|
payment_attempt.payment_method
|
||||||
{
|
{
|
||||||
let bank_transfer_next_steps: Option<api_models::payments::NextStepsRequirements> =
|
let bank_transfer_next_steps: Option<api_models::payments::BankTransferNextStepsData> =
|
||||||
payment_attempt
|
payment_attempt
|
||||||
.connector_metadata
|
.connector_metadata
|
||||||
.map(|metadata| {
|
.map(|metadata| {
|
||||||
|
|||||||
@ -177,7 +177,7 @@ Never share your secret api keys. Keep them guarded and secure.
|
|||||||
api_models::payments::NextActionType,
|
api_models::payments::NextActionType,
|
||||||
api_models::payments::Metadata,
|
api_models::payments::Metadata,
|
||||||
api_models::payments::WalletData,
|
api_models::payments::WalletData,
|
||||||
api_models::payments::NextAction,
|
api_models::payments::NextActionData,
|
||||||
api_models::payments::PayLaterData,
|
api_models::payments::PayLaterData,
|
||||||
api_models::payments::MandateData,
|
api_models::payments::MandateData,
|
||||||
api_models::payments::PhoneDetails,
|
api_models::payments::PhoneDetails,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
pub use api_models::payments::{
|
pub use api_models::payments::{
|
||||||
AcceptanceType, Address, AddressDetails, Amount, AuthenticationForStartResponse, Card,
|
AcceptanceType, Address, AddressDetails, Amount, AuthenticationForStartResponse, Card,
|
||||||
CustomerAcceptance, MandateData, MandateTxnType, MandateType, MandateValidationFields,
|
CustomerAcceptance, MandateData, MandateTxnType, MandateType, MandateValidationFields,
|
||||||
NextAction, NextActionType, OnlineMandate, PayLaterData, PaymentIdType, PaymentListConstraints,
|
NextActionType, OnlineMandate, PayLaterData, PaymentIdType, PaymentListConstraints,
|
||||||
PaymentListResponse, PaymentMethodData, PaymentMethodDataResponse, PaymentOp,
|
PaymentListResponse, PaymentMethodData, PaymentMethodDataResponse, PaymentOp,
|
||||||
PaymentRetrieveBody, PaymentRetrieveBodyWithCredentials, PaymentsCancelRequest,
|
PaymentRetrieveBody, PaymentRetrieveBodyWithCredentials, PaymentsCancelRequest,
|
||||||
PaymentsCaptureRequest, PaymentsRedirectRequest, PaymentsRedirectionResponse, PaymentsRequest,
|
PaymentsCaptureRequest, PaymentsRedirectRequest, PaymentsRedirectionResponse, PaymentsRequest,
|
||||||
|
|||||||
Reference in New Issue
Block a user