use serde::{Deserialize, Serialize};
use crate::types::CountrySource;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RateLimit {
pub limit: u32,
pub remaining: u32,
pub reset: u32,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct CreatePortalSession {
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub country: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub end_user_ip: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ttl_seconds: Option<u32>,
}
impl CreatePortalSession {
pub fn return_url(mut self, url: impl Into<String>) -> Self {
self.return_url = Some(url.into());
self
}
pub fn country(mut self, country: impl Into<String>) -> Self {
self.country = Some(country.into());
self
}
pub fn end_user_ip(mut self, ip: impl Into<String>) -> Self {
self.end_user_ip = Some(ip.into());
self
}
pub fn ttl_seconds(mut self, seconds: u32) -> Self {
self.ttl_seconds = Some(seconds);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortalSession {
pub id: String,
pub customer: String,
pub country: String,
pub country_source: CountrySource,
pub url: String,
pub expires_at: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SecretKind {
Card,
Address,
Contact,
IdentityDocument,
ShopPassword,
Loyalty,
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateSecret {
#[serde(skip_serializing_if = "Option::is_none")]
pub customer: Option<String>,
pub kind: SecretKind,
pub label: String,
pub fields: std::collections::HashMap<String, String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub shops: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expires_at: Option<String>,
}
impl CreateSecret {
pub fn new<I, K, V>(kind: SecretKind, label: impl Into<String>, fields: I) -> Self
where
I: IntoIterator<Item = (K, V)>,
K: Into<String>,
V: Into<String>,
{
Self {
customer: None,
kind,
label: label.into(),
fields: fields.into_iter().map(|(k, v)| (k.into(), v.into())).collect(),
shops: None,
default: None,
expires_at: None,
}
}
pub fn customer(mut self, customer: impl Into<String>) -> Self {
self.customer = Some(customer.into());
self
}
pub fn shops<I, S>(mut self, shops: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.shops = Some(shops.into_iter().map(Into::into).collect());
self
}
pub fn default(mut self, yes: bool) -> Self {
self.default = Some(yes);
self
}
pub fn expires_at(mut self, at: impl Into<String>) -> Self {
self.expires_at = Some(at.into());
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Mode {
Test,
Live,
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Secret {
pub id: String,
#[serde(default)]
pub customer: Option<String>,
pub kind: SecretKind,
pub label: String,
pub mask: String,
#[serde(default)]
pub public: std::collections::HashMap<String, String>,
#[serde(default)]
pub shops: Vec<String>,
#[serde(default)]
pub default: bool,
pub mode: Mode,
pub entered_by: String,
pub version: u32,
pub created_at: String,
pub updated_at: String,
#[serde(default)]
pub expires_at: Option<String>,
#[serde(default)]
pub last_used_at: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListSecrets {
#[serde(skip_serializing_if = "Option::is_none")]
pub customer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<SecretKind>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecretList {
pub data: Vec<Secret>,
#[serde(default)]
pub next_cursor: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecretUse {
pub id: String,
pub secret: String,
pub kind: SecretKind,
pub action: String,
pub actor: String,
pub outcome: String,
#[serde(default)]
pub reason: Option<String>,
#[serde(default)]
pub field: Option<String>,
#[serde(default)]
pub field_names: Vec<String>,
#[serde(default)]
pub shop: Option<String>,
#[serde(default)]
pub intent: Option<String>,
pub at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecretUseList {
pub data: Vec<SecretUse>,
#[serde(default)]
pub next_cursor: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct Page {
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateSecretRequest {
pub kinds: Vec<SecretKind>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ttl_seconds: Option<u32>,
}
impl CreateSecretRequest {
pub fn new(kinds: impl IntoIterator<Item = SecretKind>) -> Self {
Self {
kinds: kinds.into_iter().collect(),
return_url: None,
ttl_seconds: None,
}
}
pub fn return_url(mut self, url: impl Into<String>) -> Self {
self.return_url = Some(url.into());
self
}
pub fn ttl_seconds(mut self, seconds: u32) -> Self {
self.ttl_seconds = Some(seconds);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecretRequestCreated {
pub id: String,
pub customer: String,
pub kinds: Vec<SecretKind>,
pub url: String,
pub expires_at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecretRequest {
pub id: String,
pub customer: String,
pub mode: Mode,
pub kinds: Vec<SecretKind>,
pub state: String,
pub expires_at: String,
#[serde(default)]
pub completed_at: Option<String>,
#[serde(default)]
pub secrets: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LiveLink {
pub session: String,
pub url: String,
pub expires_at: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateSignIn {
pub shop_url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub country: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub end_user_ip: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<String>,
}
impl CreateSignIn {
pub fn new(shop_url: impl Into<String>) -> Self {
Self {
shop_url: shop_url.into(),
customer: None,
country: None,
end_user_ip: None,
return_url: None,
}
}
pub fn customer(mut self, customer: impl Into<String>) -> Self {
self.customer = Some(customer.into());
self
}
pub fn country(mut self, country: impl Into<String>) -> Self {
self.country = Some(country.into());
self
}
pub fn end_user_ip(mut self, ip: impl Into<String>) -> Self {
self.end_user_ip = Some(ip.into());
self
}
pub fn return_url(mut self, url: impl Into<String>) -> Self {
self.return_url = Some(url.into());
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SignInStatus {
Open,
Active,
Done,
Declined,
Expired,
Cancelled,
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SignIn {
pub id: String,
pub status: SignInStatus,
#[serde(default)]
pub customer: Option<String>,
pub shop: String,
#[serde(default)]
pub country: Option<String>,
#[serde(default)]
pub country_source: Option<CountrySource>,
#[serde(default)]
pub return_url: Option<String>,
#[serde(default)]
pub url: Option<String>,
#[serde(default)]
pub test: bool,
pub created_at: String,
pub expires_at: String,
#[serde(default)]
pub ended_at: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateWebhookEndpoint {
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub events: Option<Vec<String>>,
}
impl CreateWebhookEndpoint {
pub fn new(url: impl Into<String>) -> Self {
Self {
url: url.into(),
events: None,
}
}
pub fn events<I, S>(mut self, events: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.events = Some(events.into_iter().map(Into::into).collect());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct UpdateWebhookEndpoint {
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub events: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disabled: Option<bool>,
}
impl UpdateWebhookEndpoint {
pub fn url(mut self, url: impl Into<String>) -> Self {
self.url = Some(url.into());
self
}
pub fn events<I, S>(mut self, events: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.events = Some(events.into_iter().map(Into::into).collect());
self
}
pub fn disabled(mut self, yes: bool) -> Self {
self.disabled = Some(yes);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebhookEndpoint {
pub id: String,
pub url: String,
#[serde(default)]
pub events: Vec<String>,
#[serde(default)]
pub disabled: bool,
pub created_at: String,
#[serde(default)]
pub previous_secret_expires_at: Option<String>,
#[serde(default)]
pub secret: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebhookEndpointList {
pub data: Vec<WebhookEndpoint>,
#[serde(default)]
pub next_cursor: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DeliveryStatus {
Pending,
Delivered,
Failed,
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebhookDelivery {
pub id: String,
#[serde(default)]
pub endpoint: Option<String>,
pub event_id: String,
pub event_type: String,
pub status: DeliveryStatus,
pub attempts: u32,
#[serde(default)]
pub response_code: Option<u16>,
#[serde(default)]
pub error: Option<String>,
pub created_at: String,
#[serde(default)]
pub next_attempt_at: Option<String>,
#[serde(default)]
pub delivered_at: Option<String>,
#[serde(default)]
pub redelivery_of: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebhookDeliveryList {
pub data: Vec<WebhookDelivery>,
#[serde(default)]
pub next_cursor: Option<String>,
}