mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
refactor(router): make compatibility module, types and utilities public (#197)
This commit is contained in:
@ -1,2 +1,2 @@
|
||||
pub(crate) mod stripe;
|
||||
pub(crate) mod wrap;
|
||||
pub mod stripe;
|
||||
pub mod wrap;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
mod app;
|
||||
mod customers;
|
||||
mod payment_intents;
|
||||
mod refunds;
|
||||
mod setup_intents;
|
||||
pub mod app;
|
||||
pub mod customers;
|
||||
pub mod payment_intents;
|
||||
pub mod refunds;
|
||||
pub mod setup_intents;
|
||||
use actix_web::{web, Scope};
|
||||
mod errors;
|
||||
pub mod errors;
|
||||
|
||||
use crate::routes;
|
||||
pub struct StripeApis;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod types;
|
||||
pub mod types;
|
||||
|
||||
use actix_web::{delete, get, post, web, HttpRequest, HttpResponse};
|
||||
use error_stack::report;
|
||||
|
||||
@ -6,53 +6,53 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::{pii, types::api};
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub(crate) struct CustomerAddress {
|
||||
pub(crate) city: Option<String>,
|
||||
pub(crate) country: Option<String>,
|
||||
pub(crate) line1: Option<String>,
|
||||
pub(crate) line2: Option<String>,
|
||||
pub(crate) postal_code: Option<String>,
|
||||
pub(crate) state: Option<String>,
|
||||
pub struct CustomerAddress {
|
||||
pub city: Option<pii::Secret<String>>,
|
||||
pub country: Option<pii::Secret<String>>,
|
||||
pub line1: Option<pii::Secret<String>>,
|
||||
pub line2: Option<pii::Secret<String>>,
|
||||
pub postal_code: Option<pii::Secret<String>>,
|
||||
pub state: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub(crate) struct CreateCustomerRequest {
|
||||
pub(crate) email: Option<masking::Secret<String, pii::Email>>,
|
||||
pub(crate) invoice_prefix: Option<String>,
|
||||
pub(crate) name: Option<String>,
|
||||
pub(crate) phone: Option<masking::Secret<String, masking::WithType>>,
|
||||
pub(crate) address: Option<CustomerAddress>,
|
||||
pub struct CreateCustomerRequest {
|
||||
pub email: Option<masking::Secret<String, pii::Email>>,
|
||||
pub invoice_prefix: Option<String>,
|
||||
pub name: Option<String>,
|
||||
pub phone: Option<masking::Secret<String>>,
|
||||
pub address: Option<CustomerAddress>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub(crate) struct CustomerUpdateRequest {
|
||||
pub(crate) metadata: Option<String>,
|
||||
pub(crate) description: Option<String>,
|
||||
pub(crate) email: Option<masking::Secret<String, pii::Email>>,
|
||||
pub(crate) phone: Option<masking::Secret<String, masking::WithType>>,
|
||||
pub(crate) name: Option<String>,
|
||||
pub(crate) address: Option<CustomerAddress>,
|
||||
pub struct CustomerUpdateRequest {
|
||||
pub metadata: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub email: Option<masking::Secret<String, pii::Email>>,
|
||||
pub phone: Option<masking::Secret<String, masking::WithType>>,
|
||||
pub name: Option<String>,
|
||||
pub address: Option<CustomerAddress>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq)]
|
||||
pub(crate) struct CreateCustomerResponse {
|
||||
id: String,
|
||||
object: String,
|
||||
created: u64,
|
||||
description: Option<String>,
|
||||
email: Option<masking::Secret<String, pii::Email>>,
|
||||
metadata: Option<serde_json::Value>,
|
||||
name: Option<String>,
|
||||
phone: Option<masking::Secret<String, masking::WithType>>,
|
||||
pub struct CreateCustomerResponse {
|
||||
pub id: String,
|
||||
pub object: String,
|
||||
pub created: u64,
|
||||
pub description: Option<String>,
|
||||
pub email: Option<masking::Secret<String, pii::Email>>,
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
pub name: Option<String>,
|
||||
pub phone: Option<masking::Secret<String, masking::WithType>>,
|
||||
}
|
||||
|
||||
pub(crate) type CustomerRetrieveResponse = CreateCustomerResponse;
|
||||
pub(crate) type CustomerUpdateResponse = CreateCustomerResponse;
|
||||
pub type CustomerRetrieveResponse = CreateCustomerResponse;
|
||||
pub type CustomerUpdateResponse = CreateCustomerResponse;
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq)]
|
||||
pub(crate) struct CustomerDeleteResponse {
|
||||
pub(crate) id: String,
|
||||
pub(crate) deleted: bool,
|
||||
pub struct CustomerDeleteResponse {
|
||||
pub id: String,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
impl From<CreateCustomerRequest> for api::CustomerRequest {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod types;
|
||||
pub mod types;
|
||||
|
||||
use actix_web::{get, post, web, HttpRequest, HttpResponse};
|
||||
use api_models::payments as payment_types;
|
||||
|
||||
@ -2,14 +2,18 @@ use api_models::{payments, refunds};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{core::errors, types::api::enums as api_enums};
|
||||
use crate::{
|
||||
core::errors,
|
||||
pii::{self, PeekInterface},
|
||||
types::api::enums as api_enums,
|
||||
};
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripeBillingDetails {
|
||||
pub(crate) address: Option<payments::AddressDetails>,
|
||||
pub(crate) email: Option<String>,
|
||||
pub(crate) name: Option<String>,
|
||||
pub(crate) phone: Option<String>,
|
||||
pub struct StripeBillingDetails {
|
||||
pub address: Option<payments::AddressDetails>,
|
||||
pub email: Option<pii::Secret<String, pii::Email>>,
|
||||
pub name: Option<String>,
|
||||
pub phone: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
impl From<StripeBillingDetails> for payments::Address {
|
||||
@ -17,7 +21,7 @@ impl From<StripeBillingDetails> for payments::Address {
|
||||
Self {
|
||||
address: details.address,
|
||||
phone: Some(payments::PhoneDetails {
|
||||
number: details.phone.map(masking::Secret::new),
|
||||
number: details.phone,
|
||||
country_code: None,
|
||||
}),
|
||||
}
|
||||
@ -25,16 +29,16 @@ impl From<StripeBillingDetails> for payments::Address {
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripeCard {
|
||||
pub(crate) number: String,
|
||||
pub(crate) exp_month: String,
|
||||
pub(crate) exp_year: String,
|
||||
pub(crate) cvc: String,
|
||||
pub struct StripeCard {
|
||||
pub number: pii::Secret<String, pii::CardNumber>,
|
||||
pub exp_month: pii::Secret<String>,
|
||||
pub exp_year: pii::Secret<String>,
|
||||
pub cvc: pii::Secret<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum StripePaymentMethodType {
|
||||
pub enum StripePaymentMethodType {
|
||||
#[default]
|
||||
Card,
|
||||
}
|
||||
@ -47,18 +51,18 @@ impl From<StripePaymentMethodType> for api_enums::PaymentMethodType {
|
||||
}
|
||||
}
|
||||
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripePaymentMethodData {
|
||||
pub struct StripePaymentMethodData {
|
||||
#[serde(rename = "type")]
|
||||
pub(crate) stype: StripePaymentMethodType,
|
||||
pub(crate) billing_details: Option<StripeBillingDetails>,
|
||||
pub stype: StripePaymentMethodType,
|
||||
pub billing_details: Option<StripeBillingDetails>,
|
||||
#[serde(flatten)]
|
||||
pub(crate) payment_method_details: Option<StripePaymentMethodDetails>, // enum
|
||||
pub(crate) metadata: Option<Value>,
|
||||
pub payment_method_details: Option<StripePaymentMethodDetails>, // enum
|
||||
pub metadata: Option<Value>,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum StripePaymentMethodDetails {
|
||||
pub enum StripePaymentMethodDetails {
|
||||
Card(StripeCard),
|
||||
#[default]
|
||||
BankTransfer,
|
||||
@ -67,11 +71,11 @@ pub(crate) enum StripePaymentMethodDetails {
|
||||
impl From<StripeCard> for payments::CCard {
|
||||
fn from(card: StripeCard) -> Self {
|
||||
Self {
|
||||
card_number: masking::Secret::new(card.number),
|
||||
card_exp_month: masking::Secret::new(card.exp_month),
|
||||
card_exp_year: masking::Secret::new(card.exp_year),
|
||||
card_number: card.number,
|
||||
card_exp_month: card.exp_month,
|
||||
card_exp_year: card.exp_year,
|
||||
card_holder_name: masking::Secret::new("stripe_cust".to_owned()),
|
||||
card_cvc: masking::Secret::new(card.cvc),
|
||||
card_cvc: card.cvc,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,12 +89,12 @@ impl From<StripePaymentMethodDetails> for payments::PaymentMethod {
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct Shipping {
|
||||
pub(crate) address: Option<payments::AddressDetails>,
|
||||
pub(crate) name: Option<String>,
|
||||
pub(crate) carrier: Option<String>,
|
||||
pub(crate) phone: Option<String>,
|
||||
pub(crate) tracking_number: Option<String>,
|
||||
pub struct Shipping {
|
||||
pub address: Option<payments::AddressDetails>,
|
||||
pub name: Option<String>,
|
||||
pub carrier: Option<String>,
|
||||
pub phone: Option<pii::Secret<String>>,
|
||||
pub tracking_number: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
impl From<Shipping> for payments::Address {
|
||||
@ -98,33 +102,33 @@ impl From<Shipping> for payments::Address {
|
||||
Self {
|
||||
address: details.address,
|
||||
phone: Some(payments::PhoneDetails {
|
||||
number: details.phone.map(masking::Secret::new),
|
||||
number: details.phone,
|
||||
country_code: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripePaymentIntentRequest {
|
||||
pub(crate) amount: Option<i64>, //amount in cents, hence passed as integer
|
||||
pub(crate) connector: Option<api_enums::Connector>,
|
||||
pub(crate) currency: Option<String>,
|
||||
pub struct StripePaymentIntentRequest {
|
||||
pub amount: Option<i64>, //amount in cents, hence passed as integer
|
||||
pub connector: Option<api_enums::Connector>,
|
||||
pub currency: Option<String>,
|
||||
#[serde(rename = "amount_to_capture")]
|
||||
pub(crate) amount_capturable: Option<i64>,
|
||||
pub(crate) confirm: Option<bool>,
|
||||
pub(crate) capture_method: Option<api_enums::CaptureMethod>,
|
||||
pub(crate) customer: Option<String>,
|
||||
pub(crate) description: Option<String>,
|
||||
pub(crate) payment_method_data: Option<StripePaymentMethodData>,
|
||||
pub(crate) receipt_email: Option<String>,
|
||||
pub(crate) return_url: Option<String>,
|
||||
pub(crate) setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub(crate) shipping: Option<Shipping>,
|
||||
pub(crate) billing_details: Option<StripeBillingDetails>,
|
||||
pub(crate) statement_descriptor: Option<String>,
|
||||
pub(crate) statement_descriptor_suffix: Option<String>,
|
||||
pub(crate) metadata: Option<Value>,
|
||||
pub(crate) client_secret: Option<String>,
|
||||
pub amount_capturable: Option<i64>,
|
||||
pub confirm: Option<bool>,
|
||||
pub capture_method: Option<api_enums::CaptureMethod>,
|
||||
pub customer: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub payment_method_data: Option<StripePaymentMethodData>,
|
||||
pub receipt_email: Option<pii::Secret<String, pii::Email>>,
|
||||
pub return_url: Option<String>,
|
||||
pub setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub shipping: Option<Shipping>,
|
||||
pub billing_details: Option<StripeBillingDetails>,
|
||||
pub statement_descriptor: Option<String>,
|
||||
pub statement_descriptor_suffix: Option<String>,
|
||||
pub metadata: Option<Value>,
|
||||
pub client_secret: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
impl From<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
@ -137,15 +141,12 @@ impl From<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
amount_to_capture: item.amount_capturable,
|
||||
confirm: item.confirm,
|
||||
customer_id: item.customer,
|
||||
email: item.receipt_email.map(masking::Secret::new),
|
||||
email: item.receipt_email,
|
||||
name: item
|
||||
.billing_details
|
||||
.as_ref()
|
||||
.and_then(|b| b.name.as_ref().map(|x| masking::Secret::new(x.to_owned()))),
|
||||
phone: item
|
||||
.shipping
|
||||
.as_ref()
|
||||
.and_then(|s| s.phone.as_ref().map(|x| masking::Secret::new(x.to_owned()))),
|
||||
phone: item.shipping.as_ref().and_then(|s| s.phone.clone()),
|
||||
description: item.description,
|
||||
return_url: item.return_url,
|
||||
payment_method_data: item.payment_method_data.as_ref().and_then(|pmd| {
|
||||
@ -168,7 +169,7 @@ impl From<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
statement_descriptor_name: item.statement_descriptor,
|
||||
statement_descriptor_suffix: item.statement_descriptor_suffix,
|
||||
metadata: item.metadata,
|
||||
client_secret: item.client_secret,
|
||||
client_secret: item.client_secret.map(|s| s.peek().clone()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
@ -176,7 +177,7 @@ impl From<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
|
||||
#[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum StripePaymentStatus {
|
||||
pub enum StripePaymentStatus {
|
||||
Succeeded,
|
||||
Canceled,
|
||||
#[default]
|
||||
@ -205,7 +206,7 @@ impl From<api_enums::IntentStatus> for StripePaymentStatus {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum CancellationReason {
|
||||
pub enum CancellationReason {
|
||||
Duplicate,
|
||||
Fraudulent,
|
||||
RequestedByCustomer,
|
||||
@ -223,7 +224,7 @@ impl ToString for CancellationReason {
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Deserialize, Serialize, Copy, Clone)]
|
||||
pub(crate) struct StripePaymentCancelRequest {
|
||||
pub struct StripePaymentCancelRequest {
|
||||
cancellation_reason: Option<CancellationReason>,
|
||||
}
|
||||
|
||||
@ -237,25 +238,25 @@ impl From<StripePaymentCancelRequest> for payments::PaymentsCancelRequest {
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripeCaptureRequest {
|
||||
pub(crate) amount_to_capture: Option<i64>,
|
||||
pub struct StripeCaptureRequest {
|
||||
pub amount_to_capture: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Serialize)]
|
||||
pub(crate) struct StripePaymentIntentResponse {
|
||||
pub(crate) id: Option<String>,
|
||||
pub(crate) object: String,
|
||||
pub(crate) amount: i64,
|
||||
pub(crate) amount_received: Option<i64>,
|
||||
pub(crate) amount_capturable: Option<i64>,
|
||||
pub(crate) currency: String,
|
||||
pub(crate) status: StripePaymentStatus,
|
||||
pub(crate) client_secret: Option<masking::Secret<String>>,
|
||||
pub struct StripePaymentIntentResponse {
|
||||
pub id: Option<String>,
|
||||
pub object: String,
|
||||
pub amount: i64,
|
||||
pub amount_received: Option<i64>,
|
||||
pub amount_capturable: Option<i64>,
|
||||
pub currency: String,
|
||||
pub status: StripePaymentStatus,
|
||||
pub client_secret: Option<masking::Secret<String>>,
|
||||
#[serde(with = "common_utils::custom_serde::iso8601::option")]
|
||||
pub(crate) created: Option<time::PrimitiveDateTime>,
|
||||
pub(crate) customer: Option<String>,
|
||||
pub(crate) refunds: Option<Vec<refunds::RefundResponse>>,
|
||||
pub(crate) mandate_id: Option<String>,
|
||||
pub created: Option<time::PrimitiveDateTime>,
|
||||
pub customer: Option<String>,
|
||||
pub refunds: Option<Vec<refunds::RefundResponse>>,
|
||||
pub mandate_id: Option<String>,
|
||||
}
|
||||
|
||||
impl From<payments::PaymentsResponse> for StripePaymentIntentResponse {
|
||||
@ -334,11 +335,11 @@ fn from_timestamp_to_datetime(
|
||||
}
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Serialize)]
|
||||
pub(crate) struct StripePaymentIntentListResponse {
|
||||
pub(crate) object: String,
|
||||
pub(crate) url: String,
|
||||
pub(crate) has_more: bool,
|
||||
pub(crate) data: Vec<StripePaymentIntentResponse>,
|
||||
pub struct StripePaymentIntentListResponse {
|
||||
pub object: String,
|
||||
pub url: String,
|
||||
pub has_more: bool,
|
||||
pub data: Vec<StripePaymentIntentResponse>,
|
||||
}
|
||||
|
||||
impl From<payments::PaymentListResponse> for StripePaymentIntentListResponse {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod types;
|
||||
pub mod types;
|
||||
|
||||
use actix_web::{get, post, web, HttpRequest, HttpResponse};
|
||||
use router_env::{tracing, tracing::instrument};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mod types;
|
||||
pub mod types;
|
||||
|
||||
use actix_web::{get, post, web, HttpRequest, HttpResponse};
|
||||
use api_models::payments as payment_types;
|
||||
|
||||
@ -5,15 +5,16 @@ use serde_json::Value;
|
||||
|
||||
use crate::{
|
||||
core::errors,
|
||||
pii::{self, PeekInterface},
|
||||
types::api::{self as api_types, enums as api_enums},
|
||||
};
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripeBillingDetails {
|
||||
pub(crate) address: Option<payments::AddressDetails>,
|
||||
pub(crate) email: Option<String>,
|
||||
pub(crate) name: Option<String>,
|
||||
pub(crate) phone: Option<String>,
|
||||
pub struct StripeBillingDetails {
|
||||
pub address: Option<payments::AddressDetails>,
|
||||
pub email: Option<pii::Secret<String, pii::Email>>,
|
||||
pub name: Option<String>,
|
||||
pub phone: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
impl From<StripeBillingDetails> for payments::Address {
|
||||
@ -21,7 +22,7 @@ impl From<StripeBillingDetails> for payments::Address {
|
||||
Self {
|
||||
address: details.address,
|
||||
phone: Some(payments::PhoneDetails {
|
||||
number: details.phone.map(masking::Secret::new),
|
||||
number: details.phone,
|
||||
country_code: None,
|
||||
}),
|
||||
}
|
||||
@ -29,16 +30,16 @@ impl From<StripeBillingDetails> for payments::Address {
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripeCard {
|
||||
pub(crate) number: String,
|
||||
pub(crate) exp_month: String,
|
||||
pub(crate) exp_year: String,
|
||||
pub(crate) cvc: String,
|
||||
pub struct StripeCard {
|
||||
pub number: pii::Secret<String, pii::CardNumber>,
|
||||
pub exp_month: pii::Secret<String>,
|
||||
pub exp_year: pii::Secret<String>,
|
||||
pub cvc: pii::Secret<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum StripePaymentMethodType {
|
||||
pub enum StripePaymentMethodType {
|
||||
#[default]
|
||||
Card,
|
||||
}
|
||||
@ -51,18 +52,18 @@ impl From<StripePaymentMethodType> for api_enums::PaymentMethodType {
|
||||
}
|
||||
}
|
||||
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripePaymentMethodData {
|
||||
pub struct StripePaymentMethodData {
|
||||
#[serde(rename = "type")]
|
||||
pub(crate) stype: StripePaymentMethodType,
|
||||
pub(crate) billing_details: Option<StripeBillingDetails>,
|
||||
pub stype: StripePaymentMethodType,
|
||||
pub billing_details: Option<StripeBillingDetails>,
|
||||
#[serde(flatten)]
|
||||
pub(crate) payment_method_details: Option<StripePaymentMethodDetails>, // enum
|
||||
pub(crate) metadata: Option<Value>,
|
||||
pub payment_method_details: Option<StripePaymentMethodDetails>, // enum
|
||||
pub metadata: Option<Value>,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum StripePaymentMethodDetails {
|
||||
pub enum StripePaymentMethodDetails {
|
||||
Card(StripeCard),
|
||||
#[default]
|
||||
BankTransfer,
|
||||
@ -71,11 +72,11 @@ pub(crate) enum StripePaymentMethodDetails {
|
||||
impl From<StripeCard> for payments::CCard {
|
||||
fn from(card: StripeCard) -> Self {
|
||||
Self {
|
||||
card_number: masking::Secret::new(card.number),
|
||||
card_exp_month: masking::Secret::new(card.exp_month),
|
||||
card_exp_year: masking::Secret::new(card.exp_year),
|
||||
card_number: card.number,
|
||||
card_exp_month: card.exp_month,
|
||||
card_exp_year: card.exp_year,
|
||||
card_holder_name: masking::Secret::new("stripe_cust".to_owned()),
|
||||
card_cvc: masking::Secret::new(card.cvc),
|
||||
card_cvc: card.cvc,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,12 +90,12 @@ impl From<StripePaymentMethodDetails> for payments::PaymentMethod {
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct Shipping {
|
||||
pub(crate) address: Option<payments::AddressDetails>,
|
||||
pub(crate) name: Option<String>,
|
||||
pub(crate) carrier: Option<String>,
|
||||
pub(crate) phone: Option<String>,
|
||||
pub(crate) tracking_number: Option<String>,
|
||||
pub struct Shipping {
|
||||
pub address: Option<payments::AddressDetails>,
|
||||
pub name: Option<String>,
|
||||
pub carrier: Option<String>,
|
||||
pub phone: Option<pii::Secret<String>>,
|
||||
pub tracking_number: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
impl From<Shipping> for payments::Address {
|
||||
@ -102,27 +103,27 @@ impl From<Shipping> for payments::Address {
|
||||
Self {
|
||||
address: details.address,
|
||||
phone: Some(payments::PhoneDetails {
|
||||
number: details.phone.map(masking::Secret::new),
|
||||
number: details.phone,
|
||||
country_code: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
|
||||
pub(crate) struct StripeSetupIntentRequest {
|
||||
pub(crate) confirm: Option<bool>,
|
||||
pub(crate) customer: Option<String>,
|
||||
pub(crate) description: Option<String>,
|
||||
pub(crate) payment_method_data: Option<StripePaymentMethodData>,
|
||||
pub(crate) receipt_email: Option<String>,
|
||||
pub(crate) return_url: Option<String>,
|
||||
pub(crate) setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub(crate) shipping: Option<Shipping>,
|
||||
pub(crate) billing_details: Option<StripeBillingDetails>,
|
||||
pub(crate) statement_descriptor: Option<String>,
|
||||
pub(crate) statement_descriptor_suffix: Option<String>,
|
||||
pub(crate) metadata: Option<Value>,
|
||||
pub(crate) client_secret: Option<String>,
|
||||
pub struct StripeSetupIntentRequest {
|
||||
pub confirm: Option<bool>,
|
||||
pub customer: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub payment_method_data: Option<StripePaymentMethodData>,
|
||||
pub receipt_email: Option<pii::Secret<String, pii::Email>>,
|
||||
pub return_url: Option<String>,
|
||||
pub setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub shipping: Option<Shipping>,
|
||||
pub billing_details: Option<StripeBillingDetails>,
|
||||
pub statement_descriptor: Option<String>,
|
||||
pub statement_descriptor_suffix: Option<String>,
|
||||
pub metadata: Option<Value>,
|
||||
pub client_secret: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
impl From<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
||||
@ -134,15 +135,12 @@ impl From<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
||||
amount_to_capture: None,
|
||||
confirm: item.confirm,
|
||||
customer_id: item.customer,
|
||||
email: item.receipt_email.map(masking::Secret::new),
|
||||
email: item.receipt_email,
|
||||
name: item
|
||||
.billing_details
|
||||
.as_ref()
|
||||
.and_then(|b| b.name.as_ref().map(|x| masking::Secret::new(x.to_owned()))),
|
||||
phone: item
|
||||
.shipping
|
||||
.as_ref()
|
||||
.and_then(|s| s.phone.as_ref().map(|x| masking::Secret::new(x.to_owned()))),
|
||||
phone: item.shipping.as_ref().and_then(|s| s.phone.clone()),
|
||||
description: item.description,
|
||||
return_url: item.return_url,
|
||||
payment_method_data: item.payment_method_data.as_ref().and_then(|pmd| {
|
||||
@ -165,7 +163,7 @@ impl From<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
||||
statement_descriptor_name: item.statement_descriptor,
|
||||
statement_descriptor_suffix: item.statement_descriptor_suffix,
|
||||
metadata: item.metadata,
|
||||
client_secret: item.client_secret,
|
||||
client_secret: item.client_secret.map(|s| s.peek().clone()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
@ -173,7 +171,7 @@ impl From<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
||||
|
||||
#[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum StripeSetupStatus {
|
||||
pub enum StripeSetupStatus {
|
||||
Succeeded,
|
||||
Canceled,
|
||||
#[default]
|
||||
@ -204,7 +202,7 @@ impl From<api_enums::IntentStatus> for StripeSetupStatus {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum CancellationReason {
|
||||
pub enum CancellationReason {
|
||||
Duplicate,
|
||||
Fraudulent,
|
||||
RequestedByCustomer,
|
||||
@ -223,7 +221,7 @@ impl ToString for CancellationReason {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Copy, Clone)]
|
||||
pub(crate) struct StripePaymentCancelRequest {
|
||||
pub struct StripePaymentCancelRequest {
|
||||
cancellation_reason: Option<CancellationReason>,
|
||||
}
|
||||
|
||||
@ -236,16 +234,16 @@ impl From<StripePaymentCancelRequest> for payments::PaymentsCancelRequest {
|
||||
}
|
||||
}
|
||||
#[derive(Default, Eq, PartialEq, Serialize)]
|
||||
pub(crate) struct StripeSetupIntentResponse {
|
||||
pub(crate) id: Option<String>,
|
||||
pub(crate) object: String,
|
||||
pub(crate) status: StripeSetupStatus,
|
||||
pub(crate) client_secret: Option<masking::Secret<String>>,
|
||||
pub struct StripeSetupIntentResponse {
|
||||
pub id: Option<String>,
|
||||
pub object: String,
|
||||
pub status: StripeSetupStatus,
|
||||
pub client_secret: Option<masking::Secret<String>>,
|
||||
#[serde(with = "common_utils::custom_serde::iso8601::option")]
|
||||
pub(crate) created: Option<time::PrimitiveDateTime>,
|
||||
pub(crate) customer: Option<String>,
|
||||
pub(crate) refunds: Option<Vec<refunds::RefundResponse>>,
|
||||
pub(crate) mandate_id: Option<String>,
|
||||
pub created: Option<time::PrimitiveDateTime>,
|
||||
pub customer: Option<String>,
|
||||
pub refunds: Option<Vec<refunds::RefundResponse>>,
|
||||
pub mandate_id: Option<String>,
|
||||
}
|
||||
|
||||
impl From<payments::PaymentsResponse> for StripeSetupIntentResponse {
|
||||
|
||||
Reference in New Issue
Block a user