Add robopay token endpoint

This commit is contained in:
NG (Graham) committed 2026-03-31 17:08:50 -04:00
1 parent a182ced637
commit cab6774366
4 files changed
+65 -9

No files matched your search

+1
View File
@@ -32,6 +32,7 @@ async fn main() -> std::io::Result<()> {
.app_data(cli_args2.clone()) .app_data(cli_args2.clone())
.service(index) .service(index)
.service(robocraft::robopay_store) .service(robocraft::robopay_store)
.service(robocraft::robopay_token)
}) })
.bind((cli_args.ip, cli_args.port))? .bind((cli_args.ip, cli_args.port))?
.run() .run()
+15
View File
@@ -1,2 +1,17 @@
mod store; mod store;
pub use store::robopay_store; pub use store::robopay_store;
mod token;
pub use token::robopay_token;
use serde::Serialize;
#[derive(Serialize)]
struct Response<T> {
pub response: T
}
#[derive(Serialize)]
struct ResponseData<T> {
pub data: Vec<T>
}
+1 -9
View File
@@ -1,15 +1,7 @@
use actix_web::{web::{Data, Json}, Error, post}; use actix_web::{web::{Data, Json}, Error, post};
use serde::Serialize; use serde::Serialize;
#[derive(Serialize)] use super::{Response, ResponseData};
struct Response<T> {
response: T
}
#[derive(Serialize)]
struct ResponseData<T> {
data: Vec<T>
}
#[derive(Serialize)] #[derive(Serialize)]
struct StoreBundle { struct StoreBundle {
@@ -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<String>,
}
#[derive(Serialize)]
struct TokenResponse {
// url and data should be mutually exclusive
#[serde(skip_serializing_if = "Option::is_none")]
url: Option<String>, // open browser to URL
#[serde(skip_serializing_if = "Option::is_none")]
data: Option<String>, // change price to new price
}
type ItemResponse = Response<TokenResponse>;
#[post("/robopay/token")]
pub async fn robopay_token(_cli: Data<crate::cli::CliArgs>, body: Json<TokenRequest>) -> Result<Json<ItemResponse>, 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,
}
}))
}