diff --git a/rc_microtransactions/src/main.rs b/rc_microtransactions/src/main.rs index 1060b12..7b1b0ac 100644 --- a/rc_microtransactions/src/main.rs +++ b/rc_microtransactions/src/main.rs @@ -32,6 +32,7 @@ async fn main() -> std::io::Result<()> { .app_data(cli_args2.clone()) .service(index) .service(robocraft::robopay_store) + .service(robocraft::robopay_token) }) .bind((cli_args.ip, cli_args.port))? .run() diff --git a/rc_microtransactions/src/robocraft/mod.rs b/rc_microtransactions/src/robocraft/mod.rs index b3b3c76..a49e185 100644 --- a/rc_microtransactions/src/robocraft/mod.rs +++ b/rc_microtransactions/src/robocraft/mod.rs @@ -1,2 +1,17 @@ mod store; pub use store::robopay_store; + +mod token; +pub use token::robopay_token; + +use serde::Serialize; + +#[derive(Serialize)] +struct Response { + pub response: T +} + +#[derive(Serialize)] +struct ResponseData { + pub data: Vec +} diff --git a/rc_microtransactions/src/robocraft/store.rs b/rc_microtransactions/src/robocraft/store.rs index 0a304bc..f890ce6 100644 --- a/rc_microtransactions/src/robocraft/store.rs +++ b/rc_microtransactions/src/robocraft/store.rs @@ -1,15 +1,7 @@ use actix_web::{web::{Data, Json}, Error, post}; use serde::Serialize; -#[derive(Serialize)] -struct Response { - response: T -} - -#[derive(Serialize)] -struct ResponseData { - data: Vec -} +use super::{Response, ResponseData}; #[derive(Serialize)] struct StoreBundle { diff --git a/rc_microtransactions/src/robocraft/token.rs b/rc_microtransactions/src/robocraft/token.rs new file mode 100644 index 0000000..98e87ca --- /dev/null +++ b/rc_microtransactions/src/robocraft/token.rs @@ -0,0 +1,48 @@ +use actix_web::{web::{Data, Json}, Error, post}; +use serde::{Deserialize, Serialize}; + +use super::Response; + +#[allow(dead_code)] +#[derive(Deserialize, Debug)] +struct TokenRequest { + #[serde(rename = "Steam")] + steam: bool, + #[serde(rename = "SteamId")] + steam_id: serde_json::Value, // empty string when client not running through steam, number (SteamId64) otherwise + #[serde(rename = "Language")] + language: String, + #[serde(rename = "ItemSku")] + item_sku: String, + #[serde(rename = "ItemPrice")] + item_price: f32, + #[serde(rename = "ItemCurrency")] + item_currency: String, + #[serde(rename = "AnalyticsId")] + analytics_id: String, + #[serde(rename = "Country")] + country: Option, +} + +#[derive(Serialize)] +struct TokenResponse { + // url and data should be mutually exclusive + #[serde(skip_serializing_if = "Option::is_none")] + url: Option, // open browser to URL + #[serde(skip_serializing_if = "Option::is_none")] + data: Option, // change price to new price +} + +type ItemResponse = Response; + +#[post("/robopay/token")] +pub async fn robopay_token(_cli: Data, body: Json) -> Result, Error> { + // TODO authentication (Authorization header is "Robocraft {JWT token from auth}") + log::debug!("robopay token post body: {:?}", body); + Ok(Json(Response { + response: TokenResponse { + url: Some("https://cncycle.cheofoundation.com/".to_owned()), + data: None, + } + })) +}