Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(connector): [Adyen] change expiresAt time from string to unixtimestamp (#3506)
Swangi Kumarib7c0f9aa098c
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 3b85644553..a4f052549b 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -2019,7 +2019,7 @@ pub struct BankTransferNextStepsData {#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]pub struct VoucherNextStepData {/// Voucher expiry date and time- pub expires_at: Option<String>,+ pub expires_at: Option<i64>,/// Reference number required for the transactionpub reference: String,/// Url to download the payment instruction@@ -2087,8 +2087,8 @@ pub struct MultibancoTransferInstructions {#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]pub struct DokuBankTransferInstructions {- #[schema(value_type = String, example = "2023-07-26T17:33:00-07-21")]- pub expires_at: Option<String>,+ #[schema(value_type = String, example = "1707091200000")]+ pub expires_at: Option<i64>,#[schema(value_type = String, example = "122385736258")]pub reference: Secret<String>,#[schema(value_type = String)]diff --git a/crates/common_utils/src/custom_serde.rs b/crates/common_utils/src/custom_serde.rsindex edbfa143a6..e4608c4f37 100644--- a/crates/common_utils/src/custom_serde.rs+++ b/crates/common_utils/src/custom_serde.rs@@ -84,6 +84,53 @@ pub mod iso8601 {})}}+ /// Use the well-known ISO 8601 format which is without timezone when serializing and deserializing an+ /// [`Option<PrimitiveDateTime>`][PrimitiveDateTime].+ ///+ /// [PrimitiveDateTime]: ::time::PrimitiveDateTime+ pub mod option_without_timezone {+ use serde::{de, Deserialize, Serialize};+ use time::macros::format_description;++ use super::*;++ /// Serialize an [`Option<PrimitiveDateTime>`] using the well-known ISO 8601 format which is without timezone.+ pub fn serialize<S>(+ date_time: &Option<PrimitiveDateTime>,+ serializer: S,+ ) -> Result<S::Ok, S::Error>+ where+ S: Serializer,+ {+ date_time+ .map(|date_time| {+ let format =+ format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]");+ date_time.assume_utc().format(format)+ })+ .transpose()+ .map_err(S::Error::custom)?+ .serialize(serializer)+ }++ /// Deserialize an [`Option<PrimitiveDateTime>`] from its ISO 8601 representation.+ pub fn deserialize<'a, D>(deserializer: D) -> Result<Option<PrimitiveDateTime>, D::Error>+ where+ D: Deserializer<'a>,+ {+ Option::deserialize(deserializer)?+ .map(|time_string| {+ let format =+ format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]");+ PrimitiveDateTime::parse(time_string, format).map_err(|_| {+ de::Error::custom(format!(+ "Failed to parse PrimitiveDateTime from {time_string}"+ ))+ })+ })+ .transpose()+ }+ }}/// Use the UNIX timestamp when serializing and deserializing andiff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rsindex 8da5d15c44..b141634d46 100644--- a/crates/router/src/connector/adyen/transformers.rs+++ b/crates/router/src/connector/adyen/transformers.rs@@ -370,7 +370,12 @@ pub struct AdyenPtsAction {reference: String,download_url: Option<Url>,payment_method_type: PaymentType,- expires_at: Option<String>,+ #[serde(rename = "expiresAt")]+ #[serde(+ default,+ with = "common_utils::custom_serde::iso8601::option_without_timezone"+ )]+ expires_at: Option<PrimitiveDateTime>,initial_amount: Option<Amount>,pass_creation_token: Option<String>,total_amount: Option<Amount>,@@ -3434,6 +3439,10 @@ pub fn get_present_to_shopper_metadata(response: &PresentToShopperResponse,) -> errors::CustomResult<Option<serde_json::Value>, errors::ConnectorError> {let reference = response.action.reference.clone();+ let expires_at = response+ .action+ .expires_at+ .map(|time| utils::get_timestamp_in_milliseconds(&time));match response.action.payment_method_type {PaymentType::Alfamart@@ -3446,7 +3455,7 @@ pub fn get_present_to_shopper_metadata(| PaymentType::Seicomart| PaymentType::PayEasy => {let voucher_data = payments::VoucherNextStepData {- expires_at: response.action.expires_at.clone(),+ expires_at,reference,download_url: response.action.download_url.clone(),instructions_url: response.action.instructions_url.clone(),@@ -3470,7 +3479,7 @@ pub fn get_present_to_shopper_metadata(Box::new(payments::DokuBankTransferInstructions {reference: Secret::new(response.action.reference.clone()),instructions_url: response.action.instructions_url.clone(),- expires_at: response.action.expires_at.clone(),+ expires_at,}),);diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex d516eeed4c..9afd518252 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -7738,7 +7738,7 @@"properties": {"expires_at": {"type": "string",- "example": "2023-07-26T17:33:00-07-21"+ "example": "1707091200000"},"reference": {"type": "string",