use crate::controllers::Entity;
use serde::{Deserialize, Serialize};
use crate::controllers::payment_gateways::PaymentGatewayUpdate;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentGateway {
pub id: String,
pub title: String,
pub description: String,
pub order: String,
pub enabled: bool,
pub method_title: String,
pub method_description: String,
pub method_supports: Vec<String>,
pub settings: PaymentGatewaySettings,
}
impl Entity for PaymentGateway {
fn endpoint() -> String {
String::from("payment_gateways/")
}
fn child_endpoint(parent_id: i32) -> String {
let _ = parent_id;
String::new()
}
}
impl PaymentGateway {
pub fn turn_on() -> PaymentGatewayUpdate {
PaymentGatewayUpdate { enabled: true }
}
pub fn turn_off() -> PaymentGatewayUpdate {
PaymentGatewayUpdate { enabled: false }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentGatewaySettings {
pub title: TitleInstructions,
pub instructions: TitleInstructions,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TitleInstructions {
pub id: String,
pub label: String,
pub description: String,
#[serde(rename = "type")]
pub setting_type: SettingType,
pub value: String,
pub default: String,
pub tip: String,
pub placeholder: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SettingType {
Text,
Email,
Number,
Color,
Password,
Textarea,
Select,
Multiselect,
Radio,
ImageWidth,
Checkbox,
SafeText,
}