use crate::orders::ItemReceipt;
use crate::serde_help::*;
use crate::*;
use builder_pattern::Builder;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderResponseData {
pub delivery: Option<Delivery>,
pub operations: Vec<OrderResponseOperation>,
pub order: Option<BaseMerchantApiOrder>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Delivery {
#[serde(with = "string_as_float")]
pub price: f64,
#[serde(with = "option_string_as_float")]
pub actual_price: Option<f64>,
#[serde(with = "option_iso8601")]
pub created: Option<Time>,
pub status: DeliveryStatus,
#[serde(with = "option_iso8601")]
pub updated: Option<Time>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum DeliveryStatus {
New,
Estimating,
Expired,
ReadyForApproval,
Collecting,
Preparing,
Delivering,
Delivered,
Returning,
Returned,
Failed,
Cancelled,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderResponseOperation {
#[serde(with = "string_as_float")]
pub amount: f64,
#[serde(rename = "operationId")]
pub operation_id: String,
#[serde(rename = "operationType")]
pub operation_type: OperationType,
#[serde(rename = "orderId")]
pub order_id: String,
pub approval_code: Option<String>,
#[serde(with = "option_iso8601")]
pub created: Option<Time>,
pub external_operation_id: Option<String>,
pub params: Option<serde_json::Value>,
pub reason: Option<String>,
pub status: OperationStatus,
#[serde(with = "option_iso8601")]
pub updated: Option<Time>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum OperationType {
Authorize,
BindCard,
Refund,
Capture,
Void,
Recurring,
Prepayment,
Submit,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum OperationStatus {
Pending,
Success,
Fail,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BaseMerchantApiOrder {
pub cart: Cart,
#[serde(default)]
pub currency_code: CurrencyCode,
#[serde(with = "option_iso8601")]
pub created: Option<Time>,
#[serde(default)]
pub is_prepayment: bool,
pub merchant_id: Option<String>,
pub metadata: Option<String>,
#[serde(with = "string_as_float")]
pub order_amount: f64,
pub order_id: String,
pub payment_method: Option<PaymentMethod>,
pub payment_status: Option<PaymentStatus>,
pub payment_url: Option<String>,
pub reason: Option<String>,
pub shipping_method: Option<ShippingMethod>,
#[serde(with = "option_iso8601")]
pub updated: Option<Time>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PaymentStatus {
Pending,
Authorized,
Captured,
Voided,
Refunded,
Confirmed,
PartiallyRefunded,
Failed,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Cart {
pub items: Vec<CartItem>,
pub cart_id: String,
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub coupons: Vec<Coupon>,
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub discounts: Vec<Discount>,
pub external_id: Option<String>,
pub measurements: Option<Measurements>,
pub total: CartTotal,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct PaymentMethod {
pub method_type: MethodType,
pub card_last4: Option<String>,
pub card_network: Option<CardNetwork>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum MethodType {
Card,
Split,
Sbp,
SplitSbp,
CashOnDelivery,
CardOnDelivery,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CardNetwork {
Amex,
Discover,
Jcb,
Mastercard,
Maestro,
Visaelectron,
Visa,
Mir,
Unionpay,
Uzcard,
Humocard,
Unknown,
Undefined,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct ShippingMethod {
pub method_type: ShippingMethodType,
pub courier_option: Option<CourierOption>,
pub pickup_option: Option<PickupOption>,
pub yandex_delivery_option: Option<YandexDeliveryOption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ShippingMethodType {
Direct,
Pickup,
Courier,
YandexDelivery,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CartItem {
pub product_id: String,
pub quantity: ItemQuantity,
pub description: Option<String>,
#[serde(with = "option_string_as_float")]
pub discounted_unit_price: Option<f64>,
pub features: Option<CartItemFeatures>,
#[serde(with = "option_string_as_float")]
pub final_price: Option<f64>,
pub measurements: Option<Measurements>,
#[serde(with = "option_string_as_float")]
pub points_amount: Option<f64>,
pub receipt: Option<ItemReceipt>,
#[serde(with = "option_string_as_float")]
pub subtotal: Option<f64>,
pub title: Option<String>,
#[serde(with = "option_string_as_float")]
pub total: Option<f64>,
pub item_type: Option<CartItemType>,
#[serde(with = "option_string_as_float")]
pub unit_price: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CartItemType {
Physical,
Digital,
Unspecified,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct Coupon {
#[into]
pub value: String,
#[default(None)]
pub description: Option<String>,
#[default(None)]
pub status: Option<CouponStatus>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CouponStatus {
Valid,
Invalid,
Expired,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct Discount {
#[into]
#[serde(with = "string_as_float")]
pub amount: f64,
#[into]
pub description: String,
#[into]
pub discount_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct Measurements {
#[into]
pub height: f64,
#[into]
pub length: f64,
#[into]
pub weight: f64,
#[into]
pub width: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CourierOption {
#[serde(with = "string_as_float")]
pub amount: f64,
pub category: CourierCategory,
pub courier_option_id: String,
pub title: String,
#[serde(default = "Vec::new")]
pub allowed_payment_methods: Vec<AllowedPaymentMethodType>,
pub customer_choice: Option<FlexibleCustomerChoice>,
#[serde(with = "option_iso8601")]
pub from_date: Option<Time>,
pub from_time: Option<String>,
pub provider: Option<DeliveryProvider>,
pub receipt: Option<ItemReceipt>,
pub time_intervals: Option<FlexibleTimeIntervals>,
#[serde(with = "option_iso8601")]
pub to_date: Option<Time>,
pub to_time: Option<String>,
#[serde(default)]
pub option_type: CourierOptionType,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CourierCategory {
Express,
Today,
Standard,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CourierOptionType {
#[default]
Plain,
Flexible,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum DeliveryProvider {
Boxberry,
Cdek,
RussianPost,
Ems,
Courier,
Dhl,
ExpressDelivery,
Fivepost,
OzonRocket,
Dpd,
SberLogistics,
Pek,
Pickpoint,
Kce,
PonyExpress,
YandexDelivery,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PickupOption {
pub address: String,
pub location: Location,
pub pickup_point_id: String,
pub title: String,
#[serde(default = "Vec::new")]
pub allowed_payment_methods: Vec<AllowedPaymentMethodType>,
#[serde(with = "option_string_as_float")]
pub amount: Option<f64>,
pub description: Option<String>,
#[serde(with = "option_iso8601")]
pub from_date: Option<Time>,
#[serde(default = "Vec::new")]
pub phones: Vec<String>,
pub provider: Option<PickupProvider>,
pub receipt: Option<ItemReceipt>,
#[serde(default = "Vec::new")]
pub schedule: Vec<PickupSchedule>,
pub storage_period: Option<i32>,
#[serde(with = "option_iso8601")]
pub to_date: Option<Time>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AllowedPaymentMethodType {
Card,
Split,
CashOnDelivery,
CardOnDelivery,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PickupProvider {
YandexMarket,
Boxberry,
Cdek,
InStore,
RussianPost,
Pickpoint,
Dpd,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PickupSchedule {
pub label: String,
pub from_time: String,
pub to_time: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct YandexDeliveryOption {
#[serde(with = "string_as_float")]
pub amount: f64,
pub category: CourierCategory,
pub title: String,
pub yandex_delivery_option_id: String,
#[serde(default = "Vec::new")]
pub allowed_payment_methods: Vec<AllowedPaymentMethodType>,
#[serde(with = "option_iso8601")]
pub from_datetime: Option<Time>,
pub receipt: Option<ItemReceipt>,
#[serde(with = "option_iso8601")]
pub to_datetime: Option<Time>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FlexibleCustomerChoice {
#[serde(with = "iso8601")]
pub date: Time,
pub time: Option<TimeInterval>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FlexibleTimeIntervals {
#[serde(rename = "type")]
pub time_intervals_type: TimeIntervalsType,
pub grid: Option<FlexibleTimeIntervalsGridDescriptor>,
#[serde(default)]
pub values: Vec<TimeInterval>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TimeInterval {
pub start: String,
pub end: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FlexibleTimeIntervalsGridDescriptor {
pub duration: String,
pub end: String,
pub start: String,
pub step: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TimeIntervalsType {
Grid,
Values,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Location {
pub latitude: f64,
pub longitude: f64,
}