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(payment_link): add dedicated dashboard endpoint for Payment Link creation (#13675)
Aniket Burman9c956295efcc
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 091fad5350..4e9df6eeeb 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -1819,6 +1819,32 @@ impl PaymentsRequest {}Ok(())}++ pub fn for_payment_link(self) -> Self {+ Self {+ amount: self.amount,+ currency: self.currency,+ return_url: self.return_url,+ payment_id: self.payment_id,+ authentication_type: self.authentication_type,+ billing: self.billing,+ customer: self.customer,+ description: self.description,+ setup_future_usage: self.setup_future_usage,+ order_details: self.order_details,+ metadata: self.metadata,+ payment_link_config_id: self.payment_link_config_id,+ profile_id: self.profile_id,+ routing: self.routing,+ session_expiry: self.session_expiry,+ merchant_order_reference_id: self.merchant_order_reference_id,+ allowed_payment_method_types: self.allowed_payment_method_types,+ capture_method: self.capture_method,+ payment_link: Some(true),+ confirm: Some(false),+ ..Default::default()+ }+ }}#[cfg(feature = "v1")]diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex a0a3a0120a..9faa7f464c 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -1021,6 +1021,7 @@ impl Payments {{route = route.service(web::resource("").route(web::post().to(payments::payments_create)))+ .service(web::resource("/payment_link").route(web::post().to(payments::payment_link_create))).service(web::resource("/session_tokens").route(web::post().to(payments::payments_connector_session)),diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rsindex ca2c716470..5c2ed6923c 100644--- a/crates/router/src/routes/lock_utils.rs+++ b/crates/router/src/routes/lock_utils.rs@@ -197,6 +197,8 @@ impl From<Flow> for ApiIdentifier {| Flow::RecoveryPaymentsCreate| Flow::PaymentsSubmitCheckEligibility| Flow::PaymentsSubmitEligibility+ // PaymentLinkCreate creates a payment intent, so it uses the Payments lock namespace+ | Flow::PaymentLinkCreate| Flow::PaymentsCancelPostCaptureSync => Self::Payments,Flow::PayoutsCreate| Flow::PayoutsRetrievediff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rsindex 3a726d5a23..f929ce5f53 100644--- a/crates/router/src/routes/payments.rs+++ b/crates/router/src/routes/payments.rs@@ -144,6 +144,80 @@ pub async fn payments_create(.await}+#[cfg(feature = "v1")]+#[instrument(skip_all, fields(flow = ?Flow::PaymentLinkCreate, payment_id))]+pub async fn payment_link_create(+ state: web::Data<app::AppState>,+ req: actix_web::HttpRequest,+ json_payload: web::Json<payment_types::PaymentsRequest>,+) -> impl Responder {+ let flow = Flow::PaymentLinkCreate;+ let mut payload = json_payload.into_inner().for_payment_link();++ if let Err(err) = payload+ .validate()+ .map_err(|message| errors::ApiErrorResponse::InvalidRequestData { message })+ {+ return api::log_and_return_error_response(err.into());+ };++ if let Some(api_enums::CaptureMethod::Scheduled) = payload.capture_method {+ return http_not_implemented();+ };++ if let Err(err) = get_or_generate_payment_id(&mut payload) {+ return api::log_and_return_error_response(err);+ }++ let header_payload = match HeaderPayload::foreign_try_from(req.headers()) {+ Ok(headers) => headers,+ Err(err) => {+ return api::log_and_return_error_response(err);+ }+ };++ tracing::Span::current().record(+ "payment_id",+ payload+ .payment_id+ .as_ref()+ .map(|payment_id_type| payment_id_type.get_payment_intent_id())+ .transpose()+ .unwrap_or_default()+ .as_ref()+ .map(|id| id.get_string_repr())+ .unwrap_or_default(),+ );++ let locking_action = payload.get_locking_input(flow.clone());++ Box::pin(api::server_wrap(+ flow,+ state,+ &req,+ payload,+ |state, auth: auth::AuthenticationData, req, req_state| {+ authorize_verify_select::<_>(+ payments::PaymentCreate,+ state,+ req_state,+ auth.platform,+ auth.profile.map(|profile| profile.get_id().clone()),+ header_payload.clone(),+ req,+ api::AuthFlow::Client,+ )+ },+ &auth::InternalMerchantIdProfileIdAuth(auth::JWTAuth {+ permission: Permission::ProfilePaymentWrite,+ allow_connected: true,+ allow_platform: false,+ }),+ locking_action,+ ))+ .await+}+#[cfg(feature = "v2")]pub async fn recovery_payments_create(state: web::Data<app::AppState>,diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rsindex e71eb87713..b3defdee9a 100644--- a/crates/router_env/src/logger/types.rs+++ b/crates/router_env/src/logger/types.rs@@ -395,6 +395,8 @@ pub enum Flow {PaymentLinkList,/// Payment Link StatusPaymentLinkStatus,+ /// Payment Link Create flow+ PaymentLinkCreate,/// Create a profileProfileCreate,/// Update a profile