doc: update openapi (#453)

Co-authored-by: Sangamesh <sangamesh.kulkarni@juspay.in>
Co-authored-by: dracarys18 <karthikey.hegde@juspay.in>
Co-authored-by: bernard eugine <bernard.eugine@bernard.eugine-MacBookPro>
Co-authored-by: Abhishek Marrivagu <abhi.codes10@gmail.com>
This commit is contained in:
bernard-eugine
2023-01-30 16:56:37 +05:30
committed by GitHub
parent d3ef24e8e9
commit ec2f4ba257
40 changed files with 3314 additions and 283 deletions

View File

@ -211,7 +211,7 @@ pub struct WebhookDetails {
}
#[derive(Debug, Serialize, ToSchema)]
pub struct DeleteResponse {
pub struct DeleteMerchantAccountResponse {
/// The identifier for the Merchant Account
#[schema(max_length = 255, example = "y3oqhf46pyzuxjbcn2giaqnb44")]
pub merchant_id: String,

View File

@ -326,6 +326,7 @@ pub enum FutureUsage {
strum::Display,
strum::EnumString,
frunk::LabelledGeneric,
ToSchema,
)]
#[strum(serialize_all = "snake_case")]
#[serde(rename_all = "snake_case")]
@ -467,6 +468,7 @@ pub enum RoutingAlgorithm {
Custom,
}
/// The status of the mandate, which indicates whether it can be used to initiate a payment
#[derive(
Clone,
Copy,
@ -479,6 +481,7 @@ pub enum RoutingAlgorithm {
strum::Display,
strum::EnumString,
frunk::LabelledGeneric,
ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]

View File

@ -1,5 +1,6 @@
use masking::Secret;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::{enums as api_enums, payments};
@ -8,30 +9,54 @@ pub struct MandateId {
pub mandate_id: String,
}
#[derive(Default, Debug, Deserialize, Serialize)]
#[derive(Default, Debug, Deserialize, Serialize, ToSchema)]
pub struct MandateRevokedResponse {
/// The identifier for mandate
pub mandate_id: String,
/// The status for mandates
#[schema(value_type = MandateStatus)]
pub status: api_enums::MandateStatus,
}
#[derive(Default, Debug, Deserialize, Serialize)]
#[derive(Default, Debug, Deserialize, Serialize, ToSchema)]
pub struct MandateResponse {
/// The identifier for mandate
pub mandate_id: String,
/// The status for mandates
#[schema(value_type = MandateStatus)]
pub status: api_enums::MandateStatus,
/// The identifier for payment method
pub payment_method_id: String,
/// The payment method
pub payment_method: String,
/// The card details for mandate
pub card: Option<MandateCardDetails>,
/// Details about the customers acceptance
#[schema(value_type = Option<CustomerAcceptance>)]
pub customer_acceptance: Option<payments::CustomerAcceptance>,
}
#[derive(Default, Debug, Deserialize, Serialize)]
#[derive(Default, Debug, Deserialize, Serialize, ToSchema)]
pub struct MandateCardDetails {
/// The last 4 digits of card
pub last4_digits: Option<String>,
/// The expiry month of card
#[schema(value_type = Option<String>)]
pub card_exp_month: Option<Secret<String>>,
/// The expiry year of card
#[schema(value_type = Option<String>)]
pub card_exp_year: Option<Secret<String>>,
/// The card holder name
#[schema(value_type = Option<String>)]
pub card_holder_name: Option<Secret<String>>,
/// The token from card locker
#[schema(value_type = Option<String>)]
pub card_token: Option<Secret<String>>,
/// The card scheme network for the particular card
pub scheme: Option<String>,
/// The country code in in which the card was issued
pub issuer_country: Option<String>,
#[schema(value_type = Option<String>)]
/// A unique identifier alias to identify a particular card
pub card_fingerprint: Option<Secret<String>>,
}

View File

@ -6,76 +6,185 @@ use utoipa::ToSchema;
use crate::enums as api_enums;
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CreatePaymentMethod {
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethodType,example = "card")]
pub payment_method: api_enums::PaymentMethodType,
/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodSubType>,example = "credit_card")]
pub payment_method_type: Option<api_enums::PaymentMethodSubType>,
/// The name of the bank/ provider issuing the payment method to the end user
#[schema(example = "Citibank")]
pub payment_method_issuer: Option<String>,
/// A standard code representing the issuer of payment method
#[schema(value_type = Option<PaymentMethodIssuerCode>,example = "jp_applepay")]
pub payment_method_issuer_code: Option<api_enums::PaymentMethodIssuerCode>,
/// Card Details
#[schema(example = json!({
"card_number": "4111111145551142",
"card_exp_month": "10",
"card_exp_year": "25",
"card_holder_name": "John Doe"}))]
pub card: Option<CardDetail>,
/// 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" }))]
pub metadata: Option<serde_json::Value>,
/// The unique identifier of the customer.
#[schema(example = "cus_meowerunwiuwiwqw")]
pub customer_id: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct UpdatePaymentMethod {
/// Card Details
#[schema(example = json!({
"card_number": "4111111145551142",
"card_exp_month": "10",
"card_exp_year": "25",
"card_holder_name": "John Doe"}))]
pub card: Option<CardDetail>,
// Add more payment method update field in future
/// 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" }))]
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetail {
/// Card Number
#[schema(value_type = String,example = "4111111145551142")]
pub card_number: masking::Secret<String, pii::CardNumber>,
/// Card Expiry Month
#[schema(value_type = String,example = "10")]
pub card_exp_month: masking::Secret<String>,
/// Card Expiry Year
#[schema(value_type = String,example = "25")]
pub card_exp_year: masking::Secret<String>,
/// Card Holder Name
#[schema(value_type = String,example = "John Doe")]
pub card_holder_name: Option<masking::Secret<String>>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct PaymentMethodResponse {
/// Unique identifier for a merchant
#[schema(example = "merchant_1671528864")]
pub merchant_id: String,
/// The unique identifier of the customer.
#[schema(example = "cus_meowerunwiuwiwqw")]
pub customer_id: Option<String>,
/// The unique identifier of the Payment method
#[schema(example = "card_rGK4Vi5iSW70MY7J2mIy")]
pub payment_method_id: String,
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethodType,example = "card")]
pub payment_method: api_enums::PaymentMethodType,
/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodSubType>,example = "credit_card")]
pub payment_method_type: Option<api_enums::PaymentMethodSubType>,
/// The name of the bank/ provider issuing the payment method to the end user
#[schema(example = "Citibank")]
pub payment_method_issuer: Option<String>,
/// A standard code representing the issuer of payment method
#[schema(value_type = Option<PaymentMethodIssuerCode>,example = "jp_applepay")]
pub payment_method_issuer_code: Option<api_enums::PaymentMethodIssuerCode>,
/// Card details from card locker
#[schema(example = json!({"last4": "1142","exp_month": "03","exp_year": "2030"}))]
pub card: Option<CardDetailFromLocker>,
/// Indicates whether the payment method is eligible for recurring payments
#[schema(example = true)]
pub recurring_enabled: bool,
/// Indicates whether the payment method is eligible for installment payments
#[schema(example = true)]
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<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" }))]
pub metadata: Option<serde_json::Value>,
/// A timestamp (ISO 8601 code) that determines when the customer was created
#[schema(value_type = Option<PrimitiveDateTime>,example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct CardDetailFromLocker {
pub scheme: Option<String>,
pub issuer_country: Option<String>,
pub last4_digits: Option<String>,
#[serde(skip)]
#[schema(value_type=Option<String>)]
pub card_number: Option<masking::Secret<String, pii::CardNumber>>,
#[schema(value_type=Option<String>)]
pub expiry_month: Option<masking::Secret<String>>,
#[schema(value_type=Option<String>)]
pub expiry_year: Option<masking::Secret<String>>,
#[schema(value_type=Option<String>)]
pub card_token: Option<masking::Secret<String>>,
#[schema(value_type=Option<String>)]
pub card_holder_name: Option<masking::Secret<String>>,
#[schema(value_type=Option<String>)]
pub card_fingerprint: Option<masking::Secret<String>>,
}
//List Payment Method
#[derive(Debug, serde::Serialize, Default)]
#[derive(Debug, serde::Serialize, Default, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct ListPaymentMethodRequest {
/// This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK
#[schema(max_length = 30, min_length = 30, example = "secret_k2uj3he2893ein2d")]
pub client_secret: Option<String>,
/// The two-letter ISO currency code
#[schema(example = json!(["US", "UK", "IN"]))]
pub accepted_countries: Option<Vec<String>>,
/// The three-letter ISO currency code
#[schema(value_type = Option<Vec<Currency>>,example = json!(["USD", "EUR"]))]
pub accepted_currencies: Option<Vec<api_enums::Currency>>,
/// Filter by amount
#[schema(example = 60)]
pub amount: Option<i64>,
/// Indicates whether the payment method is eligible for recurring payments
#[schema(example = true)]
pub recurring_enabled: Option<bool>,
/// Indicates whether the payment method is eligible for installment payments
#[schema(example = true)]
pub installment_payment_enabled: Option<bool>,
}
@ -168,25 +277,78 @@ fn set_or_reject_duplicate<T, E: de::Error>(
}
}
#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct ListPaymentMethodResponse {
/// Redirect URL of the merchant
#[schema(example = "https://www.google.com")]
pub redirect_url: Option<String>,
/// Information about the payment method
#[schema(value_type = Vec<ListPaymentMethod>,example = json!(
[
{
"payment_method": "wallet",
"payment_experience": null,
"payment_method_issuers": [
"labore magna ipsum",
"aute"
]
}
]
))]
pub payment_methods: HashSet<ListPaymentMethod>,
}
#[derive(Eq, PartialEq, Hash, Debug, serde::Deserialize)]
#[derive(Eq, PartialEq, Hash, Debug, serde::Deserialize, ToSchema)]
pub struct ListPaymentMethod {
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethodType,example = "card")]
pub payment_method: api_enums::PaymentMethodType,
/// This is a sub-category of payment method.
#[schema(value_type = Option<Vec<PaymentMethodSubType>>,example = json!(["credit_card"]))]
pub payment_method_types: Option<Vec<api_enums::PaymentMethodSubType>>,
/// The name of the bank/ provider issuing the payment method to the end user
#[schema(example = json!(["Citibank"]))]
pub payment_method_issuers: Option<Vec<String>>,
/// A standard code representing the issuer of payment method
#[schema(value_type = Option<Vec<PaymentMethodIssuerCode>>,example = json!(["jp_applepay"]))]
pub payment_method_issuer_code: Option<Vec<api_enums::PaymentMethodIssuerCode>>,
/// List of payment schemes accepted or has the processing capabilities of the processor
#[schema(example = json!(["MASTER", "VISA", "DINERS"]))]
pub payment_schemes: Option<Vec<String>>,
/// List of Countries accepted or has the processing capabilities of the processor
#[schema(example = json!(["US", "UK", "IN"]))]
pub accepted_countries: Option<Vec<String>>,
/// List of currencies accepted or has the processing capabilities of the processor
#[schema(value_type = Option<Vec<Currency>>,example = json!(["USD", "EUR"]))]
pub accepted_currencies: Option<Vec<api_enums::Currency>>,
/// Minimum amount supported by the processor. To be represented in the lowest denomination of
/// the target currency (For example, for USD it should be in cents)
#[schema(example = 60000)]
pub minimum_amount: Option<i64>,
/// Maximum amount supported by the processor. To be represented in the lowest denomination of
/// the target currency (For example, for USD it should be in cents)
#[schema(example = 1)]
pub maximum_amount: Option<i64>,
/// Boolean to enable recurring payments / mandates. Default is true.
#[schema(example = true)]
pub recurring_enabled: bool,
/// Boolean to enable installment / EMI / BNPL payments. Default is true.
#[schema(example = true)]
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>>,
}
@ -217,31 +379,86 @@ impl serde::Serialize for ListPaymentMethod {
}
}
#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct ListCustomerPaymentMethodsResponse {
/// List of enabled payment methods for a customer
#[schema(value_type = Vec<ListPaymentMethod>,example = json!(
[
{
"payment_method": "wallet",
"payment_experience": null,
"payment_method_issuers": [
"labore magna ipsum",
"aute"
]
}
]
))]
pub enabled_payment_methods: HashSet<ListPaymentMethod>,
/// List of payment methods for customer
pub customer_payment_methods: Vec<CustomerPaymentMethod>,
}
#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct DeletePaymentMethodResponse {
/// The unique identifier of the Payment method
#[schema(example = "card_rGK4Vi5iSW70MY7J2mIy")]
pub payment_method_id: String,
/// Whether payment method was deleted or not
#[schema(example = true)]
pub deleted: bool,
}
#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethod {
/// Token for payment method in temporary card locker which gets refreshed often
#[schema(example = "7ebf443f-a050-4067-84e5-e6f6d4800aef")]
pub payment_token: String,
/// The unique identifier of the customer.
#[schema(example = "cus_meowerunwiuwiwqw")]
pub customer_id: String,
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethodType,example = "card")]
pub payment_method: api_enums::PaymentMethodType,
/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodSubType>,example = "credit_card")]
pub payment_method_type: Option<api_enums::PaymentMethodSubType>,
/// The name of the bank/ provider issuing the payment method to the end user
#[schema(example = "Citibank")]
pub payment_method_issuer: Option<String>,
/// A standard code representing the issuer of payment method
#[schema(value_type = Option<PaymentMethodIssuerCode>,example = "jp_applepay")]
pub payment_method_issuer_code: Option<api_enums::PaymentMethodIssuerCode>,
/// Indicates whether the payment method is eligible for recurring payments
#[schema(example = true)]
pub recurring_enabled: bool,
/// Indicates whether the payment method is eligible for installment payments
#[schema(example = true)]
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<PaymentExperience>>,
/// Card details from card locker
#[schema(example = json!({"last4": "1142","exp_month": "03","exp_year": "2030"}))]
pub card: Option<CardDetailFromLocker>,
/// 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" }))]
pub metadata: Option<serde_json::Value>,
/// A timestamp (ISO 8601 code) that determines when the customer was created
#[schema(value_type = Option<PrimitiveDateTime>,example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
}

