src/shop/shop.oxl
@error pub data Declined { pub why: str }
pub data Receipt { pub id: i64 }
/// An external payment provider (in production a gRPC service; here a contract with a default implementation).
pub service Payments {
@public rpc charge(cents: i64) -> Receipt | Declined
}
impl Payments {
rpc charge(cents) {
if cents > 100000 { fail Declined{ why: "limit" } }
Receipt{ id: cents }
}
}
/// Charges `cents`; a timeout is retried once, because charging is idempotent in this toy provider.
pub fn pay(cents: i64) -> Receipt | Declined | NetError {
match Payments.charge(cents) {
Receipt r => r
Timeout => Payments.charge(cents)?
other => other?
}
}Source: examples/testing-demo/src/shop/shop.oxl