// 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 WalletTopupsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateParams {
/// 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: SdkCreateWalletTopUpRequestApplicationJson,
}
impl CreateParams {
/// Construct a new `CreateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkCreateWalletTopUpRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
impl<'a> WalletTopupsApi<'a> {
/// Create a wallet top-up payment link
///
/// Create a paid USD top-up for an existing customer and return data.checkout_url for the customer to pay. Creating a link leaves the wallet balance unchanged. Requires both wallet:write and charge API-key abilities and both store wallet and charge permissions. The wallet must be enabled and unfrozen, and the amount and selected method must satisfy the store's wallet settings. Payment completion credits the deposit and any bonus saved at creation exactly once; custom-method modifiers do not change the deposit. Browser returns and submitted payment proof do not prove payment. The return and cancel destination is the store's customer portal wallet. Currency, metadata, and redirect overrides are unsupported. Send an Idempotency-Key and reuse the same key and request for response replay within 24 hours. Changed input returns 409. For an uncertain provider outcome, inspect the charge before starting another top-up. 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 create(
&self,
customer: &str,
params: CreateParams,
) -> Result<SdkCreateWalletTopUpResponseValue201ApplicationJson, Error> {
self.create_with_options(customer, params, None).await
}
/// Variant of [`Self::create`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_with_options(
&self,
customer: &str,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCreateWalletTopUpResponseValue201ApplicationJson, Error> {
self.create_raw(customer, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn create_raw(
&self,
customer: &str,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkCreateWalletTopUpResponseValue201ApplicationJson>, Error>
{
let customer = crate::client::path_segment(customer);
let path = format!("/v2/wallets/{customer}/top-ups");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("createWalletTopUp".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}/top-ups",
)
.await
}
}