use serde::{Deserialize, Serialize};
use serde_json::json;
use crate::{NonRustCodeRunnerFactory, NonRustRuntime, RunError};
use hanzo_messages::schemas::x402_types::{
FacilitatorConfig, Network, PaymentPayload, PaymentRequirements, Price,
};
#[derive(Debug, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Input {
pub price: Price,
pub network: Network,
pub pay_to: String,
pub payment: Option<String>,
pub x402_version: u32,
pub facilitator: FacilitatorConfig,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InvalidOutput {
pub error: String,
pub accepts: Vec<PaymentRequirements>,
pub x402_version: u32,
pub payer: Option<String>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ValidOutput {
pub decoded_payment: PaymentPayload,
pub selected_payment_requirements: PaymentRequirements,
}
#[derive(Debug, Deserialize)]
pub struct Output {
pub invalid: Option<InvalidOutput>,
pub valid: Option<ValidOutput>,
}
pub async fn verify_payment(input: Input) -> Result<Output, RunError> {
let code = include_str!("verifyPaymentDenoImpl.ts");
let runner = NonRustCodeRunnerFactory::new("verify_payment", code, vec![])
.with_runtime(NonRustRuntime::Deno)
.create_runner(json!({}));
runner.run::<_, Output>(input, None).await
}