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

This commit is contained in:
Chethan Rao
2024-05-14 18:19:35 +05:30
committed by GitHub
parent 6b509c7bec
commit e43ae653a0
4 changed files with 56 additions and 93 deletions

View File

@ -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>,

View File

@ -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() {}

View File

@ -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()?;

View File

@ -2612,6 +2612,47 @@
}
]
},
"delete": {
"tags": [
"Payment Methods"
],
"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",
"in": "path",
"description": "The unique identifier for the Payment Method",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Payment Method deleted",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaymentMethodDeleteResponse"
}
}
}
},
"404": {
"description": "Payment Method does not exist in records"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/payment_methods/{method_id}/update": {
"post": {
"tags": [
"Payment Methods"
@ -2658,45 +2699,9 @@
"security": [
{
"api_key": []
}
]
},
"delete": {
"tags": [
"Payment Methods"
],
"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",
"in": "path",
"description": "The unique identifier for the Payment Method",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Payment Method deleted",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaymentMethodDeleteResponse"
}
}
}
},
"404": {
"description": "Payment Method does not exist in records"
}
},
"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",