Skip to content

Commit

Permalink
refactor: replace redirect url in next action with consent required f…
Browse files Browse the repository at this point in the history
…or mobile payment method
  • Loading branch information
Sakilmostak committed Nov 6, 2024
1 parent 4d2f41e commit 192b61a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 63 deletions.
16 changes: 12 additions & 4 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3955,9 +3955,9 @@ pub enum NextActionData {
InvokeSdkClient {
next_action_data: SdkNextActionData,
},
/// Contains url to collect otp for mobile payment
/// Contains consent to collect otp for mobile payment
CollectOtp {
collect_otp_url: String,
consent_data_required: MobilePaymentConsent,
},
}

Expand Down Expand Up @@ -4056,8 +4056,16 @@ pub struct VoucherNextStepData {

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct MobilePaymentNextStepData {
/// Url to collect OTP
pub collect_otp_url: String,
/// is consent details required to be shown by sdk
pub consent_data_required: MobilePaymentConsent,
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum MobilePaymentConsent {
ConsentRequired,
ConsentNotRequired,
ConsentOptional,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hyperswitch_domain_models::{
router_data::{ConnectorAuthType, RouterData},
router_flow_types::refunds::{Execute, RSync},
router_request_types::ResponseId,
router_response_types::{PaymentsResponseData, RedirectForm, RefundsResponseData},
router_response_types::{PaymentsResponseData, RefundsResponseData},
types::{PaymentsAuthorizeRouterData, PaymentsCompleteAuthorizeRouterData, RefundsRouterData},
};
use hyperswitch_interfaces::errors;
Expand Down Expand Up @@ -122,6 +122,12 @@ impl From<DigitalvirgoPaymentStatus> for common_enums::AttemptStatus {
pub struct DigitalvirgoPaymentsResponse {
state: DigitalvirgoPaymentStatus,
transaction_id: String,
consent: Option<DigitalvirgoConsentStatus>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DigitalvirgoConsentStatus {
required: Option<bool>,
}

impl<F, T> TryFrom<ResponseRouterData<F, DigitalvirgoPaymentsResponse, T, PaymentsResponseData>>
Expand All @@ -131,18 +137,33 @@ impl<F, T> TryFrom<ResponseRouterData<F, DigitalvirgoPaymentsResponse, T, Paymen
fn try_from(
item: ResponseRouterData<F, DigitalvirgoPaymentsResponse, T, PaymentsResponseData>,
) -> Result<Self, Self::Error> {
let status = common_enums::AttemptStatus::from(item.response.state);
let redirection_data = Box::new(match status {
common_enums::AttemptStatus::AuthenticationPending => Some(RedirectForm::DigitalVirgo),
_ => None,
});
// show if consent is required in next action
let connector_metadata = item
.response
.consent
.and_then(|consent_status| {
consent_status.required.map(|consent_required| {
if consent_required {
serde_json::json!({
"consent_data_required": "consent_required",
})
} else {
serde_json::json!({
"consent_data_required": "consent_not_required",
})
}
})
})
.or(Some(serde_json::json!({
"consent_data_required": "consent_not_required",
})));
Ok(Self {
status,
status: common_enums::AttemptStatus::from(item.response.state),
response: Ok(PaymentsResponseData::TransactionResponse {
resource_id: ResponseId::ConnectorTransactionId(item.response.transaction_id),
redirection_data,
redirection_data: Box::new(None),
mandate_reference: Box::new(None),
connector_metadata: None,
connector_metadata,
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ pub enum RedirectForm {
form_fields: HashMap<String, String>,
collection_id: Option<String>,
},
DigitalVirgo,
}

impl From<(url::Url, Method)> for RedirectForm {
Expand Down
10 changes: 6 additions & 4 deletions crates/router/src/compatibility/stripe/payment_intents/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ pub enum StripeNextAction {
next_action_data: payments::SdkNextActionData,
},
CollectOtp {
collect_otp_url: String,
consent_data_required: payments::MobilePaymentConsent,
},
}

Expand Down Expand Up @@ -895,9 +895,11 @@ pub(crate) fn into_stripe_next_action(
payments::NextActionData::InvokeSdkClient { next_action_data } => {
StripeNextAction::InvokeSdkClient { next_action_data }
}
payments::NextActionData::CollectOtp { collect_otp_url } => {
StripeNextAction::CollectOtp { collect_otp_url }
}
payments::NextActionData::CollectOtp {
consent_data_required,
} => StripeNextAction::CollectOtp {
consent_data_required,
},
})
}

Expand Down
10 changes: 6 additions & 4 deletions crates/router/src/compatibility/stripe/setup_intents/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ pub enum StripeNextAction {
next_action_data: payments::SdkNextActionData,
},
CollectOtp {
collect_otp_url: String,
consent_data_required: payments::MobilePaymentConsent,
},
}

Expand Down Expand Up @@ -449,9 +449,11 @@ pub(crate) fn into_stripe_next_action(
payments::NextActionData::InvokeSdkClient { next_action_data } => {
StripeNextAction::InvokeSdkClient { next_action_data }
}
payments::NextActionData::CollectOtp { collect_otp_url } => {
StripeNextAction::CollectOtp { collect_otp_url }
}
payments::NextActionData::CollectOtp {
consent_data_required,
} => StripeNextAction::CollectOtp {
consent_data_required,
},
})
}

Expand Down
29 changes: 11 additions & 18 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,7 @@ where

let next_action_voucher = voucher_next_steps_check(payment_attempt.clone())?;

let next_action_mobile_payment =
mobile_payment_next_steps_check(base_url, &payment_attempt, &payment_intent)?;
let next_action_mobile_payment = mobile_payment_next_steps_check(&payment_attempt)?;

let next_action_containing_qr_code_url = qr_code_next_steps_check(payment_attempt.clone())?;

Expand Down Expand Up @@ -1384,7 +1383,7 @@ where
}))
.or(next_action_mobile_payment.map(|mobile_payment_data| {
api_models::payments::NextActionData::CollectOtp {
collect_otp_url: mobile_payment_data.collect_otp_url,
consent_data_required: mobile_payment_data.consent_data_required,
}
}))
.or(next_action_containing_qr_code_url.map(|qr_code_data| {
Expand Down Expand Up @@ -2003,24 +2002,18 @@ pub fn voucher_next_steps_check(

#[cfg(feature = "v1")]
pub fn mobile_payment_next_steps_check(
base_url: &str,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
) -> RouterResult<Option<api_models::payments::MobilePaymentNextStepData>> {
let mobile_payment_next_step = if let Some(diesel_models::enums::PaymentMethod::MobilePayment) =
payment_attempt.payment_method
{
Some(api_models::payments::MobilePaymentNextStepData {
collect_otp_url: helpers::create_startpay_url(
base_url,
payment_attempt,
payment_intent,
),
payment_attempt
.connector_metadata
.clone()
.map(|metadata| {
metadata
.parse_value("MobilePaymentNextStepData")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to parse the Value to NextRequirements struct")
})
} else {
None
};
Ok(mobile_payment_next_step)
.transpose()
}

pub fn change_order_details_to_new_type(
Expand Down
23 changes: 0 additions & 23 deletions crates/router/src/services/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1933,29 +1933,6 @@ pub fn build_redirection_form(
}
}
},
RedirectForm::DigitalVirgo => {
maud::html! {
(maud::DOCTYPE)
head {
meta name="viewport" content="width=device-width, initial-scale=1";
}

(PreEscaped(format!("<form id='payment_form'>
<input type='text' name='otp' required>
<input type='submit' value='Submit'>
</form>
<script>
function setFormAction() {{
var responseForm = document.getElementById('payment_form');
responseForm.action=window.location.pathname.replace(/payments\\/redirect\\/(\\w+)\\/(\\w+)\\/\\w+/, \"payments/$1/$2/redirect/complete/digitalvirgo\");
responseForm.method='POST';
}}
window.onload = setFormAction;
</script>")))
}
}
}
}

Expand Down

0 comments on commit 192b61a

Please sign in to comment.