mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
fix(compatibility): Add metadata object in both payment_intent and setup_intent request (#1519)
Co-authored-by: Sahkal Poddar <sahkal.poddar@juspay.in> Co-authored-by: Abhishek Marrivagu <68317979+Abhicodes-crypto@users.noreply.github.com>
This commit is contained in:
@ -14,6 +14,7 @@ use crate::{
|
||||
api::{admin, enums as api_enums},
|
||||
transformers::{ForeignFrom, ForeignTryFrom},
|
||||
},
|
||||
utils::OptionExt,
|
||||
};
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
@ -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()),
|
||||
@ -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,
|
||||
|
||||
@ -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};
|
||||
@ -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)]
|
||||
@ -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>,
|
||||
@ -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>,
|
||||
@ -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,
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user