1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add robopay token endpoint

This commit is contained in:
NG (Graham)
2026-01-12 20:34:34 -05:00
parent a182ced637
commit cab6774366
4 changed files with 65 additions and 9 deletions

View File

@@ -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()

View File

@@ -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<T> {
pub response: T
}
#[derive(Serialize)]
struct ResponseData<T> {
pub data: Vec<T>
}

View File

@@ -1,15 +1,7 @@
use actix_web::{web::{Data, Json}, Error, post};
use serde::Serialize;
#[derive(Serialize)]
struct Response<T> {
response: T
}
#[derive(Serialize)]
struct ResponseData<T> {
data: Vec<T>
}
use super::{Response, ResponseData};
#[derive(Serialize)]
struct StoreBundle {

View File

@@ -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,
}
}))
}