Skip to main content

tauri_plugin_sumup/
lib.rs

1use tauri::{
2  plugin::{Builder, TauriPlugin},
3  Manager, Runtime,
4};
5
6pub use models::*;
7
8mod mobile;
9
10mod commands;
11mod error;
12mod models;
13
14pub use error::{Error, Result};
15
16use mobile::Sumup;
17
18/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the sumup APIs.
19pub trait SumupExt<R: Runtime> {
20  fn sumup(&self) -> &Sumup<R>;
21}
22
23impl<R: Runtime, T: Manager<R>> crate::SumupExt<R> for T {
24  fn sumup(&self) -> &Sumup<R> {
25    self.state::<Sumup<R>>().inner()
26  }
27}
28
29/// Initializes the plugin.
30pub fn init<R: Runtime>() -> TauriPlugin<R> {
31  Builder::new("sumup")
32    .invoke_handler(tauri::generate_handler![
33      commands::init_sumup_sdk,
34      commands::is_logged_in,
35      commands::logout,
36      commands::login_with_token,
37      commands::get_merchant,
38      commands::prepare_for_checkout,
39      commands::present_card_reader_selection,
40      commands::checkout
41    ])
42    .setup(|app, api| {
43      let sumup = mobile::init(app, api)?;
44      app.manage(sumup);
45      Ok(())
46    })
47    .build()
48}