feat(session_token): serialize with camelCase for gpay token (#324)

This commit is contained in:
Narayan Bhat
2023-01-09 16:56:48 +05:30
committed by GitHub
parent 8cffdc96ca
commit a3f52bb456
2 changed files with 11 additions and 2 deletions

View File

@ -778,18 +778,21 @@ pub struct PaymentsSessionRequest {
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GpayAllowedMethodsParameters { pub struct GpayAllowedMethodsParameters {
pub allowed_auth_methods: Vec<String>, pub allowed_auth_methods: Vec<String>,
pub allowed_card_networks: Vec<String>, pub allowed_card_networks: Vec<String>,
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GpayTokenParameters { pub struct GpayTokenParameters {
pub gateway: String, pub gateway: String,
pub gateway_merchant_id: String, pub gateway_merchant_id: String,
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GpayTokenizationSpecification { pub struct GpayTokenizationSpecification {
#[serde(rename = "type")] #[serde(rename = "type")]
pub token_specification_type: String, pub token_specification_type: String,
@ -797,6 +800,7 @@ pub struct GpayTokenizationSpecification {
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GpayAllowedPaymentMethods { pub struct GpayAllowedPaymentMethods {
#[serde(rename = "type")] #[serde(rename = "type")]
pub payment_method_type: String, pub payment_method_type: String,
@ -805,6 +809,7 @@ pub struct GpayAllowedPaymentMethods {
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GpayTransactionInfo { pub struct GpayTransactionInfo {
pub country_code: String, pub country_code: String,
pub currency_code: String, pub currency_code: String,
@ -813,11 +818,13 @@ pub struct GpayTransactionInfo {
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GpayMerchantInfo { pub struct GpayMerchantInfo {
pub merchant_name: String, pub merchant_name: String,
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GpayMetadata { pub struct GpayMetadata {
pub merchant_info: GpayMerchantInfo, pub merchant_info: GpayMerchantInfo,
pub allowed_payment_methods: Vec<GpayAllowedPaymentMethods>, pub allowed_payment_methods: Vec<GpayAllowedPaymentMethods>,
@ -833,7 +840,9 @@ pub struct GpaySessionTokenData {
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum SessionToken { pub enum SessionToken {
Gpay { Gpay {
allowed_payment_methods: Vec<GpayAllowedPaymentMethods>, #[serde(flatten)]
gpay_token: GpayMetadata,
#[serde(rename(serialize = "transactionInfo"))]
transaction_info: GpayTransactionInfo, transaction_info: GpayTransactionInfo,
}, },
Klarna { Klarna {

View File

@ -84,7 +84,7 @@ fn create_gpay_session_token(
let response_router_data = types::PaymentsSessionRouterData { let response_router_data = types::PaymentsSessionRouterData {
response: Ok(types::PaymentsResponseData::SessionResponse { response: Ok(types::PaymentsResponseData::SessionResponse {
session_token: payment_types::SessionToken::Gpay { session_token: payment_types::SessionToken::Gpay {
allowed_payment_methods: gpay_data.gpay.allowed_payment_methods, gpay_token: gpay_data.gpay,
transaction_info, transaction_info,
}, },
}), }),