delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! Sell-to restrictions: the buyer countries a merchant refuses to sell to,
//! merchant-wide, per project, per shop and per connector account.

use serde::Deserialize;
use serde_json::Value;

/// A sell-to policy.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SellToRestrictionPolicy {
    /// Buyer countries refused, as ISO 3166-1 alpha-2 codes.
    #[serde(default)]
    pub blocked_countries: Vec<String>,
    /// Whether a payment whose buyer IP country cannot be resolved is refused.
    #[serde(default)]
    pub block_unknown_ip_country: bool,
    /// ISO 8601 last-modification timestamp.
    pub modified_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One shop's effective policy and where it comes from.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ShopSellToRestriction {
    /// The shop (business profile).
    pub profile_id: String,
    /// The shop's name.
    pub profile_name: String,
    /// `merchant`, `shop`, `project`, `connector` or `none`.
    pub source: String,
    /// The policy that applies to the shop.
    #[serde(default)]
    pub effective_policy: Option<SellToRestrictionPolicy>,
    /// The project the policy comes from, for a `project` source.
    #[serde(default)]
    pub source_project_id: Option<String>,
    /// That project's name.
    #[serde(default)]
    pub source_project_name: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One project's own policy.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectSellToRestriction {
    /// The project.
    pub project_id: String,
    /// The project's name.
    pub project_name: String,
    /// The parent project.
    #[serde(default)]
    pub parent_project_id: Option<String>,
    /// Whether the project is active.
    pub is_active: bool,
    /// The project's own policy, or `None` when it has none.
    #[serde(default)]
    pub policy: Option<SellToRestrictionPolicy>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Which buyer signals a connector account's payments can be judged on.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ConnectorSellToEnforcement {
    /// The buyer's IP country.
    pub ip_country: bool,
    /// The card's issuing country.
    pub card_issuing_country: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One connector account's own policy.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ConnectorSellToRestriction {
    /// The connector account.
    pub merchant_connector_id: String,
    /// The connector.
    pub connector_name: String,
    /// The account's label.
    #[serde(default)]
    pub connector_label: Option<String>,
    /// The account's own policy, or `None` when it has none.
    #[serde(default)]
    pub policy: Option<SellToRestrictionPolicy>,
    /// Which buyer signals its payments can be judged on.
    pub enforces: ConnectorSellToEnforcement,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The merchant-wide policy and every shop's effective policy.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SellToRestrictionsResponse {
    /// The merchant-wide policy. `None` for a caller scoped to one shop.
    #[serde(default)]
    pub merchant_policy: Option<SellToRestrictionPolicy>,
    /// Every shop the caller sees.
    #[serde(default)]
    pub shops: Vec<ShopSellToRestriction>,
    /// Every project with its own policy.
    #[serde(default)]
    pub projects: Vec<ProjectSellToRestriction>,
    /// Every connector account with its own policy.
    #[serde(default)]
    pub connectors: Vec<ConnectorSellToRestriction>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// How this deployment resolves a buyer's IP country.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct IpCountryResolution {
    /// From a country header set at the edge.
    pub edge_country_header: bool,
    /// From a GeoIP database.
    pub geoip_database: bool,
    /// From a country the hosted checkout forwards, signed.
    pub signed_checkout_forwarding: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Which checks one payment path performs.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SellToRestrictionRailCapability {
    /// The payment path, for example `api_payments` or `stripe_hosted_card`.
    pub rail: String,
    /// `checkout_and_confirm`, `checkout_only` or `merchant_stated_ip`.
    pub ip_country: String,
    /// `before_authorization`, `not_enforced` or `not_applicable`.
    pub card_issuing_country: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Which checks each payment path performs, and how a buyer's country is
/// resolved.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SellToRestrictionCapabilitiesResponse {
    /// How the buyer's IP country is resolved.
    pub ip_country_resolution: IpCountryResolution,
    /// One entry per payment path.
    #[serde(default)]
    pub rails: Vec<SellToRestrictionRailCapability>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One refusal of a payment by a sell-to policy.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SellToRestrictionDecisionResponse {
    /// Where: `checkout_render` or `confirm`.
    pub stage: String,
    /// The signal that refused: `ip_country`, `ip_country_unknown`,
    /// `ip_country_unverified` or `card_issuing_country`.
    pub signal: String,
    /// The country refused, as an ISO 3166-1 alpha-2 code.
    #[serde(default)]
    pub country: Option<String>,
    /// The policy that refused: `merchant`, `shop`, `project` or `connector`.
    pub policy_source: String,
    /// The payment attempt.
    #[serde(default)]
    pub attempt_id: Option<String>,
    /// The connector.
    #[serde(default)]
    pub connector: Option<String>,
    /// ISO 8601 timestamp.
    pub created_at: String,
    /// The id of the project or connector account whose policy refused.
    #[serde(default)]
    pub policy_ref: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Why a payment was refused by sell-to policies.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SellToRestrictionDecisionsResponse {
    /// The payment.
    pub payment_id: String,
    /// Every refusal.
    #[serde(default)]
    pub decisions: Vec<SellToRestrictionDecisionResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}