-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(router): Override the setup_future_usage
to on_session
based on the merchant config
#5016
Changes from all commits
1bd0d87
6efdf99
049ba05
99beebd
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 |
---|---|---|
|
@@ -515,35 +515,79 @@ where | |
} | ||
}, | ||
None => { | ||
let pm_metadata = create_payment_method_metadata(None, connector_token)?; | ||
|
||
locker_id = resp.payment_method.and_then(|pm| { | ||
if pm == PaymentMethod::Card { | ||
Some(resp.payment_method_id) | ||
} else { | ||
None | ||
let customer_apple_pay_saved_pm_id_option = if payment_method_type | ||
== Some(api_models::enums::PaymentMethodType::ApplePay) | ||
{ | ||
match state | ||
.store | ||
.find_payment_method_by_customer_id_merchant_id_list( | ||
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. pass the PM type directly in the query and return top 1. return Option to avoid iterating the list. 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 do not have db interface that accepts payment method type and list the payment method of the passed payment method type for given customer. |
||
&customer_id, | ||
merchant_id, | ||
None, | ||
) | ||
.await | ||
{ | ||
Ok(customer_payment_methods) => Ok(customer_payment_methods | ||
.iter() | ||
.find(|payment_method| { | ||
payment_method.payment_method_type | ||
== Some(api_models::enums::PaymentMethodType::ApplePay) | ||
}) | ||
.map(|pm| pm.payment_method_id.clone())), | ||
Err(error) => { | ||
if error.current_context().is_db_not_found() { | ||
Ok(None) | ||
} else { | ||
Err(error) | ||
.change_context( | ||
errors::ApiErrorResponse::InternalServerError, | ||
) | ||
.attach_printable( | ||
"failed to find payment methods for a customer", | ||
) | ||
} | ||
} | ||
} | ||
}); | ||
|
||
resp.payment_method_id = generate_id(consts::ID_LENGTH, "pm"); | ||
payment_methods::cards::create_payment_method( | ||
db, | ||
&payment_method_create_request, | ||
&customer_id, | ||
&resp.payment_method_id, | ||
locker_id, | ||
merchant_id, | ||
pm_metadata, | ||
customer_acceptance, | ||
pm_data_encrypted, | ||
key_store, | ||
connector_mandate_details, | ||
None, | ||
network_transaction_id, | ||
merchant_account.storage_scheme, | ||
encrypted_payment_method_billing_address, | ||
) | ||
.await?; | ||
} else { | ||
Ok(None) | ||
}?; | ||
|
||
if let Some(customer_apple_pay_saved_pm_id) = | ||
customer_apple_pay_saved_pm_id_option | ||
{ | ||
resp.payment_method_id = customer_apple_pay_saved_pm_id; | ||
} else { | ||
let pm_metadata = | ||
create_payment_method_metadata(None, connector_token)?; | ||
|
||
locker_id = resp.payment_method.and_then(|pm| { | ||
if pm == PaymentMethod::Card { | ||
Some(resp.payment_method_id) | ||
} else { | ||
None | ||
} | ||
}); | ||
|
||
resp.payment_method_id = generate_id(consts::ID_LENGTH, "pm"); | ||
payment_methods::cards::create_payment_method( | ||
db, | ||
&payment_method_create_request, | ||
&customer_id, | ||
&resp.payment_method_id, | ||
locker_id, | ||
merchant_id, | ||
pm_metadata, | ||
customer_acceptance, | ||
pm_data_encrypted, | ||
key_store, | ||
connector_mandate_details, | ||
None, | ||
network_transaction_id, | ||
merchant_account.storage_scheme, | ||
encrypted_payment_method_billing_address, | ||
) | ||
.await?; | ||
}; | ||
} | ||
} | ||
|
||
|
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.
since we are updating the
setup_future_usage
based on config, it will be better if we log to know why it is updated to avoid confusion