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
refactor(payment_methods): add `requires_cvv` field to customer payment method list api object (#1852)
Chethan Rao2dec2ca50bba
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rsindex 248525fcc4..f795513c6e 100644--- a/crates/api_models/src/payment_methods.rs+++ b/crates/api_models/src/payment_methods.rs@@ -577,6 +577,10 @@ pub struct CustomerPaymentMethod {#[cfg(feature = "payouts")]#[schema(value_type = Option<Bank>)]pub bank_transfer: Option<payouts::Bank>,++ /// Whether this payment method requires CVV to be collected+ #[schema(example = true)]+ pub requires_cvv: bool,}#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]pub struct PaymentMethodId {diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rsindex 8b7db2d6c8..9dab92f67f 100644--- a/crates/router/src/core/payment_methods/cards.rs+++ b/crates/router/src/core/payment_methods/cards.rs@@ -1727,6 +1727,25 @@ pub async fn list_customer_payment_method(.await.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)?;+ let is_requires_cvv = db+ .find_config_by_key(format!("{}_requires_cvv", merchant_account.merchant_id).as_str())+ .await;++ let requires_cvv = match is_requires_cvv {+ // If an entry is found with the config value as `false`, we set requires_cvv to false+ Ok(value) => value.config != "false",+ Err(err) => {+ if err.current_context().is_db_not_found() {+ // By default, cvv is made required field for all merchants+ true+ } else {+ Err(err+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to fetch merchant_id config for requires_cvv"))?+ }+ }+ };+let resp = db.find_payment_method_by_customer_id_merchant_id_list(customer_id,@@ -1771,6 +1790,7 @@ pub async fn list_customer_payment_method(bank_transfer: pmd,#[cfg(not(feature = "payouts"))]bank_transfer: None,+ requires_cvv,};customer_pms.push(pma.to_owned());diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex 5334bf3d63..e25db0bde8 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -4273,7 +4273,8 @@"customer_id","payment_method","recurring_enabled",- "installment_payment_enabled"+ "installment_payment_enabled",+ "requires_cvv"],"properties": {"payment_token": {@@ -4359,6 +4360,11 @@}],"nullable": true+ },+ "requires_cvv": {+ "type": "boolean",+ "description": "Whether this payment method requires CVV to be collected",+ "example": true}}},