-
Notifications
You must be signed in to change notification settings - Fork 264
feat(qwikcilver): add payment method eligibility check #2135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
70827f6
dae1e71
d51eb64
cc75234
a592409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,13 @@ use common_enums::{AttemptStatus, RechargeStatus, RefundStatus}; | |
| use common_utils::types::FloatMajorUnit; | ||
| use domain_types::{ | ||
| connector_flow::{ | ||
| Authorize, CreatePaymentMethod, GetPaymentMethod, Recharge, Refund, | ||
| ServerAuthenticationToken, | ||
| Authorize, CreatePaymentMethod, GetPaymentMethod, PaymentMethodEligibility, Recharge, | ||
| Refund, ServerAuthenticationToken, | ||
| }, | ||
| connector_types::{ | ||
| CreatePaymentMethodData, CreatePaymentMethodResponseData, CustomerInfo, | ||
| GetPaymentMethodData, GetPaymentMethodResponseData, PaymentFlowData, PaymentsAuthorizeData, | ||
| GetPaymentMethodData, GetPaymentMethodResponseData, PaymentFlowData, | ||
| PaymentMethodEligibilityData, PaymentMethodEligibilityResponse, PaymentsAuthorizeData, | ||
| PaymentsResponseData, RechargeRequestData, RechargeResponseData, RefundFlowData, | ||
| RefundsData, RefundsResponseData, ResponseId, ServerAuthenticationTokenRequestData, | ||
| ServerAuthenticationTokenResponseData, | ||
|
|
@@ -948,6 +949,14 @@ where | |
| #[serde(transparent)] | ||
| pub struct QwikcilverGetWalletResponse(pub QwikcilverWalletEnvelope); | ||
|
|
||
| /// Distinct response newtype for `PaymentMethodEligibility`. Wraps the identical | ||
| /// `QwikcilverWalletEnvelope` payload `GetPaymentMethod` parses — macro-generated templating | ||
| /// types are keyed by response type name, so this flow needs its own type to avoid colliding | ||
| /// with `GetPaymentMethod`'s templating impl, even though it's the same connector call. | ||
| #[derive(Debug, Clone, Deserialize, Serialize)] | ||
| #[serde(transparent)] | ||
| pub struct QwikcilverEligibilityResponse(pub QwikcilverWalletEnvelope); | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct QwikcilverWalletDetails { | ||
|
|
@@ -1204,6 +1213,73 @@ impl TryFrom<ResponseRouterData<QwikcilverGetWalletResponse, Self>> | |
| } | ||
| } | ||
|
|
||
| /// Performs the exact same wallet lookup as `GetPaymentMethod` and derives eligibility from | ||
| /// the wallet's status: ACTIVE → Eligible, INACTIVE → Ineligible. The resolved wallet's | ||
| /// payment method details (balance, items, etc.) are returned alongside the eligibility | ||
| /// verdict in the same response. | ||
| impl TryFrom<ResponseRouterData<QwikcilverEligibilityResponse, Self>> | ||
| for RouterDataV2< | ||
| PaymentMethodEligibility, | ||
| PaymentFlowData, | ||
| PaymentMethodEligibilityData, | ||
| PaymentMethodEligibilityResponse, | ||
| > | ||
| { | ||
| type Error = error_stack::Report<ConnectorError>; | ||
|
|
||
| fn try_from( | ||
| item: ResponseRouterData<QwikcilverEligibilityResponse, Self>, | ||
| ) -> Result<Self, Self::Error> { | ||
| let mut data = item.router_data; | ||
| let body = item.response.0; | ||
| data.resource_common_data.raw_connector_response = | ||
| serde_json::to_string(&body).ok().map(Secret::new); | ||
| data.response = match body.response_code { | ||
| QWIKCILVER_SUCCESS_CODE => { | ||
| let currency = data.request.amount.currency; | ||
| let (eligibility, payment_method_details) = | ||
| if let Some(wallet) = body.wallet.as_ref() { | ||
| let eligibility = match map_wallet_status(wallet.status.as_ref()) { | ||
| Some(common_enums::WalletStatus::Active) => { | ||
| common_enums::EligibilityStatus::Eligible | ||
| } | ||
| Some(common_enums::WalletStatus::Inactive) => { | ||
| common_enums::EligibilityStatus::Ineligible | ||
| } | ||
| Some(common_enums::WalletStatus::Unspecified) | None => { | ||
| common_enums::EligibilityStatus::Unknown | ||
| } | ||
| }; | ||
| ( | ||
| eligibility, | ||
| Some(wallet_details_to_payment_method_details( | ||
| wallet, | ||
| Some(currency), | ||
| )), | ||
| ) | ||
| } else { | ||
| (common_enums::EligibilityStatus::Unknown, None) | ||
| }; | ||
| Ok(PaymentMethodEligibilityResponse { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we will only check for wallet eligibility and not amount cause the payment can also be performed via split payments |
||
| eligibility, | ||
| payment_method_details, | ||
| status_code: u32::from(item.http_code), | ||
| }) | ||
| } | ||
| _ => { | ||
| let txn_id = body.transaction_id.map(|t| t.to_string()); | ||
| Err(error_response_from_qc( | ||
| (&body).into(), | ||
| txn_id, | ||
| item.http_code, | ||
| None, | ||
| )) | ||
| } | ||
| }; | ||
| Ok(data) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct QwikcilverErrorResponse { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amount.currencyis the order currency, but it drivesconvert_backon the wallet's balance.GetPaymentMethod(:1178) andCreatePaymentMethod(:1113) read the same envelope viacurrency_from_feature_data. A JPY order against the AED wallet from your repro turns2339.68into2340instead of233968, so/getand/eligibilityreport different balances for one wallet.Some(currency)at :1257 then becomes justcurrency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not required in connector_feature_data, passing it in the amount field itself