View File

@ -96,7 +96,7 @@ pub struct PaymentsRequest {
/// Provide a reference to a stored payment method
#[schema(example = "187282ab-40ef-47a9-9206-5099ba31e432")]
pub payment_token: Option<String>,
/// This is used when payment is to be confirmed and the card is not saved
#[schema(value_type = Option<String>)]
pub card_cvc: Option<Secret<String>>,
/// The shipping address for the payment
@ -301,7 +301,7 @@ pub struct OnlineMandate {
}
#[derive(Default, Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct CCard {
pub struct Card {
/// The card number
#[schema(value_type = String, example = "4242424242424242")]
pub card_number: Secret<String, pii::CardNumber>,
@ -375,17 +375,13 @@ pub enum PayLaterData {
}
#[derive(Debug, Clone, Eq, PartialEq, Default, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum PaymentMethod {
#[serde(rename(deserialize = "card"))]
Card(CCard),
Card(Card),
#[default]
#[serde(rename(deserialize = "bank_transfer"))]
BankTransfer,
#[serde(rename(deserialize = "wallet"))]
Wallet(WalletData),
#[serde(rename(deserialize = "pay_later"))]
PayLater(PayLaterData),
#[serde(rename(deserialize = "paypal"))]
Paypal,
}
@ -399,7 +395,7 @@ pub struct WalletData {
}
#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize)]
pub struct CCardResponse {
pub struct CardResponse {
last4: String,
exp_month: String,
exp_year: String,
@ -408,7 +404,7 @@ pub struct CCardResponse {
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize)]
pub enum PaymentMethodDataResponse {
#[serde(rename = "card")]
Card(CCardResponse),
Card(CardResponse),
#[serde(rename(deserialize = "bank_transfer"))]
BankTransfer,
Wallet(WalletData),
@ -936,8 +932,8 @@ impl From<PaymentsCaptureRequest> for PaymentsResponse {
}
}
impl From<CCard> for CCardResponse {
fn from(card: CCard) -> Self {
impl From<Card> for CardResponse {
fn from(card: Card) -> Self {
let card_number_length = card.card_number.peek().clone().len();
Self {
last4: card.card_number.peek().clone()[card_number_length - 4..card_number_length]
@ -951,7 +947,7 @@ impl From<CCard> for CCardResponse {
impl From<PaymentMethod> for PaymentMethodDataResponse {
fn from(payment_method_data: PaymentMethod) -> Self {
match payment_method_data {
PaymentMethod::Card(card) => Self::Card(CCardResponse::from(card)),
PaymentMethod::Card(card) => Self::Card(CardResponse::from(card)),
PaymentMethod::BankTransfer => Self::BankTransfer,
PaymentMethod::PayLater(pay_later_data) => Self::PayLater(pay_later_data),
PaymentMethod::Wallet(wallet_data) => Self::Wallet(wallet_data),

View File

@ -67,18 +67,29 @@ pub enum RefundType {
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct RefundResponse {
/// The identifier for refund
pub refund_id: String,
/// The identifier for payment
pub payment_id: String,
/// The refund amount, which should be less than or equal to the total payment amount. Amount for the payment in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc
pub amount: i64,
/// The three-letter ISO currency code
pub currency: String,
/// An arbitrary string attached to the object. Often useful for displaying to users and your customer support executive
pub reason: Option<String>,
/// The status for refund
pub status: RefundStatus,
/// 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>)]
pub metadata: Option<serde_json::Value>,
/// The error message
pub error_message: Option<String>,
/// The code for the error
pub error_code: Option<String>,
/// The timestamp at which refund is created
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub created_at: Option<PrimitiveDateTime>,
/// The timestamp at which refund is updated
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub updated_at: Option<PrimitiveDateTime>,
}
@ -114,11 +125,13 @@ pub struct RefundListRequest {
pub created_gte: Option<PrimitiveDateTime>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct RefundListResponse {
/// The list of refund response
pub data: Vec<RefundResponse>,
}
/// The status for refunds
#[derive(Debug, Eq, Clone, PartialEq, Default, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum RefundStatus {