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(platform): enable payment_link for platform and add processor_merchant_id, created_by columns to payment_link (#11858)
Ankit Kumar Guptacfe30d48837f
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex fc78e13920..d0e6ae9f78 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -38889,6 +38889,11 @@"type": "string","description": "Identifier for Merchant"},+ "processor_merchant_id": {+ "type": "string",+ "description": "Identifier for the processor merchant",+ "nullable": true+ },"link_to_pay": {"type": "string","description": "Open payment link (without any security checks and listing SPMs)"diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 22fb385ce8..a8efd520a3 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -28676,6 +28676,11 @@"type": "string","description": "Identifier for Merchant"},+ "processor_merchant_id": {+ "type": "string",+ "description": "Identifier for the processor merchant",+ "nullable": true+ },"link_to_pay": {"type": "string","description": "Open payment link (without any security checks and listing SPMs)"diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex e48f72d3a0..854b827296 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -12177,6 +12177,9 @@ pub struct RetrievePaymentLinkResponse {/// Identifier for Merchant#[schema(value_type = String)]pub merchant_id: id_type::MerchantId,+ /// Identifier for the processor merchant+ #[schema(value_type = Option<String>)]+ pub processor_merchant_id: Option<id_type::MerchantId>,/// Open payment link (without any security checks and listing SPMs)pub link_to_pay: String,/// The payment amount. Amount for the payment in the lowest denomination of the currencydiff --git a/crates/diesel_models/src/payment_link.rs b/crates/diesel_models/src/payment_link.rsindex e9d7a17579..d7a23015b5 100644--- a/crates/diesel_models/src/payment_link.rs+++ b/crates/diesel_models/src/payment_link.rs@@ -25,6 +25,8 @@ pub struct PaymentLink {pub description: Option<String>,pub profile_id: Option<common_utils::id_type::ProfileId>,pub secure_link: Option<String>,+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,+ pub created_by: Option<String>,}#[derive(@@ -56,4 +58,6 @@ pub struct PaymentLinkNew {pub description: Option<String>,pub profile_id: Option<common_utils::id_type::ProfileId>,pub secure_link: Option<String>,+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,+ pub created_by: Option<String>,}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 1fa7a07951..dc2c30fe5c 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -1322,6 +1322,10 @@ diesel::table! {profile_id -> Nullable<Varchar>,#[max_length = 255]secure_link -> Nullable<Varchar>,+ #[max_length = 64]+ processor_merchant_id -> Nullable<Varchar>,+ #[max_length = 255]+ created_by -> Nullable<Varchar>,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 0d3b7f9e23..57447d249e 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -1283,6 +1283,10 @@ diesel::table! {profile_id -> Nullable<Varchar>,#[max_length = 255]secure_link -> Nullable<Varchar>,+ #[max_length = 64]+ processor_merchant_id -> Nullable<Varchar>,+ #[max_length = 255]+ created_by -> Nullable<Varchar>,}}diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rsindex 2336ea78e8..0c677058de 100644--- a/crates/router/src/core/payment_link.rs+++ b/crates/router/src/core/payment_link.rs@@ -66,7 +66,7 @@ pub async fn retrieve_payment_link(#[cfg(feature = "v2")]pub async fn form_payment_link_data(state: &SessionState,- platform: domain::Platform,+ processor: domain::Processor,merchant_id: common_utils::id_type::MerchantId,payment_id: common_utils::id_type::PaymentId,) -> RouterResult<(PaymentLink, PaymentLinkData, PaymentLinkConfig)> {@@ -76,7 +76,7 @@ pub async fn form_payment_link_data(#[cfg(feature = "v1")]pub async fn form_payment_link_data(state: &SessionState,- platform: domain::Platform,+ processor: domain::Processor,processor_merchant_id: common_utils::id_type::MerchantId,payment_id: common_utils::id_type::PaymentId,) -> RouterResult<(PaymentLink, PaymentLinkData, PaymentLinkConfig)> {@@ -86,8 +86,8 @@ pub async fn form_payment_link_data(.find_payment_intent_by_payment_id_processor_merchant_id(&payment_id,&processor_merchant_id,- platform.get_processor().get_key_store(),- platform.get_processor().get_account().storage_scheme,+ processor.get_key_store(),+ processor.get_account().storage_scheme,).await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;@@ -97,8 +97,7 @@ pub async fn form_payment_link_data(.get_required_value("payment_link_id").change_context(errors::ApiErrorResponse::PaymentLinkNotFound)?;- let merchant_name_from_merchant_account = platform- .get_processor()+ let merchant_name_from_merchant_account = processor.get_account().merchant_name.clone()@@ -154,7 +153,7 @@ pub async fn form_payment_link_data(.attach_printable("Profile id missing in payment link and payment intent")?;let business_profile = db- .find_business_profile_by_profile_id(platform.get_processor().get_key_store(), &profile_id)+ .find_business_profile_by_profile_id(processor.get_key_store(), &profile_id).await.to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {id: profile_id.get_string_repr().to_owned(),@@ -215,8 +214,8 @@ pub async fn form_payment_link_data(&payment_intent.payment_id,&processor_merchant_id,&attempt_id.clone(),- platform.get_processor().get_account().storage_scheme,- platform.get_processor().get_key_store(),+ processor.get_account().storage_scheme,+ processor.get_key_store(),).await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;@@ -249,8 +248,8 @@ pub async fn form_payment_link_data(&payment_intent.payment_id,&processor_merchant_id,&attempt_id.clone(),- platform.get_processor().get_account().storage_scheme,- platform.get_processor().get_key_store(),+ processor.get_account().storage_scheme,+ processor.get_key_store(),).await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;@@ -290,11 +289,7 @@ pub async fn form_payment_link_data(order_details,return_url,session_expiry,- pub_key: platform- .get_processor()- .get_account()- .publishable_key- .to_owned(),+ pub_key: processor.get_account().publishable_key.to_owned(),client_secret,merchant_logo: payment_link_config.logo.clone(),max_items_visible_after_collapse: 3,@@ -339,13 +334,13 @@ pub async fn form_payment_link_data(pub async fn initiate_secure_payment_link_flow(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,merchant_id: common_utils::id_type::MerchantId,payment_id: common_utils::id_type::PaymentId,request_headers: &header::HeaderMap,) -> RouterResponse<services::PaymentLinkFormData> {let (payment_link, payment_link_details, payment_link_config) =- form_payment_link_data(&state, platform, merchant_id, payment_id).await?;+ form_payment_link_data(&state, processor, merchant_id, payment_id).await?;validator::validate_secure_payment_link_render_request(request_headers,@@ -444,12 +439,12 @@ pub async fn initiate_secure_payment_link_flow(pub async fn initiate_payment_link_flow(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,merchant_id: common_utils::id_type::MerchantId,payment_id: common_utils::id_type::PaymentId,) -> RouterResponse<services::PaymentLinkFormData> {let (_, payment_details, payment_link_config) =- form_payment_link_data(&state, platform, merchant_id, payment_id).await?;+ form_payment_link_data(&state, processor, merchant_id, payment_id).await?;let css_script = get_payment_link_css_script(&payment_link_config)?;let js_script = get_js_script(&payment_details)?;@@ -524,7 +519,7 @@ pub async fn list_payment_link() -> RouterResponse<Vec<api_models::payments::RetrievePaymentLinkResponse>> {let db = state.store.as_ref();let payment_link = db- .list_payment_link_by_merchant_id(merchant.get_id(), constraints)+ .list_payment_link_by_processor_merchant_id(merchant.get_id(), constraints).await.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Unable to retrieve payment link")?;@@ -791,7 +786,7 @@ pub async fn get_payment_link_status(#[cfg(feature = "v1")]pub async fn get_payment_link_status(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,processor_merchant_id: common_utils::id_type::MerchantId,payment_id: common_utils::id_type::PaymentId,) -> RouterResponse<services::PaymentLinkFormData> {@@ -801,8 +796,8 @@ pub async fn get_payment_link_status(.find_payment_intent_by_payment_id_processor_merchant_id(&payment_id,&processor_merchant_id,- platform.get_processor().get_key_store(),- platform.get_processor().get_account().storage_scheme,+ processor.get_key_store(),+ processor.get_account().storage_scheme,).await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;@@ -813,8 +808,8 @@ pub async fn get_payment_link_status(&payment_intent.payment_id,&processor_merchant_id,&attempt_id.clone(),- platform.get_processor().get_account().storage_scheme,- platform.get_processor().get_key_store(),+ processor.get_account().storage_scheme,+ processor.get_key_store(),).await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;@@ -824,8 +819,7 @@ pub async fn get_payment_link_status(.get_required_value("payment_link_id").change_context(errors::ApiErrorResponse::PaymentLinkNotFound)?;- let merchant_name_from_merchant_account = platform- .get_processor()+ let merchant_name_from_merchant_account = processor.get_account().merchant_name.clone()@@ -898,7 +892,7 @@ pub async fn get_payment_link_status(.attach_printable("Profile id missing in payment link and payment intent")?;let business_profile = db- .find_business_profile_by_profile_id(platform.get_processor().get_key_store(), &profile_id)+ .find_business_profile_by_profile_id(processor.get_key_store(), &profile_id).await.to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {id: profile_id.get_string_repr().to_owned(),diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex e0ff37aae3..830896d411 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -292,7 +292,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>create_payment_link(request,payment_link_config,- platform.get_processor(),+ platform,payment_id.clone(),db,amount,@@ -1977,7 +1977,7 @@ pub fn payments_create_request_validation(async fn create_payment_link(request: &api::PaymentsRequest,payment_link_config: api_models::admin::PaymentLinkConfig,- processor: &domain::Processor,+ platform: &domain::Platform,payment_id: common_utils::id_type::PaymentId,db: &dyn StorageInterface,amount: api::Amount,@@ -1990,11 +1990,11 @@ async fn create_payment_link(let created_at @ last_modified_at = Some(common_utils::date_time::now());let payment_link_id = utils::generate_id(consts::ID_LENGTH, "plink");let locale_str = locale.unwrap_or("en".to_owned());- let merchant_id = processor.get_account().get_id();+ let processor_merchant_id = platform.get_processor().get_account().get_id();let open_payment_link = format!("{}/payment_link/{}/{}?locale={}",domain_name,- merchant_id.get_string_repr(),+ processor_merchant_id.get_string_repr(),payment_id.get_string_repr(),locale_str.clone(),);@@ -2003,7 +2003,7 @@ async fn create_payment_link(format!("{}/payment_link/s/{}/{}?locale={}",domain_name,- merchant_id.get_string_repr(),+ processor_merchant_id.get_string_repr(),payment_id.get_string_repr(),locale_str,)@@ -2018,7 +2018,7 @@ async fn create_payment_link(let payment_link_req = storage::PaymentLinkNew {payment_link_id: payment_link_id.clone(),payment_id: payment_id.clone(),- merchant_id: merchant_id.clone(),+ merchant_id: platform.get_provider().get_account().get_id().clone(),link_to_pay: open_payment_link.clone(),amount: MinorUnit::from(amount),currency: request.currency,@@ -2030,6 +2030,11 @@ async fn create_payment_link(payment_link_config: Some(payment_link_config_encoded_value),profile_id: Some(profile_id),secure_link,+ processor_merchant_id: Some(processor_merchant_id.clone()),+ created_by: platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),};let payment_link_db = db.insert_payment_link(payment_link_req)diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rsindex af00fdab7b..44c4d8336f 100644--- a/crates/router/src/db/kafka_store.rs+++ b/crates/router/src/db/kafka_store.rs@@ -1040,13 +1040,16 @@ impl PaymentLinkInterface for KafkaStore {.await}- async fn list_payment_link_by_merchant_id(+ async fn list_payment_link_by_processor_merchant_id(&self,- merchant_id: &id_type::MerchantId,+ processor_merchant_id: &id_type::MerchantId,payment_link_constraints: api_models::payments::PaymentLinkListConstraints,) -> CustomResult<Vec<storage::PaymentLink>, errors::StorageError> {self.diesel_store- .list_payment_link_by_merchant_id(merchant_id, payment_link_constraints)+ .list_payment_link_by_processor_merchant_id(+ processor_merchant_id,+ payment_link_constraints,+ ).await}}diff --git a/crates/router/src/db/payment_link.rs b/crates/router/src/db/payment_link.rsindex 50be9ec728..f203e737f5 100644--- a/crates/router/src/db/payment_link.rs+++ b/crates/router/src/db/payment_link.rs@@ -21,9 +21,9 @@ pub trait PaymentLinkInterface {_payment_link: storage::PaymentLinkNew,) -> CustomResult<storage::PaymentLink, errors::StorageError>;- async fn list_payment_link_by_merchant_id(+ async fn list_payment_link_by_processor_merchant_id(&self,- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,payment_link_constraints: api_models::payments::PaymentLinkListConstraints,) -> CustomResult<Vec<storage::PaymentLink>, errors::StorageError>;}@@ -54,15 +54,19 @@ impl PaymentLinkInterface for Store {}#[instrument(skip_all)]- async fn list_payment_link_by_merchant_id(+ async fn list_payment_link_by_processor_merchant_id(&self,- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,payment_link_constraints: api_models::payments::PaymentLinkListConstraints,) -> CustomResult<Vec<storage::PaymentLink>, errors::StorageError> {let conn = connection::pg_connection_read(self).await?;- storage::PaymentLink::filter_by_constraints(&conn, merchant_id, payment_link_constraints)- .await- .map_err(|error| report!(errors::StorageError::from(error)))+ storage::PaymentLink::filter_by_constraints(+ &conn,+ processor_merchant_id,+ payment_link_constraints,+ )+ .await+ .map_err(|error| report!(errors::StorageError::from(error)))}}@@ -84,9 +88,9 @@ impl PaymentLinkInterface for MockDb {Err(errors::StorageError::MockDbError)?}- async fn list_payment_link_by_merchant_id(+ async fn list_payment_link_by_processor_merchant_id(&self,- _merchant_id: &common_utils::id_type::MerchantId,+ _processor_merchant_id: &common_utils::id_type::MerchantId,_payment_link_constraints: api_models::payments::PaymentLinkListConstraints,) -> CustomResult<Vec<storage::PaymentLink>, errors::StorageError> {// TODO: Implement function for `MockDb`xdiff --git a/crates/router/src/routes/payment_link.rs b/crates/router/src/routes/payment_link.rsindex 450bcf75d1..a6c0c92c09 100644--- a/crates/router/src/routes/payment_link.rs+++ b/crates/router/src/routes/payment_link.rs@@ -19,7 +19,10 @@ pub async fn payment_link_retrieve() -> impl Responder {let flow = Flow::PaymentLinkRetrieve;let payload = json_payload.into_inner();- let api_auth = auth::ApiKeyAuth::default();+ let api_auth = auth::ApiKeyAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ };let (auth_type, _) = {#[cfg(feature = "v1")]@@ -73,7 +76,7 @@ pub async fn initiate_payment_link(|state, auth: auth::AuthenticationData, _, _| {initiate_payment_link_flow(state,- auth.platform,+ auth.platform.get_processor().clone(),payload.merchant_id.clone(),payload.payment_id.clone(),)@@ -107,7 +110,7 @@ pub async fn initiate_secure_payment_link(|state, auth: auth::AuthenticationData, _, _| {initiate_secure_payment_link_flow(state,- auth.platform,+ auth.platform.get_processor().clone(),payload.merchant_id.clone(),payload.payment_id.clone(),headers,@@ -143,7 +146,7 @@ pub async fn payments_link_list()},&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),api_locking::LockAction::NotApplicable,@@ -174,7 +177,7 @@ pub async fn payment_link_status(|state, auth: auth::AuthenticationData, _, _| {get_payment_link_status(state,- auth.platform,+ auth.platform.get_processor().clone(),payload.merchant_id.clone(),payload.payment_id.clone(),)diff --git a/crates/router/src/types/api/payment_link.rs b/crates/router/src/types/api/payment_link.rsindex 3d50db35fc..e7149efdf4 100644--- a/crates/router/src/types/api/payment_link.rs+++ b/crates/router/src/types/api/payment_link.rs@@ -27,6 +27,7 @@ impl PaymentLinkResponseExt for RetrievePaymentLinkResponse {description: payment_link.description,created_at: payment_link.created_at,merchant_id: payment_link.merchant_id,+ processor_merchant_id: payment_link.processor_merchant_id,expiry: payment_link.fulfilment_time,currency: payment_link.currency,status,diff --git a/crates/router/src/types/storage/payment_link.rs b/crates/router/src/types/storage/payment_link.rsindex ae9aa41732..71e20ddc6c 100644--- a/crates/router/src/types/storage/payment_link.rs+++ b/crates/router/src/types/storage/payment_link.rs@@ -1,5 +1,5 @@use async_bb8_diesel::AsyncRunQueryDsl;-use diesel::{associations::HasTable, ExpressionMethods, QueryDsl};+use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods, QueryDsl};pub use diesel_models::{payment_link::{PaymentLink, PaymentLinkNew},schema::payment_link::dsl,@@ -16,7 +16,7 @@ use crate::{pub trait PaymentLinkDbExt: Sized {async fn filter_by_constraints(conn: &PgPooledConn,- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,payment_link_list_constraints: api_models::payments::PaymentLinkListConstraints,) -> CustomResult<Vec<Self>, errors::DatabaseError>;}@@ -25,11 +25,17 @@ pub trait PaymentLinkDbExt: Sized {impl PaymentLinkDbExt for PaymentLink {async fn filter_by_constraints(conn: &PgPooledConn,- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,payment_link_list_constraints: api_models::payments::PaymentLinkListConstraints,) -> CustomResult<Vec<Self>, errors::DatabaseError> {let mut filter = <Self as HasTable>::table()- .filter(dsl::merchant_id.eq(merchant_id.to_owned()))+ .filter(+ dsl::processor_merchant_id+ .eq(processor_merchant_id.to_owned())+ .or(dsl::processor_merchant_id+ .is_null()+ .and(dsl::merchant_id.eq(processor_merchant_id.to_owned()))),+ ).order(dsl::created_at.desc()).into_boxed();diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex f2084efcd0..0cf7a84507 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -1766,6 +1766,7 @@ impl ForeignFrom<(storage::PaymentLink, payments::PaymentLinkStatus)>Self {payment_link_id: payment_link_config.payment_link_id,merchant_id: payment_link_config.merchant_id,+ processor_merchant_id: payment_link_config.processor_merchant_id,link_to_pay: payment_link_config.link_to_pay,amount: payment_link_config.amount,created_at: payment_link_config.created_at,diff --git a/migrations/2026-04-16-135945_add_processor_merchant_id_created_by_to_payment_link/down.sql b/migrations/2026-04-16-135945_add_processor_merchant_id_created_by_to_payment_link/down.sqlnew file mode 100644index 0000000000..36f2f1df1e--- /dev/null+++ b/migrations/2026-04-16-135945_add_processor_merchant_id_created_by_to_payment_link/down.sql@@ -0,0 +1,3 @@+-- This file should undo anything in `up.sql`+ALTER TABLE payment_link DROP COLUMN IF EXISTS processor_merchant_id;+ALTER TABLE payment_link DROP COLUMN IF EXISTS created_by;diff --git a/migrations/2026-04-16-135945_add_processor_merchant_id_created_by_to_payment_link/up.sql b/migrations/2026-04-16-135945_add_processor_merchant_id_created_by_to_payment_link/up.sqlnew file mode 100644index 0000000000..65107ab24b--- /dev/null+++ b/migrations/2026-04-16-135945_add_processor_merchant_id_created_by_to_payment_link/up.sql@@ -0,0 +1,6 @@+-- Your SQL goes here+ALTER TABLE payment_link ADD COLUMN IF NOT EXISTS processor_merchant_id VARCHAR(64);+ALTER TABLE payment_link ADD COLUMN IF NOT EXISTS created_by VARCHAR(255);++-- This backfill should be executed after deployment is complete.+UPDATE payment_link SET processor_merchant_id = merchant_id WHERE processor_merchant_id IS NULL;