feat(router): add fallback while add card and retrieve card from rust locker (#2888)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Shankar Singh C
2023-11-16 22:54:14 +05:30
committed by GitHub
parent 6ebf14aabc
commit f735fb0551
7 changed files with 208 additions and 131 deletions

View File

@ -24,6 +24,7 @@ optin = "optin" # Boku preflow name
optin_id = "optin_id" # Boku's id for optin flow
deriver = "deriver"
Deriver = "Deriver"
requestor_card_reference = "requestor_card_reference"
[default.extend-words]
aci = "aci" # Name of a connector

View File

@ -95,7 +95,7 @@ sampling_rate = 0.1 # decimal rate between 0.0
otel_exporter_otlp_endpoint = "http://localhost:4317" # endpoint to send metrics and traces to, can include port number
otel_exporter_otlp_timeout = 5000 # timeout (in milliseconds) for sending metrics and traces
use_xray_generator = false # Set this to true for AWS X-ray compatible traces
route_to_trace = [ "*/confirm" ]
route_to_trace = ["*/confirm"]
# This section provides some secret values.
[secrets]
@ -234,11 +234,11 @@ adyen = { banks = "e_platby_vub,postova_banka,sporo_pay,tatra_pay,viamo" }
# Bank redirect configs for allowed banks through online_banking_poland payment method
[bank_config.online_banking_poland]
adyen = { banks = "blik_psp,place_zipko,m_bank,pay_with_ing,santander_przelew24,bank_pekaosa,bank_millennium,pay_with_alior_bank,banki_spoldzielcze,pay_with_inteligo,bnp_paribas_poland,bank_nowy_sa,credit_agricole,pay_with_bos,pay_with_citi_handlowy,pay_with_plus_bank,toyota_bank,velo_bank,e_transfer_pocztowy24"}
adyen = { banks = "blik_psp,place_zipko,m_bank,pay_with_ing,santander_przelew24,bank_pekaosa,bank_millennium,pay_with_alior_bank,banki_spoldzielcze,pay_with_inteligo,bnp_paribas_poland,bank_nowy_sa,credit_agricole,pay_with_bos,pay_with_citi_handlowy,pay_with_plus_bank,toyota_bank,velo_bank,e_transfer_pocztowy24" }
# Bank redirect configs for allowed banks through open_banking_uk payment method
[bank_config.open_banking_uk]
adyen = { banks = "aib,bank_of_scotland,danske_bank,first_direct,first_trust,halifax,lloyds,monzo,nat_west,nationwide_bank,royal_bank_of_scotland,starling,tsb_bank,tesco_bank,ulster_bank,barclays,hsbc_bank,revolut,santander_przelew24,open_bank_success,open_bank_failure,open_bank_cancelled"}
adyen = { banks = "aib,bank_of_scotland,danske_bank,first_direct,first_trust,halifax,lloyds,monzo,nat_west,nationwide_bank,royal_bank_of_scotland,starling,tsb_bank,tesco_bank,ulster_bank,barclays,hsbc_bank,revolut,santander_przelew24,open_bank_success,open_bank_failure,open_bank_cancelled" }
# Bank redirect configs for allowed banks through przelewy24 payment method
[bank_config.przelewy24]
@ -320,17 +320,17 @@ base_url = "" # Base url used when adding links that should redirect to self
[tokenization]
stripe = { long_lived_token = false, payment_method = "wallet", payment_method_type = { type = "disable_only", list = "google_pay" } }
checkout = { long_lived_token = false, payment_method = "wallet" }
mollie = {long_lived_token = false, payment_method = "card"}
mollie = { long_lived_token = false, payment_method = "card" }
stax = { long_lived_token = true, payment_method = "card,bank_debit" }
square = {long_lived_token = false, payment_method = "card"}
square = { long_lived_token = false, payment_method = "card" }
braintree = { long_lived_token = false, payment_method = "card" }
gocardless = {long_lived_token = true, payment_method = "bank_debit"}
gocardless = { long_lived_token = true, payment_method = "bank_debit" }
[temp_locker_enable_config]
stripe = {payment_method = "bank_transfer"}
nuvei = {payment_method = "card"}
shift4 = {payment_method = "card"}
bluesnap = {payment_method = "card"}
stripe = { payment_method = "bank_transfer" }
nuvei = { payment_method = "card" }
shift4 = { payment_method = "card" }
bluesnap = { payment_method = "card" }
[dummy_connector]
enabled = true # Whether dummy connector is enabled or not
@ -353,49 +353,52 @@ slack_invite_url = "https://www.example.com/" # Slack invite url for hyperswit
discord_invite_url = "https://www.example.com/" # Discord invite url for hyperswitch
[mandates.supported_payment_methods]
card.credit = {connector_list = "stripe,adyen"} # Mandate supported payment method type and connector for card
wallet.paypal = {connector_list = "adyen"} # Mandate supported payment method type and connector for wallets
pay_later.klarna = {connector_list = "adyen"} # Mandate supported payment method type and connector for pay_later
bank_debit.ach = { connector_list = "gocardless"} # Mandate supported payment method type and connector for bank_debit
bank_debit.becs = { connector_list = "gocardless"} # Mandate supported payment method type and connector for bank_debit
bank_debit.sepa = { connector_list = "gocardless"} # Mandate supported payment method type and connector for bank_debit
card.credit = { connector_list = "stripe,adyen" } # Mandate supported payment method type and connector for card
wallet.paypal = { connector_list = "adyen" } # Mandate supported payment method type and connector for wallets
pay_later.klarna = { connector_list = "adyen" } # Mandate supported payment method type and connector for pay_later
bank_debit.ach = { connector_list = "gocardless" } # Mandate supported payment method type and connector for bank_debit
bank_debit.becs = { connector_list = "gocardless" } # Mandate supported payment method type and connector for bank_debit
bank_debit.sepa = { connector_list = "gocardless" } # Mandate supported payment method type and connector for bank_debit
# Required fields info used while listing the payment_method_data
[required_fields.pay_later] # payment_method = "pay_later"
afterpay_clearpay = {fields = {stripe = [ # payment_method_type = afterpay_clearpay, connector = "stripe"
afterpay_clearpay = { fields = { stripe = [ # payment_method_type = afterpay_clearpay, connector = "stripe"
# Required fields vector with its respective display name in front-end and field_type
{ required_field = "shipping.address.first_name", display_name = "first_name", field_type = "text" },
{ required_field = "shipping.address.last_name", display_name = "last_name", field_type = "text" },
{ required_field = "shipping.address.country", display_name = "country", field_type = { drop_down = { options = [ "US", "IN" ] } } },
] } }
{ required_field = "shipping.address.country", display_name = "country", field_type = { drop_down = { options = [
"US",
"IN",
] } } },
] } }
[payouts]
payout_eligibility = true # Defaults the eligibility of a payout method to true in case connector does not provide checks for payout eligibility
[pm_filters.adyen]
online_banking_fpx = {country = "MY", currency = "MYR"}
online_banking_thailand = {country = "TH", currency = "THB"}
touch_n_go = {country = "MY", currency = "MYR"}
atome = {country = "MY,SG", currency = "MYR,SGD"}
swish = {country = "SE", currency = "SEK"}
permata_bank_transfer = {country = "ID", currency = "IDR"}
bca_bank_transfer = {country = "ID", currency = "IDR"}
bni_va = {country = "ID", currency = "IDR"}
bri_va = {country = "ID", currency = "IDR"}
cimb_va = {country = "ID", currency = "IDR"}
danamon_va = {country = "ID", currency = "IDR"}
mandiri_va = {country = "ID", currency = "IDR"}
alfamart = {country = "ID", currency = "IDR"}
indomaret = {country = "ID", currency = "IDR"}
open_banking_uk = {country = "GB", currency = "GBP"}
oxxo = {country = "MX", currency = "MXN"}
pay_safe_card = {country = "AT,AU,BE,BR,BE,CA,HR,CY,CZ,DK,FI,FR,GE,DE,GI,HU,IS,IE,KW,LV,IE,LI,LT,LU,MT,MX,MD,ME,NL,NZ,NO,PY,PE,PL,PT,RO,SA,RS,SK,SI,ES,SE,CH,TR,UAE,UK,US,UY", currency = "EUR,AUD,BRL,CAD,CZK,DKK,GEL,GIP,HUF,ISK,KWD,CHF,MXN,MDL,NZD,NOK,PYG,PEN,PLN,RON,SAR,RSD,SEK,TRY,AED,GBP,USD,UYU"}
seven_eleven = {country = "JP", currency = "JPY"}
lawson = {country = "JP", currency = "JPY"}
mini_stop = {country = "JP", currency = "JPY"}
family_mart = {country = "JP", currency = "JPY"}
seicomart = {country = "JP", currency = "JPY"}
pay_easy = {country = "JP", currency = "JPY"}
online_banking_fpx = { country = "MY", currency = "MYR" }
online_banking_thailand = { country = "TH", currency = "THB" }
touch_n_go = { country = "MY", currency = "MYR" }
atome = { country = "MY,SG", currency = "MYR,SGD" }
swish = { country = "SE", currency = "SEK" }
permata_bank_transfer = { country = "ID", currency = "IDR" }
bca_bank_transfer = { country = "ID", currency = "IDR" }
bni_va = { country = "ID", currency = "IDR" }
bri_va = { country = "ID", currency = "IDR" }
cimb_va = { country = "ID", currency = "IDR" }
danamon_va = { country = "ID", currency = "IDR" }
mandiri_va = { country = "ID", currency = "IDR" }
alfamart = { country = "ID", currency = "IDR" }
indomaret = { country = "ID", currency = "IDR" }
open_banking_uk = { country = "GB", currency = "GBP" }
oxxo = { country = "MX", currency = "MXN" }
pay_safe_card = { country = "AT,AU,BE,BR,BE,CA,HR,CY,CZ,DK,FI,FR,GE,DE,GI,HU,IS,IE,KW,LV,IE,LI,LT,LU,MT,MX,MD,ME,NL,NZ,NO,PY,PE,PL,PT,RO,SA,RS,SK,SI,ES,SE,CH,TR,UAE,UK,US,UY", currency = "EUR,AUD,BRL,CAD,CZK,DKK,GEL,GIP,HUF,ISK,KWD,CHF,MXN,MDL,NZD,NOK,PYG,PEN,PLN,RON,SAR,RSD,SEK,TRY,AED,GBP,USD,UYU" }
seven_eleven = { country = "JP", currency = "JPY" }
lawson = { country = "JP", currency = "JPY" }
mini_stop = { country = "JP", currency = "JPY" }
family_mart = { country = "JP", currency = "JPY" }
seicomart = { country = "JP", currency = "JPY" }
pay_easy = { country = "JP", currency = "JPY" }
[pm_filters.zen]
credit = { not_available_flows = { capture_method = "manual" } }
@ -415,7 +418,7 @@ debit = { currency = "USD" }
ach = { currency = "USD" }
[pm_filters.stripe]
cashapp = {country = "US", currency = "USD"}
cashapp = { country = "US", currency = "USD" }
[pm_filters.prophetpay]
card_redirect = { currency = "USD" }

View File

@ -106,7 +106,7 @@ pub async fn call_to_locker(
let (_add_card_rs_resp, _is_duplicate) = cards::add_card_hs(
state,
pm_create,
card_details,
&card_details,
customer_id.to_string(),
merchant_account,
api_enums::LockerChoice::Tartarus,

View File

@ -103,16 +103,12 @@ pub async fn add_payment_method(
let merchant_id = &merchant_account.merchant_id;
let customer_id = req.customer_id.clone().get_required_value("customer_id")?;
let response = match req.card.clone() {
Some(card) => add_card_to_locker(
&state,
req.clone(),
card,
customer_id.clone(),
merchant_account,
)
Some(card) => {
add_card_to_locker(&state, req.clone(), &card, &customer_id, merchant_account)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Add Card Failed"),
.attach_printable("Add Card Failed")
}
None => {
let pm_id = generate_id(consts::ID_LENGTH, "pm");
let payment_method_response = api::PaymentMethodResponse {
@ -207,18 +203,18 @@ pub async fn update_customer_payment_method(
pub async fn add_card_to_locker(
state: &routes::AppState,
req: api::PaymentMethodCreate,
card: api::CardDetail,
customer_id: String,
card: &api::CardDetail,
customer_id: &String,
merchant_account: &domain::MerchantAccount,
) -> errors::CustomResult<(api::PaymentMethodResponse, bool), errors::VaultError> {
metrics::STORED_TO_LOCKER.add(&metrics::CONTEXT, 1, &[]);
request::record_operation_time(
let add_card_to_hs_resp = request::record_operation_time(
async {
add_card_hs(
state,
req,
req.clone(),
card,
customer_id,
customer_id.to_string(),
merchant_account,
api_enums::LockerChoice::Basilisk,
None,
@ -232,7 +228,34 @@ pub async fn add_card_to_locker(
&metrics::CARD_ADD_TIME,
&[],
)
.await?;
logger::debug!("card added to basilisk locker");
let add_card_to_rs_resp = request::record_operation_time(
async {
add_card_hs(
state,
req,
card,
customer_id.to_string(),
merchant_account,
api_enums::LockerChoice::Tartarus,
Some(&add_card_to_hs_resp.0.payment_method_id),
)
.await
.map_err(|error| {
metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);
error
})
},
&metrics::CARD_ADD_TIME,
&[],
)
.await?;
logger::debug!("card added to rust locker");
Ok(add_card_to_rs_resp)
}
pub async fn get_card_from_locker(
@ -243,9 +266,38 @@ pub async fn get_card_from_locker(
) -> errors::RouterResult<payment_methods::Card> {
metrics::GET_FROM_LOCKER.add(&metrics::CONTEXT, 1, &[]);
request::record_operation_time(
let get_card_from_rs_locker_resp = request::record_operation_time(
async {
get_card_from_hs_locker(state, customer_id, merchant_id, card_reference)
get_card_from_hs_locker(
state,
customer_id,
merchant_id,
card_reference,
api_enums::LockerChoice::Tartarus,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while getting card from basilisk_hs")
.map_err(|error| {
metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);
error
})
},
&metrics::CARD_GET_TIME,
&[],
)
.await;
match get_card_from_rs_locker_resp {
Err(_) => request::record_operation_time(
async {
get_card_from_hs_locker(
state,
customer_id,
merchant_id,
card_reference,
api_enums::LockerChoice::Basilisk,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while getting card from basilisk_hs")
@ -258,6 +310,15 @@ pub async fn get_card_from_locker(
&[],
)
.await
.map(|inner_card| {
logger::debug!("card retrieved from basilisk locker");
inner_card
}),
Ok(_) => {
logger::debug!("card retrieved from rust locker");
get_card_from_rs_locker_resp
}
}
}
pub async fn delete_card_from_locker(
@ -287,7 +348,7 @@ pub async fn delete_card_from_locker(
pub async fn add_card_hs(
state: &routes::AppState,
req: api::PaymentMethodCreate,
card: api::CardDetail,
card: &api::CardDetail,
customer_id: String,
merchant_account: &domain::MerchantAccount,
locker_choice: api_enums::LockerChoice,
@ -296,7 +357,7 @@ pub async fn add_card_hs(
let payload = payment_methods::StoreLockerReq::LockerCard(payment_methods::StoreCardReq {
merchant_id: &merchant_account.merchant_id,
merchant_customer_id: customer_id.to_owned(),
card_reference: card_reference.map(str::to_string),
requestor_card_reference: card_reference.map(str::to_string),
card: payment_methods::Card {
card_number: card.card_number.to_owned(),
name_on_card: card.card_holder_name.to_owned(),
@ -307,11 +368,12 @@ pub async fn add_card_hs(
nick_name: card.nick_name.as_ref().map(masking::Secret::peek).cloned(),
},
});
let store_card_payload =
call_to_locker_hs(state, &payload, &customer_id, locker_choice).await?;
let payment_method_resp = payment_methods::mk_add_card_response_hs(
card,
card.clone(),
store_card_payload.card_reference,
req,
&merchant_account.merchant_id,
@ -351,6 +413,7 @@ pub async fn get_payment_method_from_hs_locker<'a>(
customer_id: &str,
merchant_id: &str,
payment_method_reference: &'a str,
locker_choice: Option<api_enums::LockerChoice>,
) -> errors::CustomResult<Secret<String>, errors::VaultError> {
let locker = &state.conf.locker;
#[cfg(not(feature = "kms"))]
@ -365,6 +428,7 @@ pub async fn get_payment_method_from_hs_locker<'a>(
customer_id,
merchant_id,
payment_method_reference,
locker_choice,
)
.await
.change_context(errors::VaultError::FetchPaymentMethodFailed)
@ -466,6 +530,7 @@ pub async fn get_card_from_hs_locker<'a>(
customer_id: &str,
merchant_id: &str,
card_reference: &'a str,
locker_choice: api_enums::LockerChoice,
) -> errors::CustomResult<payment_methods::Card, errors::VaultError> {
let locker = &state.conf.locker;
#[cfg(not(feature = "kms"))]
@ -480,6 +545,7 @@ pub async fn get_card_from_hs_locker<'a>(
customer_id,
merchant_id,
card_reference,
Some(locker_choice),
)
.await
.change_context(errors::VaultError::FetchCardFailed)
@ -2193,6 +2259,7 @@ pub async fn get_lookup_key_for_payout_method(
&pm.customer_id,
&pm.merchant_id,
&pm.payment_method_id,
None,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)

View File

@ -28,7 +28,7 @@ pub struct StoreCardReq<'a> {
pub merchant_id: &'a str,
pub merchant_customer_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub card_reference: Option<String>,
pub requestor_card_reference: Option<String>,
pub card: Card,
}
@ -428,6 +428,7 @@ pub async fn mk_get_card_request_hs(
customer_id: &str,
merchant_id: &str,
card_reference: &str,
locker_choice: Option<api_enums::LockerChoice>,
) -> CustomResult<services::Request, errors::VaultError> {
let merchant_customer_id = customer_id.to_owned();
let card_req_body = CardReqBody {
@ -448,11 +449,16 @@ pub async fn mk_get_card_request_hs(
.await
.change_context(errors::VaultError::RequestEncodingFailed)?;
let jwe_payload = mk_basilisk_req(jwekey, &jws, api_enums::LockerChoice::Basilisk).await?;
let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::Basilisk);
let jwe_payload = mk_basilisk_req(jwekey, &jws, target_locker).await?;
let body = utils::Encode::<encryption::JweBody>::encode_to_value(&jwe_payload)
.change_context(errors::VaultError::RequestEncodingFailed)?;
let mut url = locker.host.to_owned();
let mut url = match target_locker {
api_enums::LockerChoice::Basilisk => locker.host.to_owned(),
api_enums::LockerChoice::Tartarus => locker.host_rs.to_owned(),
};
url.push_str("/cards/retrieve");
let mut request = services::Request::new(services::Method::Post, &url);
request.add_header(headers::CONTENT_TYPE, "application/json".into());

View File

@ -183,8 +183,8 @@ pub async fn save_in_locker(
Some(card) => payment_methods::cards::add_card_to_locker(
state,
payment_method_request,
card,
customer_id,
&card,
&customer_id,
merchant_account,
)
.await

View File

@ -152,7 +152,7 @@ pub async fn save_payout_data_to_locker(
card_isin: None,
nick_name: None,
},
card_reference: None,
requestor_card_reference: None,
});
(
payload,