mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
feat(admin): add payment_connector_list API (#160)
This commit is contained in:
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -1825,6 +1825,16 @@ dependencies = [
|
|||||||
"pkg-config",
|
"pkg-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libmimalloc-sys"
|
||||||
|
version = "0.1.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04d1c67deb83e6b75fa4fe3309e09cfeade12e7721d95322af500d3814ea60c9"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libz-sys"
|
name = "libz-sys"
|
||||||
version = "1.1.8"
|
version = "1.1.8"
|
||||||
@ -1943,6 +1953,15 @@ version = "2.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mimalloc"
|
||||||
|
version = "0.1.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b2374e2999959a7b583e1811a1ddbf1d3a4b9496eceb9746f1192a59d871eca"
|
||||||
|
dependencies = [
|
||||||
|
"libmimalloc-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
version = "0.3.16"
|
version = "0.3.16"
|
||||||
@ -2712,6 +2731,7 @@ dependencies = [
|
|||||||
"literally",
|
"literally",
|
||||||
"masking",
|
"masking",
|
||||||
"maud",
|
"maud",
|
||||||
|
"mimalloc",
|
||||||
"mime",
|
"mime",
|
||||||
"nanoid",
|
"nanoid",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use crate::{
|
|||||||
types::{
|
types::{
|
||||||
self, api,
|
self, api,
|
||||||
storage::{self, MerchantAccount},
|
storage::{self, MerchantAccount},
|
||||||
transformers::ForeignInto,
|
transformers::{ForeignInto, ForeignTryInto},
|
||||||
},
|
},
|
||||||
utils::{self, OptionExt, ValueExt},
|
utils::{self, OptionExt, ValueExt},
|
||||||
};
|
};
|
||||||
@ -356,22 +356,35 @@ pub async fn retrieve_payment_connector(
|
|||||||
.map_err(|error| {
|
.map_err(|error| {
|
||||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)
|
error.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)
|
||||||
})?;
|
})?;
|
||||||
let payment_methods_enabled = match mca.payment_methods_enabled {
|
|
||||||
Some(val) => serde_json::Value::Array(val)
|
Ok(service_api::BachResponse::Json(mca.foreign_try_into()?))
|
||||||
.parse_value("PaymentMethods")
|
}
|
||||||
.change_context(errors::ApiErrorResponse::InternalServerError)?,
|
|
||||||
None => None,
|
pub async fn list_payment_connectors(
|
||||||
};
|
store: &dyn StorageInterface,
|
||||||
let response = api::PaymentConnectorCreate {
|
merchant_id: String,
|
||||||
connector_type: mca.connector_type.foreign_into(),
|
) -> RouterResponse<Vec<api::PaymentConnectorCreate>> {
|
||||||
connector_name: mca.connector_name,
|
// Validate merchant account
|
||||||
merchant_connector_id: Some(mca.merchant_connector_id),
|
store
|
||||||
connector_account_details: Some(Secret::new(mca.connector_account_details)),
|
.find_merchant_account_by_merchant_id(&merchant_id)
|
||||||
test_mode: mca.test_mode,
|
.await
|
||||||
disabled: mca.disabled,
|
.map_err(|err| {
|
||||||
payment_methods_enabled,
|
err.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||||
metadata: None,
|
})?;
|
||||||
};
|
|
||||||
|
let merchant_connector_accounts = store
|
||||||
|
.find_merchant_connector_account_by_merchant_id_list(&merchant_id)
|
||||||
|
.await
|
||||||
|
.map_err(|error| {
|
||||||
|
error.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)
|
||||||
|
})?;
|
||||||
|
let mut response = vec![];
|
||||||
|
|
||||||
|
// The can be eliminated once [#79711](https://github.com/rust-lang/rust/issues/79711) is stabilized
|
||||||
|
for mca in merchant_connector_accounts.into_iter() {
|
||||||
|
response.push(mca.foreign_try_into()?);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(service_api::BachResponse::Json(response))
|
Ok(service_api::BachResponse::Json(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -130,6 +130,24 @@ pub async fn payment_connector_retrieve(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip_all, fields(flow = ?Flow::PaymentConnectorsList))]
|
||||||
|
|
||||||
|
pub async fn payment_connector_list(
|
||||||
|
state: web::Data<AppState>,
|
||||||
|
req: HttpRequest,
|
||||||
|
path: web::Path<String>,
|
||||||
|
) -> HttpResponse {
|
||||||
|
let merchant_id = path.into_inner();
|
||||||
|
api::server_wrap(
|
||||||
|
&state,
|
||||||
|
&req,
|
||||||
|
merchant_id,
|
||||||
|
|state, _, merchant_id| list_payment_connectors(&*state.store, merchant_id),
|
||||||
|
api::MerchantAuthentication::AdminApiKey,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument(skip_all, fields(flow = ?Flow::PaymentConnectorsUpdate))]
|
#[instrument(skip_all, fields(flow = ?Flow::PaymentConnectorsUpdate))]
|
||||||
// #[post("/{merchant_id}/connectors/{merchant_connector_id}")]
|
// #[post("/{merchant_id}/connectors/{merchant_connector_id}")]
|
||||||
pub async fn payment_connector_update(
|
pub async fn payment_connector_update(
|
||||||
|
|||||||
@ -177,7 +177,8 @@ impl MerchantConnectorAccount {
|
|||||||
.app_data(web::Data::new(config))
|
.app_data(web::Data::new(config))
|
||||||
.service(
|
.service(
|
||||||
web::resource("/{merchant_id}/connectors")
|
web::resource("/{merchant_id}/connectors")
|
||||||
.route(web::post().to(payment_connector_create)),
|
.route(web::post().to(payment_connector_create))
|
||||||
|
.route(web::get().to(payment_connector_list)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/{merchant_id}/payment_methods")
|
web::resource("/{merchant_id}/payment_methods")
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use api_models::enums as api_enums;
|
use api_models::enums as api_enums;
|
||||||
|
use common_utils::ext_traits::ValueExt;
|
||||||
|
use error_stack::ResultExt;
|
||||||
use storage_models::enums as storage_enums;
|
use storage_models::enums as storage_enums;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -321,3 +323,33 @@ impl<'a> From<F<&'a storage::Address>> for F<api_types::Address> {
|
|||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<F<storage::MerchantConnectorAccount>>
|
||||||
|
for F<api_models::admin::PaymentConnectorCreate>
|
||||||
|
{
|
||||||
|
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||||
|
fn try_from(item: F<storage::MerchantConnectorAccount>) -> Result<Self, Self::Error> {
|
||||||
|
let merchant_ca = item.0;
|
||||||
|
|
||||||
|
let payment_methods_enabled = match merchant_ca.payment_methods_enabled {
|
||||||
|
Some(val) => serde_json::Value::Array(val)
|
||||||
|
.parse_value("PaymentMethods")
|
||||||
|
.change_context(errors::ApiErrorResponse::InternalServerError)?,
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(api_models::admin::PaymentConnectorCreate {
|
||||||
|
connector_type: merchant_ca.connector_type.foreign_into(),
|
||||||
|
connector_name: merchant_ca.connector_name,
|
||||||
|
merchant_connector_id: Some(merchant_ca.merchant_connector_id),
|
||||||
|
connector_account_details: Some(masking::Secret::new(
|
||||||
|
merchant_ca.connector_account_details,
|
||||||
|
)),
|
||||||
|
test_mode: merchant_ca.test_mode,
|
||||||
|
disabled: merchant_ca.disabled,
|
||||||
|
metadata: None,
|
||||||
|
payment_methods_enabled,
|
||||||
|
}
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -70,6 +70,8 @@ pub enum Flow {
|
|||||||
PaymentConnectorsUpdate,
|
PaymentConnectorsUpdate,
|
||||||
/// Payment connectors delete flow.
|
/// Payment connectors delete flow.
|
||||||
PaymentConnectorsDelete,
|
PaymentConnectorsDelete,
|
||||||
|
/// Payment connectors list flow.
|
||||||
|
PaymentConnectorsList,
|
||||||
/// Customers create flow.
|
/// Customers create flow.
|
||||||
CustomersCreate,
|
CustomersCreate,
|
||||||
/// Customers retrieve flow.
|
/// Customers retrieve flow.
|
||||||
|
|||||||
Reference in New Issue
Block a user