mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor(connector): [Adyen] change expiresAt time from string to unixtimestamp (#3506)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -2019,7 +2019,7 @@ pub struct BankTransferNextStepsData {
|
|||||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||||
pub struct VoucherNextStepData {
|
pub struct VoucherNextStepData {
|
||||||
/// Voucher expiry date and time
|
/// Voucher expiry date and time
|
||||||
pub expires_at: Option<String>,
|
pub expires_at: Option<i64>,
|
||||||
/// Reference number required for the transaction
|
/// Reference number required for the transaction
|
||||||
pub reference: String,
|
pub reference: String,
|
||||||
/// Url to download the payment instruction
|
/// Url to download the payment instruction
|
||||||
@ -2087,8 +2087,8 @@ pub struct MultibancoTransferInstructions {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||||
pub struct DokuBankTransferInstructions {
|
pub struct DokuBankTransferInstructions {
|
||||||
#[schema(value_type = String, example = "2023-07-26T17:33:00-07-21")]
|
#[schema(value_type = String, example = "1707091200000")]
|
||||||
pub expires_at: Option<String>,
|
pub expires_at: Option<i64>,
|
||||||
#[schema(value_type = String, example = "122385736258")]
|
#[schema(value_type = String, example = "122385736258")]
|
||||||
pub reference: Secret<String>,
|
pub reference: Secret<String>,
|
||||||
#[schema(value_type = String)]
|
#[schema(value_type = String)]
|
||||||
|
|||||||
@ -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 an
|
/// Use the UNIX timestamp when serializing and deserializing an
|
||||||
|
|||||||
@ -370,7 +370,12 @@ pub struct AdyenPtsAction {
|
|||||||
reference: String,
|
reference: String,
|
||||||
download_url: Option<Url>,
|
download_url: Option<Url>,
|
||||||
payment_method_type: PaymentType,
|
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>,
|
initial_amount: Option<Amount>,
|
||||||
pass_creation_token: Option<String>,
|
pass_creation_token: Option<String>,
|
||||||
total_amount: Option<Amount>,
|
total_amount: Option<Amount>,
|
||||||
@ -3434,6 +3439,10 @@ pub fn get_present_to_shopper_metadata(
|
|||||||
response: &PresentToShopperResponse,
|
response: &PresentToShopperResponse,
|
||||||
) -> errors::CustomResult<Option<serde_json::Value>, errors::ConnectorError> {
|
) -> errors::CustomResult<Option<serde_json::Value>, errors::ConnectorError> {
|
||||||
let reference = response.action.reference.clone();
|
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 {
|
match response.action.payment_method_type {
|
||||||
PaymentType::Alfamart
|
PaymentType::Alfamart
|
||||||
@ -3446,7 +3455,7 @@ pub fn get_present_to_shopper_metadata(
|
|||||||
| PaymentType::Seicomart
|
| PaymentType::Seicomart
|
||||||
| PaymentType::PayEasy => {
|
| PaymentType::PayEasy => {
|
||||||
let voucher_data = payments::VoucherNextStepData {
|
let voucher_data = payments::VoucherNextStepData {
|
||||||
expires_at: response.action.expires_at.clone(),
|
expires_at,
|
||||||
reference,
|
reference,
|
||||||
download_url: response.action.download_url.clone(),
|
download_url: response.action.download_url.clone(),
|
||||||
instructions_url: response.action.instructions_url.clone(),
|
instructions_url: response.action.instructions_url.clone(),
|
||||||
@ -3470,7 +3479,7 @@ pub fn get_present_to_shopper_metadata(
|
|||||||
Box::new(payments::DokuBankTransferInstructions {
|
Box::new(payments::DokuBankTransferInstructions {
|
||||||
reference: Secret::new(response.action.reference.clone()),
|
reference: Secret::new(response.action.reference.clone()),
|
||||||
instructions_url: response.action.instructions_url.clone(),
|
instructions_url: response.action.instructions_url.clone(),
|
||||||
expires_at: response.action.expires_at.clone(),
|
expires_at,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -7738,7 +7738,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"expires_at": {
|
"expires_at": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "2023-07-26T17:33:00-07-21"
|
"example": "1707091200000"
|
||||||
},
|
},
|
||||||
"reference": {
|
"reference": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|||||||
Reference in New Issue
Block a user