feat(payment_methods): Client secret implementation in payment method… (#4134)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sarthak Soni
2024-04-19 17:32:06 +05:30
committed by GitHub
parent f6fccafb3d
commit 43307815e0
27 changed files with 548 additions and 60 deletions

View File

@ -23,13 +23,14 @@ pub async fn create_payment_method_api(
json_payload: web::Json<payment_methods::PaymentMethodCreate>,
) -> HttpResponse {
let flow = Flow::PaymentMethodsCreate;
Box::pin(api::server_wrap(
flow,
state,
&req,
json_payload.into_inner(),
|state, auth, req, _| async move {
Box::pin(cards::add_payment_method(
Box::pin(cards::get_client_secret_or_add_payment_method(
state,
req,
&auth.merchant_account,
@ -43,6 +44,41 @@ pub async fn create_payment_method_api(
.await
}
#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodSave))]
pub async fn save_payment_method_api(
state: web::Data<AppState>,
req: HttpRequest,
json_payload: web::Json<payment_methods::PaymentMethodCreate>,
path: web::Path<String>,
) -> HttpResponse {
let flow = Flow::PaymentMethodSave;
let payload = json_payload.into_inner();
let pm_id = path.into_inner();
let (auth, _) = match auth::check_client_secret_and_get_auth(req.headers(), &payload) {
Ok((auth, _auth_flow)) => (auth, _auth_flow),
Err(e) => return api::log_and_return_error_response(e),
};
Box::pin(api::server_wrap(
flow,
state,
&req,
payload,
|state, auth, req, _| {
Box::pin(cards::add_payment_method_data(
state,
req,
auth.merchant_account,
auth.key_store,
pm_id.clone(),
))
},
&*auth,
api_locking::LockAction::NotApplicable,
))
.await
}
#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsList))]
pub async fn list_payment_method_api(
state: web::Data<AppState>,