1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
use serde::{Deserialize, Serialize};
use crate::controllers::payment_gateways::PaymentGatewayUpdate;
/// ```rust
/// #[cfg(test)]
/// mod tests {
/// use crate::{payment_gateways::PaymentGateway, ApiClient, Entity};
///
/// #[tokio::test]
/// async fn test_list_all_retrieve_payment_gateway() {
/// let client = ApiClient::from_env().unwrap();
/// let gts = client
/// .list_all::<PaymentGateway>(Entity::PaymentGateway)
/// .await
/// .unwrap();
/// assert!(!gts.is_empty());
/// if let Some(f) = gts.first() {
/// let p: PaymentGateway = client
/// .retrieve(Entity::PaymentGateway, &f.id)
/// .await
/// .unwrap();
/// assert_eq!(f.id, p.id);
/// }
/// }
/// #[tokio::test]
/// async fn test_update_payment_gateway() {
/// let client = ApiClient::from_env().unwrap();
/// let update = PaymentGateway::turn_off();
/// let id = "cheque";
/// let updated: PaymentGateway = client
/// .update(Entity::PaymentGateway, id, update)
/// .await
/// .unwrap();
/// assert!(!updated.enabled);
/// }
/// }
/// ```
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentGateway {
/// Payment gateway ID.
pub id: String,
/// Payment gateway title on checkout.
pub title: String,
/// Payment gateway description on checkout.
pub description: String,
/// Payment gateway sort order.
pub order: String,
/// Payment gateway enabled status.
pub enabled: bool,
/// Payment gateway method title.
pub method_title: String,
/// Payment gateway method description.
pub method_description: String,
/// Supported features for this payment gateway.
pub method_supports: Vec<String>,
/// Payment gateway settings.
pub settings: PaymentGatewaySettings,
}
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 {
/// A unique identifier for the setting.
pub id: String,
/// A human readable label for the setting used in interfaces.
pub label: String,
/// A human readable description for the setting used in interfaces.
pub description: String,
/// Type of setting. Options: text, email, number, color, password, textarea, select, multiselect, radio, image_width and checkbox.
#[serde(rename = "type")]
pub setting_type: SettingType,
/// Setting value.
pub value: String,
/// Default value for the setting.
pub default: String,
/// Additional help text shown to the user about the setting.
pub tip: String,
/// Placeholder text to be displayed in text inputs.
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,
}