Skip to content

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

refactor(payment_methods): update api contract for update payment method endpoint (#4641)

Chethan Raoe43ae653a02c
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index b7a58b3b5b..e045cf2c42 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -88,24 +88,6 @@ pub struct PaymentMethodUpdate {
"card_holder_name": "John Doe"}))]
pub card: Option<CardDetailUpdate>,
- /// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
- #[schema(value_type = Option<CardNetwork>,example = "Visa")]
- pub card_network: Option<api_enums::CardNetwork>,
-
- /// Payment method details from locker
- #[cfg(feature = "payouts")]
- #[schema(value_type = Option<Bank>)]
- pub bank_transfer: Option<payouts::Bank>,
-
- /// Payment method details from locker
- #[cfg(feature = "payouts")]
- #[schema(value_type = Option<Wallet>)]
- pub wallet: Option<payouts::Wallet>,
-
- /// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
- #[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
- pub metadata: Option<pii::SecretSerdeValue>,
-
/// This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK
#[schema(max_length = 30, min_length = 30, example = "secret_k2uj3he2893eiu2d")]
pub client_secret: Option<String>,
diff --git a/crates/openapi/src/routes/payment_method.rs b/crates/openapi/src/routes/payment_method.rs
index 07e6cc3590..3bc593aa5b 100644
--- a/crates/openapi/src/routes/payment_method.rs
+++ b/crates/openapi/src/routes/payment_method.rs
@@ -138,7 +138,7 @@ pub async fn payment_method_retrieve_api() {}
/// This API is useful for use cases such as updating the card number for expired cards to prevent discontinuity in recurring payments.
#[utoipa::path(
post,
- path = "/payment_methods/{method_id}",
+ path = "/payment_methods/{method_id}/update",
params (
("method_id" = String, Path, description = "The unique identifier for the Payment Method"),
),
@@ -149,7 +149,7 @@ pub async fn payment_method_retrieve_api() {}
),
tag = "Payment Methods",
operation_id = "Update a Payment method",
- security(("api_key" = []))
+ security(("api_key" = []), ("publishable_key" = []))
)]
pub async fn payment_method_update_api() {}
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 8c946630c8..307f2dcd08 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -775,6 +775,14 @@ pub async fn update_customer_payment_method(
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
+ if let Some(cs) = &req.client_secret {
+ let is_client_secret_expired = authenticate_pm_client_secret_and_check_expiry(cs, &pm)?;
+
+ if is_client_secret_expired {
+ return Err((errors::ApiErrorResponse::ClientSecretExpired).into());
+ };
+ };
+
if pm.status == enums::PaymentMethodStatus::AwaitingData {
return Err(report!(errors::ApiErrorResponse::NotSupported {
message: "Payment method is awaiting data so it cannot be updated".into()
@@ -849,18 +857,15 @@ pub async fn update_customer_payment_method(
payment_method_issuer: pm.payment_method_issuer.clone(),
payment_method_issuer_code: pm.payment_method_issuer_code,
#[cfg(feature = "payouts")]
- bank_transfer: req.bank_transfer,
+ bank_transfer: None,
card: Some(updated_card_details.clone()),
#[cfg(feature = "payouts")]
- wallet: req.wallet,
- metadata: req.metadata,
+ wallet: None,
+ metadata: None,
customer_id: Some(pm.customer_id.clone()),
client_secret: pm.client_secret.clone(),
payment_method_data: None,
- card_network: req
- .card_network
- .as_ref()
- .map(|card_network| card_network.to_string()),
+ card_network: None,
};
new_pm.validate()?;
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index d9061baebb..0c3893c463 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -2612,13 +2612,13 @@
}
]
},
- "post": {
+ "delete": {
"tags": [
"Payment Methods"
],
- "summary": "Payment Method - Update",
- "description": "Payment Method - Update\n\nUpdate an existing payment method of a customer.\nThis API is useful for use cases such as updating the card number for expired cards to prevent discontinuity in recurring payments.",
- "operationId": "Update a Payment method",
+ "summary": "Payment Method - Delete",
+ "description": "Payment Method - Delete\n\nDeletes a payment method of a customer.",
+ "operationId": "Delete a Payment method",
"parameters": [
{
"name": "method_id",
@@ -2630,23 +2630,13 @@
}
}
],
- "requestBody": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/PaymentMethodUpdate"
- }
- }
- },
- "required": true
- },
"responses": {
"200": {
- "description": "Payment Method updated",
+ "description": "Payment Method deleted",
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/PaymentMethodResponse"
+ "$ref": "#/components/schemas/PaymentMethodDeleteResponse"
}
}
}
@@ -2660,14 +2650,16 @@
"api_key": []
}
]
- },
- "delete": {
+ }
+ },
+ "/payment_methods/{method_id}/update": {
+ "post": {
"tags": [
"Payment Methods"
],
- "summary": "Payment Method - Delete",
- "description": "Payment Method - Delete\n\nDeletes a payment method of a customer.",
- "operationId": "Delete a Payment method",
+ "summary": "Payment Method - Update",
+ "description": "Payment Method - Update\n\nUpdate an existing payment method of a customer.\nThis API is useful for use cases such as updating the card number for expired cards to prevent discontinuity in recurring payments.",
+ "operationId": "Update a Payment method",
"parameters": [
{
"name": "method_id",
@@ -2679,13 +2671,23 @@
}
}
],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PaymentMethodUpdate"
+ }
+ }
+ },
+ "required": true
+ },
"responses": {
"200": {
- "description": "Payment Method deleted",
+ "description": "Payment Method updated",
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/PaymentMethodDeleteResponse"
+ "$ref": "#/components/schemas/PaymentMethodResponse"
}
}
}
@@ -2697,6 +2699,9 @@
"security": [
{
"api_key": []
+ },
+ {
+ "publishable_key": []
}
]
}
@@ -13258,35 +13263,6 @@
],
"nullable": true
},
- "card_network": {
- "allOf": [
- {
- "$ref": "#/components/schemas/CardNetwork"
- }
- ],
- "nullable": true
- },
- "bank_transfer": {
- "allOf": [
- {
- "$ref": "#/components/schemas/Bank"
- }
- ],
- "nullable": true
- },
- "wallet": {
- "allOf": [
- {
- "$ref": "#/components/schemas/Wallet"
- }
- ],
- "nullable": true
- },
- "metadata": {
- "type": "object",
- "description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.",
- "nullable": true
- },
"client_secret": {
"type": "string",
"description": "This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK",