// This file is auto-generated by oagen. Do not edit.
use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;
pub struct WalletApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
/// Number of items to return per page.
///
/// Defaults to `15`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Page number to return.
///
/// Defaults to `1`.
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
impl Default for ListParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
limit: Some(15),
page: Some(1),
x_store: Default::default(),
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct AdjustParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkAdjustCustomerWalletRequestApplicationJson,
}
impl AdjustParams {
/// Construct a new `AdjustParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkAdjustCustomerWalletRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateStatusParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkUpdateCustomerWalletStatusRequestApplicationJson,
}
impl UpdateStatusParams {
/// Construct a new `UpdateStatusParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkUpdateCustomerWalletStatusRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
impl<'a> WalletApi<'a> {
/// List customer wallets
///
/// List customer wallet balances for the authenticated store. Requires the `wallet` or `wallet:write` API ability. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn list(
&self,
params: ListParams,
) -> Result<SdkListCustomerWalletsResponseValue200ApplicationJson, Error> {
self.list_with_options(params, None).await
}
/// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_with_options(
&self,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkListCustomerWalletsResponseValue200ApplicationJson, Error> {
self.list_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn list_raw(
&self,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkListCustomerWalletsResponseValue200ApplicationJson>, Error>
{
let path = "/v2/wallets".to_string();
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("listCustomerWallets".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(method, &path, ¶ms, options, "GET /v2/wallets")
.await
}
/// Retrieve a customer wallet
///
/// Retrieve one current-store customer wallet by customer ID. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn get(
&self,
customer: &str,
params: GetParams,
) -> Result<SdkGetCustomerWalletResponseValue200ApplicationJson, Error> {
self.get_with_options(customer, params, None).await
}
/// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_with_options(
&self,
customer: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetCustomerWalletResponseValue200ApplicationJson, Error> {
self.get_raw(customer, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_raw(
&self,
customer: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkGetCustomerWalletResponseValue200ApplicationJson>, Error>
{
let customer = crate::client::path_segment(customer);
let path = format!("/v2/wallets/{customer}");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getCustomerWallet".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/wallets/{customer}",
)
.await
}
/// Adjust a customer wallet
///
/// Add or subtract a nonzero amount from a customer wallet. Requires the wallet:write API ability and store wallet permission. Use signed integer cents and a nonblank note. Positive adjustments can create a wallet and follow the store's credit-expiration policy; negative adjustments need an existing eligible wallet and sufficient balance. Wallets must be enabled. Send idempotency_key in the body. Replaying the same key returns the original entry only for the same store, customer, staff actor, amount and trimmed note; changed input returns 422. Keep that identity unchanged across retries. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn adjust(
&self,
customer: &str,
params: AdjustParams,
) -> Result<SdkAdjustCustomerWalletResponseValue200ApplicationJson, Error> {
self.adjust_with_options(customer, params, None).await
}
/// Variant of [`Self::adjust`] that accepts per-request [`crate::RequestOptions`].
pub async fn adjust_with_options(
&self,
customer: &str,
params: AdjustParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkAdjustCustomerWalletResponseValue200ApplicationJson, Error> {
self.adjust_raw(customer, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn adjust_raw(
&self,
customer: &str,
params: AdjustParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkAdjustCustomerWalletResponseValue200ApplicationJson>, Error>
{
let customer = crate::client::path_segment(customer);
let path = format!("/v2/wallets/{customer}/adjustments");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("adjustCustomerWallet".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/wallets/{customer}/adjustments",
)
.await
}
/// Update a customer wallet status
///
/// Freeze or activate an existing customer wallet. Requires wallet:write and the store wallet permission, with wallets enabled. Activating a frozen wallet expires eligible credits before returning, so its balance may decrease. Read balance_cents from the returned wallet. Repeating the current status leaves the wallet unchanged. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn update_status(
&self,
customer: &str,
params: UpdateStatusParams,
) -> Result<SdkUpdateCustomerWalletStatusResponseValue200ApplicationJson, Error> {
self.update_status_with_options(customer, params, None)
.await
}
/// Variant of [`Self::update_status`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_status_with_options(
&self,
customer: &str,
params: UpdateStatusParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkUpdateCustomerWalletStatusResponseValue200ApplicationJson, Error> {
self.update_status_raw(customer, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn update_status_raw(
&self,
customer: &str,
params: UpdateStatusParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkUpdateCustomerWalletStatusResponseValue200ApplicationJson>,
Error,
> {
let customer = crate::client::path_segment(customer);
let path = format!("/v2/wallets/{customer}/status");
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("updateCustomerWalletStatus".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/wallets/{customer}/status",
)
.await
}
}