use crate::{IosIapProduct, IosIapTransaction};
#[derive(Debug, Clone)]
pub enum IosIapProductsResponse {
Done(Vec<IosIapProduct>),
Error(String),
}
impl IosIapProductsResponse {
pub(crate) fn done(items: Vec<IosIapProduct>) -> Self {
Self::Done(items)
}
pub(crate) fn error(e: String) -> Self {
Self::Error(e)
}
}
#[derive(Debug, Clone)]
pub enum IosIapTransactionResponse {
Done(Vec<IosIapTransaction>),
Error(String),
}
impl IosIapTransactionResponse {
pub(crate) fn done(items: Vec<IosIapTransaction>) -> Self {
Self::Done(items)
}
pub(crate) fn error(e: String) -> Self {
Self::Error(e)
}
}
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum IosIapTransactionFinishResponse {
UnknownTransaction(u64),
Finished(IosIapTransaction),
Error(String),
}
impl IosIapTransactionFinishResponse {
pub(crate) fn unknown(id: u64) -> Self {
Self::UnknownTransaction(id)
}
pub(crate) fn finished(t: IosIapTransaction) -> Self {
Self::Finished(t)
}
pub(crate) fn error(e: String) -> Self {
Self::Error(e)
}
}
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum IosIapPurchaseResponse {
Success(IosIapTransaction),
Canceled(String),
Pending(String),
Unknown(String),
Error(String),
PurchaseError {
error: IosIapPurchaseError,
localized_description: String,
},
StoreKitError {
error: IosIapStoreKitError,
localized_description: String,
},
}
impl IosIapPurchaseResponse {
pub(crate) fn success(t: IosIapTransaction) -> Self {
Self::Success(t)
}
pub(crate) fn canceled(id: String) -> Self {
Self::Canceled(id)
}
pub(crate) fn pending(id: String) -> Self {
Self::Pending(id)
}
pub(crate) fn unknown(id: String) -> Self {
Self::Unknown(id)
}
pub(crate) fn error(e: String) -> Self {
Self::Error(e)
}
pub(crate) fn purchase_error(
error: IosIapPurchaseError,
localized_description: String,
) -> Self {
Self::PurchaseError {
error,
localized_description,
}
}
pub(crate) fn storekit_error(
error: IosIapStoreKitError,
localized_description: String,
) -> Self {
Self::StoreKitError {
error,
localized_description,
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum IosIapPurchaseError {
InvalidQuantity,
ProductUnavailable,
PurchaseNotAllowed,
IneligibleForOffer,
InvalidOfferIdentifier,
InvalidOfferPrice,
InvalidOfferSignature,
MissingOfferParameters,
}
impl IosIapPurchaseError {
pub fn invalid_quantity() -> Self {
Self::InvalidQuantity
}
pub fn product_unavailable() -> Self {
Self::ProductUnavailable
}
pub fn purchase_not_allowed() -> Self {
Self::PurchaseNotAllowed
}
pub fn ineligible_for_offer() -> Self {
Self::IneligibleForOffer
}
pub fn invalid_offer_identifier() -> Self {
Self::InvalidOfferIdentifier
}
pub fn invalid_offer_price() -> Self {
Self::InvalidOfferPrice
}
pub fn invalid_offer_signature() -> Self {
Self::InvalidOfferSignature
}
pub fn missing_offer_parameters() -> Self {
Self::MissingOfferParameters
}
}
#[derive(Debug, Clone)]
pub enum IosIapStoreKitError {
Unknown,
UserCancelled,
NetworkError(String),
SystemError(String),
NotAvailableInStorefront,
NotEntitled,
}
impl IosIapStoreKitError {
pub fn unknown() -> Self {
Self::Unknown
}
pub fn user_cancelled() -> Self {
Self::UserCancelled
}
pub fn network_error(e: String) -> Self {
Self::NetworkError(e)
}
pub fn system_error(e: String) -> Self {
Self::SystemError(e)
}
pub fn not_available_in_storefront() -> Self {
Self::NotAvailableInStorefront
}
pub fn not_entitled() -> Self {
Self::NotEntitled
}
}