Skip to content

Commit

Permalink
feat: return customer details in payments response body (#4237)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithikesh026 authored Apr 1, 2024
1 parent a843713 commit 740749e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod client_secret_tests {
}
}

#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema, PartialEq)]
pub struct CustomerDetails {
/// The identifier for the customer.
pub id: String,
Expand Down Expand Up @@ -2935,6 +2935,9 @@ pub struct PaymentsResponse {
#[schema(max_length = 255, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
pub customer_id: Option<String>,

/// Details of customer attached to this payment
pub customer: Option<CustomerDetails>,

/// A description of the payment
#[schema(example = "It's my first payment request")]
pub description: Option<String>,
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ where
))
}

let customer_details_response = customer.as_ref().map(ForeignInto::foreign_into);

headers.extend(
external_latency
.map(|latency| {
Expand Down Expand Up @@ -779,6 +781,7 @@ where
.set_payment_method_status(
payment_data.payment_method_info.map(|info| info.status),
)
.set_customer(customer_details_response.clone())
.to_owned(),
headers,
))
Expand Down Expand Up @@ -849,6 +852,7 @@ where
expires_on: payment_intent.session_expiry,
external_3ds_authentication_attempted: payment_attempt
.external_three_ds_authentication_attempted,
customer: customer_details_response,
..Default::default()
},
headers,
Expand Down
18 changes: 18 additions & 0 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,24 @@ impl ForeignFrom<storage::GatewayStatusMap> for gsm_api_types::GsmResponse {
}
}

impl ForeignFrom<&domain::Customer> for api_models::payments::CustomerDetails {
fn foreign_from(customer: &domain::Customer) -> Self {
Self {
id: customer.customer_id.clone(),
name: customer
.name
.as_ref()
.map(|name| name.get_inner().to_owned()),
email: customer.email.clone().map(Into::into),
phone: customer
.phone
.as_ref()
.map(|phone| phone.get_inner().to_owned()),
phone_country_code: customer.phone_country_code.clone(),
}
}
}

#[cfg(feature = "olap")]
impl ForeignTryFrom<api_types::webhook_events::EventListConstraints>
for api_types::webhook_events::EventListConstraintsInternal
Expand Down
8 changes: 8 additions & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -14338,6 +14338,14 @@
"nullable": true,
"maxLength": 255
},
"customer": {
"allOf": [
{
"$ref": "#/components/schemas/CustomerDetails"
}
],
"nullable": true
},
"description": {
"type": "string",
"description": "A description of the payment",
Expand Down

0 comments on commit 740749e

Please sign in to comment.