refactor: add payment_issuer and payment_experience in pa (#491)

This commit is contained in:
Narayan Bhat
2023-02-19 19:29:22 +05:30
committed by GitHub
parent c47619b5ea
commit 66563595df
54 changed files with 790 additions and 801 deletions

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use super::payments::AddressDetails;
use crate::{enums as api_enums, payment_methods};
use crate::enums as api_enums;
#[derive(Clone, Debug, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]
@ -325,7 +325,7 @@ pub struct PaymentMethods {
pub installment_payment_enabled: bool,
/// Type of payment experience enabled with the connector
#[schema(value_type = Option<Vec<PaymentExperience>>,example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<payment_methods::PaymentExperience>>,
pub payment_experience: Option<Vec<api_enums::PaymentExperience>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]

View File

@ -343,6 +343,66 @@ pub enum PaymentMethodIssuerCode {
JpBacs,
}
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
frunk::LabelledGeneric,
ToSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum PaymentIssuer {
Klarna,
Affirm,
AfterpayClearpay,
AmericanExpress,
BankOfAmerica,
Barclays,
CapitalOne,
Chase,
Citi,
Discover,
NavyFederalCreditUnion,
PentagonFederalCreditUnion,
SynchronyBank,
WellsFargo,
}
#[derive(
Eq,
PartialEq,
Hash,
Copy,
Clone,
Debug,
serde::Serialize,
serde::Deserialize,
ToSchema,
Default,
frunk::LabelledGeneric,
)]
#[serde(rename_all = "snake_case")]
pub enum PaymentExperience {
/// The URL to which the customer needs to be redirected for completing the payment.
#[default]
RedirectToUrl,
/// Contains the data for invoking the sdk client for completing the payment.
InvokeSdkClient,
/// The QR code data to be displayed to the customer.
DisplayQrCode,
/// Contains data to finish one click payment.
OneClick,
/// Redirect customer to link wallet
LinkWallet,
/// Contains the data for invoking the sdk client for completing the payment.
InvokePaymentApp,
}
#[derive(
Clone,
Copy,

View File

@ -122,7 +122,7 @@ pub struct PaymentMethodResponse {
/// Type of payment experience enabled with the connector
#[schema(value_type = Option<Vec<PaymentExperience>>,example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<PaymentExperience>>,
pub payment_experience: Option<Vec<api_enums::PaymentExperience>>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
@ -348,8 +348,8 @@ pub struct ListPaymentMethod {
pub installment_payment_enabled: bool,
/// Type of payment experience enabled with the connector
#[schema(example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<PaymentExperience>>,
#[schema(value_type = Option<Vec<PaymentExperience>>, example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<api_enums::PaymentExperience>>,
}
/// We need a custom serializer to only send relevant fields in ListPaymentMethodResponse
@ -447,7 +447,7 @@ pub struct CustomerPaymentMethod {
/// Type of payment experience enabled with the connector
#[schema(value_type = Option<Vec<PaymentExperience>>,example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<PaymentExperience>>,
pub payment_experience: Option<Vec<api_enums::PaymentExperience>>,
/// Card details from card locker
#[schema(example = json!({"last4": "1142","exp_month": "03","exp_year": "2030"}))]
@ -462,26 +462,6 @@ pub struct CustomerPaymentMethod {
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
}
#[derive(Eq, PartialEq, Hash, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PaymentExperience {
/// The URL to which the customer needs to be redirected for completing the payment.The URL to
/// which the customer needs to be redirected for completing the payment.
RedirectToUrl,
/// Contains the data for invoking the sdk client for completing the payment.
InvokeSdkClient,
/// The QR code data to be displayed to the customer.
DisplayQrCode,
/// Contains data to finish one click payment.
OneClick,
/// Redirect customer to link wallet
LinkWallet,
/// Contains the data for invoking the sdk client for completing the payment.
InvokePaymentApp,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct PaymentMethodId {
pub payment_method_id: String,

View File

@ -132,6 +132,12 @@ pub struct PaymentsRequest {
"java_script_enabled":true
}"#)]
pub browser_info: Option<serde_json::Value>,
/// Payment Issuser for the current payment
#[schema(value_type = Option<PaymentIssuer>, example = "klarna")]
pub payment_issuer: Option<api_enums::PaymentIssuer>,
/// Payment Experience, works in tandem with payment_issuer
#[schema(value_type = Option<PaymentExperience>, example = "redirect_to_url")]
pub payment_experience: Option<api_enums::PaymentExperience>,
}
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq, Eq)]
@ -342,35 +348,27 @@ pub enum AfterpayClearpayIssuer {
pub enum PayLaterData {
/// For KlarnaRedirect as PayLater Option
KlarnaRedirect {
/// The issuer name of the redirect
issuer_name: KlarnaIssuer,
/// The billing email
billing_email: String,
#[schema(value_type = String)]
billing_email: Secret<String, pii::Email>,
// The billing country code
billing_country: String,
},
/// For Klarna Sdk as PayLater Option
KlarnaSdk {
/// The issuer name of the sdk
issuer_name: KlarnaIssuer,
/// The token for the sdk workflow
token: String,
},
/// For Affirm redirect as PayLater Option
AffirmRedirect {
/// The issuer name of affirm redirect issuer
issuer_name: AffirmIssuer,
/// The billing email
billing_email: String,
},
AffirmRedirect {},
/// For AfterpayClearpay redirect as PayLater Option
AfterpayClearpayRedirect {
/// The issuer name of afterpayclearpay redirect issuer
issuer_name: AfterpayClearpayIssuer,
/// The billing email
billing_email: String,
#[schema(value_type = String)]
billing_email: Secret<String, pii::Email>,
/// The billing name
billing_name: String,
#[schema(value_type = String)]
billing_name: Secret<String>,
},
}