use serde::de::DeserializeOwned;
use tauri::{AppHandle, Runtime};
use crate::models::*;
#[cfg(mobile)]
use tauri::plugin::{PluginApi, PluginHandle};
#[cfg(target_os = "ios")]
tauri::ios_plugin_binding!(init_plugin_sumup);
#[cfg(mobile)]
pub fn init<R: Runtime, C: DeserializeOwned>(
_app: &AppHandle<R>,
api: PluginApi<R, C>,
) -> crate::Result<Sumup<R>> {
#[cfg(target_os = "android")]
let handle = api.register_android_plugin("ch.manaf.tauri_plugins.sumup", "SumupPlugin")?;
#[cfg(target_os = "ios")]
let handle = api.register_ios_plugin(init_plugin_sumup)?;
Ok(Sumup(handle))
}
#[cfg(desktop)]
pub fn init<R: Runtime, C: DeserializeOwned>(
_app: &AppHandle<R>,
_api: tauri::plugin::PluginApi<R, C>,
) -> crate::Result<Sumup<R>> {
Ok(Sumup(std::marker::PhantomData))
}
#[cfg(mobile)]
pub struct Sumup<R: Runtime>(PluginHandle<R>);
#[cfg(desktop)]
pub struct Sumup<R: Runtime>(std::marker::PhantomData<*const R>);
#[cfg(desktop)]
unsafe impl<R: Runtime> Send for Sumup<R> {}
#[cfg(desktop)]
unsafe impl<R: Runtime> Sync for Sumup<R> {}
#[cfg(mobile)]
impl<R: Runtime> Sumup<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
self
.0
.run_mobile_plugin("ping", payload)
.map_err(Into::into)
}
pub fn init_sumup_sdk(&self, _payload: InitSdkRequest) -> crate::Result<bool> {
self
.0
.run_mobile_plugin("init_sumup_sdk", _payload)
.map_err(Into::into)
}
pub fn is_logged_in(&self) -> crate::Result<bool> {
self
.0
.run_mobile_plugin("is_logged_in", EmptyResponse::default())
.map_err(Into::into)
}
pub fn logout(&self) -> crate::Result<EmptyResponse> {
self
.0
.run_mobile_plugin("logout", EmptyResponse::default())
.map_err(Into::into)
}
pub fn login_with_token(&self, payload: LoginRequest) -> crate::Result<bool> {
self
.0
.run_mobile_plugin("login_with_token", payload)
.map_err(Into::into)
}
pub fn get_merchant(&self) -> crate::Result<MerchantInfo> {
self
.0
.run_mobile_plugin("get_merchant", EmptyResponse::default())
.map_err(Into::into)
}
pub fn prepare_for_checkout(&self) -> crate::Result<EmptyResponse> {
self
.0
.run_mobile_plugin("prepare_for_checkout", EmptyResponse::default())
.map_err(Into::into)
}
pub fn present_card_reader_selection(&self) -> crate::Result<EmptyResponse> {
self
.0
.run_mobile_plugin("present_card_reader_selection", EmptyResponse::default())
.map_err(Into::into)
}
pub fn checkout(&self, payload: CheckoutRequest) -> crate::Result<CheckoutResult> {
self
.0
.run_mobile_plugin("checkout", payload)
.map_err(Into::into)
}
}
#[cfg(desktop)]
impl<R: Runtime> Sumup<R> {
pub fn ping(&self, _payload: PingRequest) -> crate::Result<PingResponse> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn init_sumup_sdk(&self, _payload: InitSdkRequest) -> crate::Result<bool> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn is_logged_in(&self) -> crate::Result<bool> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn logout(&self) -> crate::Result<EmptyResponse> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn login_with_token(&self, _payload: LoginRequest) -> crate::Result<bool> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn get_merchant(&self) -> crate::Result<MerchantInfo> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn prepare_for_checkout(&self) -> crate::Result<EmptyResponse> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn present_card_reader_selection(&self) -> crate::Result<EmptyResponse> {
Err(crate::Error::UnsupportedPlatform)
}
pub fn checkout(&self, _payload: CheckoutRequest) -> crate::Result<CheckoutResult> {
Err(crate::Error::UnsupportedPlatform)
}
}