refactor(core): accept customer data in customer object (#1447)

Co-authored-by: Abhishek Marrivagu <68317979+Abhicodes-crypto@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2023-06-16 18:55:01 +05:30
committed by GitHub
parent 3ef1d2935e
commit cff1ce61f0
11 changed files with 195 additions and 66 deletions

View File

@ -45,6 +45,28 @@ pub struct BankCodeResponse {
pub eligible_connectors: Vec<String>,
}
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct CustomerDetails {
/// The identifier for the customer.
pub id: String,
/// The customer's name
#[schema(max_length = 255, value_type = Option<String>, example = "John Doe")]
pub name: Option<Secret<String>>,
/// The customer's email address
#[schema(max_length = 255, value_type = Option<String>, example = "johntest@test.com")]
pub email: Option<Email>,
/// The customer's phone number
#[schema(value_type = Option<String>, max_length = 10, example = "3141592653")]
pub phone: Option<Secret<String>>,
/// The country code for the customer's phone number
#[schema(max_length = 2, example = "+1")]
pub phone_country_code: Option<String>,
}
#[derive(
Default,
Debug,
@ -114,23 +136,33 @@ pub struct PaymentsRequest {
#[schema(default = false, example = true)]
pub confirm: Option<bool>,
/// The identifier for the customer object. If not provided the customer ID will be autogenerated.
/// The details of a customer for this payment
/// This will create the customer if `customer.id` does not exist
/// If customer id already exists, it will update the details of the customer
pub customer: Option<CustomerDetails>,
/// The identifier for the customer object.
/// This field will be deprecated soon, use the customer object instead
#[schema(max_length = 255, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
pub customer_id: Option<String>,
/// description: The customer's email address
/// The customer's email address
/// This field will be deprecated soon, use the customer object instead
#[schema(max_length = 255, value_type = Option<String>, example = "johntest@test.com")]
pub email: Option<Email>,
/// description: The customer's name
/// This field will be deprecated soon, use the customer object instead
#[schema(value_type = Option<String>, max_length = 255, example = "John Test")]
pub name: Option<Secret<String>>,
/// The customer's phone number
/// This field will be deprecated soon, use the customer object instead
#[schema(value_type = Option<String>, max_length = 255, example = "3141592653")]
pub phone: Option<Secret<String>>,
/// The country code for the customer phone number
/// This field will be deprecated soon, use the customer object instead
#[schema(max_length = 255, example = "+1")]
pub phone_country_code: Option<String>,
@ -303,27 +335,6 @@ pub struct VerifyRequest {
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
}
impl From<PaymentsRequest> for VerifyRequest {
fn from(item: PaymentsRequest) -> Self {
Self {
client_secret: item.client_secret,
merchant_id: item.merchant_id,
customer_id: item.customer_id,
email: item.email,
name: item.name,
phone: item.phone,
phone_country_code: item.phone_country_code,
payment_method: item.payment_method,
payment_method_data: item.payment_method_data,
payment_token: item.payment_token,
mandate_data: item.mandate_data,
setup_future_usage: item.setup_future_usage,
off_session: item.off_session,
merchant_connector_details: item.merchant_connector_details,
}
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MandateTxnType {
@ -1478,7 +1489,12 @@ impl From<&PaymentsRequest> for MandateValidationFields {
Self {
mandate_id: req.mandate_id.clone(),
confirm: req.confirm,
customer_id: req.customer_id.clone(),
customer_id: req
.customer
.as_ref()
.map(|customer_details| &customer_details.id)
.or(req.customer_id.as_ref())
.map(ToOwned::to_owned),
mandate_data: req.mandate_data.clone(),
setup_future_usage: req.setup_future_usage,
off_session: req.off_session,