rust_woocommerce/models/
payment_gateways.rs

1use crate::controllers::Entity;
2use serde::{Deserialize, Serialize};
3
4use crate::controllers::payment_gateways::PaymentGatewayUpdate;
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct PaymentGateway {
7    /// Payment gateway ID.
8    pub id: String,
9    /// Payment gateway title on checkout.
10    pub title: String,
11    /// Payment gateway description on checkout.
12    pub description: String,
13    /// Payment gateway sort order.
14    pub order: String,
15    /// Payment gateway enabled status.
16    pub enabled: bool,
17    /// Payment gateway method title.
18    pub method_title: String,
19    /// Payment gateway method description.
20    pub method_description: String,
21    /// Supported features for this payment gateway.
22    pub method_supports: Vec<String>,
23    /// Payment gateway settings.
24    pub settings: PaymentGatewaySettings,
25}
26impl Entity for PaymentGateway {
27    fn endpoint() -> String {
28        String::from("payment_gateways/")
29    }
30
31    fn child_endpoint(parent_id: i32) -> String {
32        let _ = parent_id;
33        String::new()
34    }
35}
36impl PaymentGateway {
37    pub fn turn_on() -> PaymentGatewayUpdate {
38        PaymentGatewayUpdate { enabled: true }
39    }
40    pub fn turn_off() -> PaymentGatewayUpdate {
41        PaymentGatewayUpdate { enabled: false }
42    }
43}
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct PaymentGatewaySettings {
46    pub title: TitleInstructions,
47    pub instructions: TitleInstructions,
48}
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct TitleInstructions {
51    /// A unique identifier for the setting.
52    pub id: String,
53    /// A human readable label for the setting used in interfaces.
54    pub label: String,
55    /// A human readable description for the setting used in interfaces.
56    pub description: String,
57    /// Type of setting. Options: text, email, number, color, password, textarea, select, multiselect, radio, image_width and checkbox.
58    #[serde(rename = "type")]
59    pub setting_type: SettingType,
60    /// Setting value.
61    pub value: String,
62    /// Default value for the setting.
63    pub default: String,
64    /// Additional help text shown to the user about the setting.
65    pub tip: String,
66    /// Placeholder text to be displayed in text inputs.
67    pub placeholder: String,
68}
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(rename_all = "snake_case")]
71pub enum SettingType {
72    Text,
73    Email,
74    Number,
75    Color,
76    Password,
77    Textarea,
78    Select,
79    Multiselect,
80    Radio,
81    ImageWidth,
82    Checkbox,
83    SafeText,
84}