Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(customers): provision reference ID based customer retrieval (#12947)
Kashif90ab4babb94c
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex deaa302f46..4d13b62983 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -1835,6 +1835,57 @@]}},+ "/v1/customers/reference/{merchant_reference_id}": {+ "get": {+ "tags": [+ "Customers"+ ],+ "summary": "Customers - Retrieve using Merchant Reference ID",+ "description": "Retrieves a customer's details using the merchant supplied reference ID.",+ "operationId": "Retrieve a Customer using Merchant Reference ID",+ "parameters": [+ {+ "name": "merchant_reference_id",+ "in": "path",+ "description": "The merchant supplied reference identifier for the Customer",+ "required": true,+ "schema": {+ "type": "string"+ }+ },+ {+ "name": "X-Profile-Id",+ "in": "header",+ "description": "Profile ID associated to the customer",+ "required": true,+ "schema": {+ "type": "string"+ },+ "example": "pro_abcdefghijklmnop"+ }+ ],+ "responses": {+ "200": {+ "description": "Customer Retrieved",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/CustomerResponse"+ }+ }+ }+ },+ "404": {+ "description": "Customer was not found"+ }+ },+ "security": [+ {+ "api_key": []+ }+ ]+ }+ },"/v1/customers/{id}": {"get": {"tags": [diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex d5e58e2e66..5933e6b7c3 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -117,6 +117,7 @@ Never share your secret api keys. Keep them guarded and secure.routes::customers::customers_create,routes::customers::customers_create_v1,routes::customers::customers_retrieve,+ routes::customers::customers_retrieve_by_merchant_reference_id,routes::customers::customers_retrieve_v1,routes::customers::customers_update,routes::customers::customers_update_v1,diff --git a/crates/openapi/src/routes/customers.rs b/crates/openapi/src/routes/customers.rsindex 224b0b7b6f..9f1e960131 100644--- a/crates/openapi/src/routes/customers.rs+++ b/crates/openapi/src/routes/customers.rs@@ -202,6 +202,35 @@ pub async fn customers_create_v1() {}#[cfg(feature = "v2")]pub async fn customers_retrieve() {}+/// Customers - Retrieve using Merchant Reference ID+///+/// Retrieves a customer's details using the merchant supplied reference ID.+#[utoipa::path(+ get,+ path = "/v1/customers/reference/{merchant_reference_id}",+ params (+ (+ "merchant_reference_id" = String,+ Path,+ description = "The merchant supplied reference identifier for the Customer"+ ),+ (+ "X-Profile-Id" = String, Header,+ description = "Profile ID associated to the customer",+ example = "pro_abcdefghijklmnop"+ )+ ),+ responses(+ (status = 200, description = "Customer Retrieved", body = CustomerResponse),+ (status = 404, description = "Customer was not found")+ ),+ tag = "Customers",+ operation_id = "Retrieve a Customer using Merchant Reference ID",+ security(("api_key" = []))+)]+#[cfg(feature = "v2")]+pub async fn customers_retrieve_by_merchant_reference_id() {}+/// Customers - Retrieve////// Retrieves a customer's details.diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rsindex cc332a2c8d..e889dfc5f1 100644--- a/crates/router/src/core/customers.rs+++ b/crates/router/src/core/customers.rs@@ -635,6 +635,32 @@ pub async fn retrieve_customer())}+#[cfg(feature = "v2")]+#[instrument(skip(state))]+pub async fn retrieve_customer_by_merchant_reference_id(+ state: SessionState,+ provider: domain::Provider,+ merchant_reference_id: id_type::CustomerId,+) -> errors::CustomerResponse<customers::CustomerResponse> {+ let db = state.store.as_ref();++ let response = db+ .find_customer_by_merchant_reference_id_merchant_id(+ &merchant_reference_id,+ provider.get_account().get_id(),+ provider.get_key_store(),+ provider.get_account().storage_scheme,+ )+ .await+ .switch()?;++ Ok(services::ApplicationResponse::Json(+ customers::CustomerResponse::try_from(response)+ .change_context(errors::CustomersErrorResponse::InternalServerError)+ .attach_printable("Failed to convert domain customer to CustomerResponse")?,+ ))+}+#[instrument(skip(state))]pub async fn list_customers(state: SessionState,diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex acaacdd666..7d40dbb363 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -1413,22 +1413,26 @@ impl Customers {}#[cfg(all(feature = "oltp", feature = "v2"))]{- route = route- .service(web::resource("").route(web::post().to(customers::customers_create)))- .service(- web::resource("/migrate/global-id")- .route(web::post().to(customers::migrate::migrate_global_id)),- )- .service(- web::resource("/{id}")- .route(web::put().to(customers::customers_update))- .route(web::get().to(customers::customers_retrieve))- .route(web::delete().to(customers::customers_delete)),- )- .service(- web::resource("/{customer_id}/payment-methods/{payment_method_id}/default")- .route(web::post().to(payment_methods::default_payment_method_set_api)),- )+ route =+ route+ .service(web::resource("").route(web::post().to(customers::customers_create)))+ .service(+ web::resource("/migrate/global-id")+ .route(web::post().to(customers::migrate::migrate_global_id)),+ )+ .service(web::resource("/reference/{merchant_reference_id}").route(+ web::get().to(customers::customers_retrieve_by_merchant_reference_id),+ ))+ .service(+ web::resource("/{id}")+ .route(web::put().to(customers::customers_update))+ .route(web::get().to(customers::customers_retrieve))+ .route(web::delete().to(customers::customers_delete)),+ )+ .service(+ web::resource("/{customer_id}/payment-methods/{payment_method_id}/default")+ .route(web::post().to(payment_methods::default_payment_method_set_api)),+ )}route}diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rsindex ac9d2b027e..06ab354dbe 100644--- a/crates/router/src/routes/customers.rs+++ b/crates/router/src/routes/customers.rs@@ -201,6 +201,38 @@ pub async fn customers_retrieve(.await}+#[cfg(feature = "v2")]+#[instrument(skip_all, fields(flow = ?Flow::CustomersRetrieveByReferenceId))]+pub async fn customers_retrieve_by_merchant_reference_id(+ state: web::Data<AppState>,+ req: HttpRequest,+ path: web::Path<id_type::CustomerId>,+) -> HttpResponse {+ let flow = Flow::CustomersRetrieveByReferenceId;+ let merchant_reference_id = path.into_inner();+ let auth = auth::V2ApiKeyAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,+ };++ Box::pin(api::server_wrap(+ flow,+ state,+ &req,+ (),+ move |state, auth: auth::AuthenticationData, _, _| {+ retrieve_customer_by_merchant_reference_id(+ state,+ auth.platform.get_provider().clone(),+ merchant_reference_id.clone(),+ )+ },+ &auth,+ api_locking::LockAction::NotApplicable,+ ))+ .await+}+#[cfg(feature = "v2")]#[instrument(skip_all, fields(flow = ?Flow::CustomersList))]pub async fn customers_list(diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rsindex b2e6dd87ec..3756b61ba5 100644--- a/crates/router/src/routes/lock_utils.rs+++ b/crates/router/src/routes/lock_utils.rs@@ -120,6 +120,7 @@ impl From<Flow> for ApiIdentifier {| Flow::CreateConfigKey => Self::Configs,Flow::CustomersCreate| Flow::CustomersRetrieve+ | Flow::CustomersRetrieveByReferenceId| Flow::CustomersUpdate| Flow::CustomersDelete| Flow::CustomersGetMandatesdiff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rsindex 453d18888b..af61c6dddf 100644--- a/crates/router_env/src/logger/types.rs+++ b/crates/router_env/src/logger/types.rs@@ -112,6 +112,8 @@ pub enum Flow {CustomersCreate,/// Customers retrieve flow.CustomersRetrieve,+ /// Customers retrieve by reference id flow.+ CustomersRetrieveByReferenceId,/// Customers update flow.CustomersUpdate,/// Customers delete flow.diff --git a/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/down.sql b/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/down.sqlnew file mode 100644index 0000000000..d5935e6b72--- /dev/null+++ b/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS customers_merchant_id_merchant_reference_id_index;diff --git a/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/metadata.toml b/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/metadata.tomlnew file mode 100644index 0000000000..16153bc09f--- /dev/null+++ b/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/metadata.toml@@ -0,0 +1 @@+run_in_transaction = false\ No newline at end of filediff --git a/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/up.sql b/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/up.sqlnew file mode 100644index 0000000000..475bc6e5b7--- /dev/null+++ b/v2_compatible_migrations/2026-06-24-000001_add_customers_merchant_reference_id_index/up.sql@@ -0,0 +1,3 @@+CREATE INDEX CONCURRENTLY IF NOT EXISTS customers_merchant_id_merchant_reference_id_index+ON customers (merchant_id, merchant_reference_id)+WHERE merchant_reference_id IS NOT NULL;