Skip to content

Commit

Permalink
fix(compatibility): Add metadata object in both payment_intent and se…
Browse files Browse the repository at this point in the history
…tup_intent request (#1519)

Co-authored-by: Sahkal Poddar <[email protected]>
Co-authored-by: Abhishek Marrivagu <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2023
1 parent 0c86243 commit 6ec6272
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
api::{admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
utils::OptionExt,
};

#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
Expand Down Expand Up @@ -218,6 +219,13 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
field_name: "receipt_ipaddress".to_string(),
expected_format: "127.0.0.1".to_string(),
})?;
let metadata_object = item
.metadata
.clone()
.parse_value("metadata")
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "metadata mapping failed",
})?;
let request = Ok(Self {
payment_id: item.id.map(payments::PaymentIdType::PaymentIntentId),
amount: item.amount.map(|amount| amount.into()),
Expand Down Expand Up @@ -255,6 +263,7 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
.and_then(|pmd| pmd.billing_details.map(payments::Address::from)),
statement_descriptor_name: item.statement_descriptor,
statement_descriptor_suffix: item.statement_descriptor_suffix,
metadata: metadata_object,
udf: item.metadata,
client_secret: item.client_secret.map(|s| s.peek().clone()),
authentication_type,
Expand Down
16 changes: 12 additions & 4 deletions crates/router/src/compatibility/stripe/setup_intents/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use api_models::payments;
use common_utils::{date_time, ext_traits::StringExt};
use common_utils::{date_time, ext_traits::StringExt, pii as secret};
use error_stack::{IntoReport, ResultExt};
use router_env::logger;
use serde::{Deserialize, Serialize};
Expand All @@ -18,6 +18,7 @@ use crate::{
api::{self as api_types, admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
utils::OptionExt,
};

#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
Expand Down Expand Up @@ -121,7 +122,6 @@ impl From<Shipping> for payments::Address {
}

#[derive(Default, PartialEq, Eq, Deserialize, Clone)]

pub struct StripeSetupIntentRequest {
pub confirm: Option<bool>,
pub customer: Option<String>,
Expand All @@ -135,7 +135,7 @@ pub struct StripeSetupIntentRequest {
pub billing_details: Option<StripeBillingDetails>,
pub statement_descriptor: Option<String>,
pub statement_descriptor_suffix: Option<String>,
pub metadata: Option<api_models::payments::Metadata>,
pub metadata: Option<secret::SecretSerdeValue>,
pub client_secret: Option<pii::Secret<String>>,
pub payment_method_options: Option<payment_intent::StripePaymentMethodOptions>,
pub payment_method: Option<String>,
Expand Down Expand Up @@ -174,6 +174,13 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
field_name: "receipt_ipaddress".to_string(),
expected_format: "127.0.0.1".to_string(),
})?;
let metadata_object = item
.metadata
.clone()
.parse_value("metadata")
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "metadata mapping failed",
})?;
let request = Ok(Self {
amount: Some(api_types::Amount::Zero),
capture_method: None,
Expand Down Expand Up @@ -215,7 +222,8 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
.map(|b| payments::Address::from(b.to_owned())),
statement_descriptor_name: item.statement_descriptor,
statement_descriptor_suffix: item.statement_descriptor_suffix,
metadata: item.metadata,
metadata: metadata_object,
udf: item.metadata,
client_secret: item.client_secret.map(|s| s.peek().clone()),
setup_future_usage: item.setup_future_usage,
merchant_connector_details: item.merchant_connector_details,
Expand Down

0 comments on commit 6ec6272

Please sign in to comment.