feat: store card network for cards (#687)

This commit is contained in:
Narayan Bhat
2023-02-28 18:30:03 +05:30
committed by GitHub
parent 5c29f37ab2
commit bfca26d9fd
3 changed files with 19 additions and 1 deletions

View File

@ -41,6 +41,10 @@ pub struct CreatePaymentMethod {
/// The unique identifier of the customer. /// The unique identifier of the customer.
#[schema(example = "cus_meowerunwiuwiwqw")] #[schema(example = "cus_meowerunwiuwiwqw")]
pub customer_id: Option<String>, pub customer_id: Option<String>,
/// The card network
#[schema(example = "Visa")]
pub card_network: Option<String>,
} }
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)] #[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
@ -54,6 +58,10 @@ pub struct UpdatePaymentMethod {
"card_holder_name": "John Doe"}))] "card_holder_name": "John Doe"}))]
pub card: Option<CardDetail>, pub card: Option<CardDetail>,
/// 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>,
/// 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. /// 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" }))] #[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<serde_json::Value>, pub metadata: Option<serde_json::Value>,

View File

@ -48,6 +48,7 @@ pub async fn create_payment_method(
payment_method: req.payment_method.foreign_into(), payment_method: req.payment_method.foreign_into(),
payment_method_type: req.payment_method_type.map(ForeignInto::foreign_into), payment_method_type: req.payment_method_type.map(ForeignInto::foreign_into),
payment_method_issuer: req.payment_method_issuer.clone(), payment_method_issuer: req.payment_method_issuer.clone(),
scheme: req.card_network.clone(),
metadata: req.metadata.clone(), metadata: req.metadata.clone(),
..storage::PaymentMethodNew::default() ..storage::PaymentMethodNew::default()
}) })
@ -129,6 +130,10 @@ pub async fn update_customer_payment_method(
card: req.card, card: req.card,
metadata: req.metadata, metadata: req.metadata,
customer_id: Some(pm.customer_id), customer_id: Some(pm.customer_id),
card_network: req
.card_network
.as_ref()
.map(|card_network| card_network.to_string()),
}; };
add_payment_method(state, new_pm, &merchant_account).await add_payment_method(state, new_pm, &merchant_account).await
} }

View File

@ -517,11 +517,15 @@ pub(crate) async fn call_payment_method(
let payment_method_request = api::CreatePaymentMethod { let payment_method_request = api::CreatePaymentMethod {
payment_method: payment_method_type.foreign_into(), payment_method: payment_method_type.foreign_into(),
payment_method_type: None, payment_method_type: None,
payment_method_issuer: None, payment_method_issuer: card.card_issuer.clone(),
payment_method_issuer_code: None, payment_method_issuer_code: None,
card: Some(card_detail), card: Some(card_detail),
metadata: None, metadata: None,
customer_id: Some(customer_id), customer_id: Some(customer_id),
card_network: card
.card_network
.as_ref()
.map(|card_network| card_network.to_string()),
}; };
let resp = cards::add_payment_method( let resp = cards::add_payment_method(
state, state,
@ -553,6 +557,7 @@ pub(crate) async fn call_payment_method(
card: None, card: None,
metadata: None, metadata: None,
customer_id: None, customer_id: None,
card_network: None,
}; };
let resp = let resp =
cards::add_payment_method(state, payment_method_request, merchant_account) cards::add_payment_method(state, payment_method_request, merchant_account)