use payjp_client_core::{PayjpClient, BlockingClient, PayjpRequest, RequestBuilder, PayjpMethod};
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
struct ListChargeBuilder {
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
offset: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
since: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
until: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
customer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
subscription: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tenant: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
term: Option<String>,
}
impl ListChargeBuilder {
fn new() -> Self {
Self {
limit: None,offset: None,since: None,until: None,customer: None,subscription: None,tenant: None,term: None,
}
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct ListCharge {
inner: ListChargeBuilder,
}
impl ListCharge {
pub fn new() -> Self {
Self {
inner: ListChargeBuilder::new()
}
}
pub fn limit(mut self, limit: impl Into<i64>) -> Self {
self.inner.limit = Some(limit.into());
self
}
pub fn offset(mut self, offset: impl Into<i64>) -> Self {
self.inner.offset = Some(offset.into());
self
}
pub fn since(mut self, since: impl Into<i64>) -> Self {
self.inner.since = Some(since.into());
self
}
pub fn until(mut self, until: impl Into<i64>) -> Self {
self.inner.until = Some(until.into());
self
}
pub fn customer(mut self, customer: impl Into<String>) -> Self {
self.inner.customer = Some(customer.into());
self
}
pub fn subscription(mut self, subscription: impl Into<String>) -> Self {
self.inner.subscription = Some(subscription.into());
self
}
pub fn tenant(mut self, tenant: impl Into<String>) -> Self {
self.inner.tenant = Some(tenant.into());
self
}
pub fn term(mut self, term: impl Into<String>) -> Self {
self.inner.term = Some(term.into());
self
}
}
impl Default for ListCharge {
fn default() -> Self {
Self::new()
}
}impl ListCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
pub fn paginate(&self) -> payjp_client_core::ListPaginator<payjp_types::List<payjp_core::Charge>> {
payjp_client_core::ListPaginator::new_list("/charges", &self.inner)
}
}
impl PayjpRequest for ListCharge {
type Output = payjp_types::List<payjp_core::Charge>;
fn build(&self) -> RequestBuilder {
RequestBuilder::new(PayjpMethod::Get, "/charges").query(&self.inner)
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
struct CreateChargeBuilder {
#[serde(skip_serializing_if = "Option::is_none")]
amount: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
capture: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
card: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
currency: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
customer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
expiry_days: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(with = "payjp_types::with_serde_json_opt")]
metadata: Option<miniserde::json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
platform_fee: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
product: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tenant: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
three_d_secure: Option<bool>,
}
impl CreateChargeBuilder {
fn new() -> Self {
Self {
amount: None,capture: None,card: None,currency: None,customer: None,description: None,expiry_days: None,metadata: None,platform_fee: None,product: None,tenant: None,three_d_secure: None,
}
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct CreateCharge {
inner: CreateChargeBuilder,
}
impl CreateCharge {
pub fn new() -> Self {
Self {
inner: CreateChargeBuilder::new()
}
}
pub fn amount(mut self, amount: impl Into<i64>) -> Self {
self.inner.amount = Some(amount.into());
self
}
pub fn capture(mut self, capture: impl Into<bool>) -> Self {
self.inner.capture = Some(capture.into());
self
}
pub fn card(mut self, card: impl Into<String>) -> Self {
self.inner.card = Some(card.into());
self
}
pub fn currency(mut self, currency: impl Into<String>) -> Self {
self.inner.currency = Some(currency.into());
self
}
pub fn customer(mut self, customer: impl Into<String>) -> Self {
self.inner.customer = Some(customer.into());
self
}
pub fn description(mut self, description: impl Into<String>) -> Self {
self.inner.description = Some(description.into());
self
}
pub fn expiry_days(mut self, expiry_days: impl Into<u32>) -> Self {
self.inner.expiry_days = Some(expiry_days.into());
self
}
pub fn metadata(mut self, metadata: impl Into<miniserde::json::Value>) -> Self {
self.inner.metadata = Some(metadata.into());
self
}
pub fn platform_fee(mut self, platform_fee: impl Into<i64>) -> Self {
self.inner.platform_fee = Some(platform_fee.into());
self
}
pub fn product(mut self, product: impl Into<String>) -> Self {
self.inner.product = Some(product.into());
self
}
pub fn tenant(mut self, tenant: impl Into<String>) -> Self {
self.inner.tenant = Some(tenant.into());
self
}
pub fn three_d_secure(mut self, three_d_secure: impl Into<bool>) -> Self {
self.inner.three_d_secure = Some(three_d_secure.into());
self
}
}
impl Default for CreateCharge {
fn default() -> Self {
Self::new()
}
}impl CreateCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for CreateCharge {
type Output = payjp_core::Charge;
fn build(&self) -> RequestBuilder {
RequestBuilder::new(PayjpMethod::Post, "/charges").form(&self.inner)
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct RetrieveCharge {
charge: payjp_core::ChargeId,
}
impl RetrieveCharge {
pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
Self {
charge: charge.into(),
}
}
}
impl RetrieveCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for RetrieveCharge {
type Output = payjp_core::Charge;
fn build(&self) -> RequestBuilder {
let charge = &self.charge;
RequestBuilder::new(PayjpMethod::Get, format!("/charges/{charge}"))
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
struct UpdateChargeBuilder {
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(with = "payjp_types::with_serde_json_opt")]
metadata: Option<miniserde::json::Value>,
}
impl UpdateChargeBuilder {
fn new() -> Self {
Self {
description: None,metadata: None,
}
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct UpdateCharge {
inner: UpdateChargeBuilder,
charge: payjp_core::ChargeId,
}
impl UpdateCharge {
pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
Self {
charge: charge.into(),inner: UpdateChargeBuilder::new()
}
}
pub fn description(mut self, description: impl Into<String>) -> Self {
self.inner.description = Some(description.into());
self
}
pub fn metadata(mut self, metadata: impl Into<miniserde::json::Value>) -> Self {
self.inner.metadata = Some(metadata.into());
self
}
}
impl UpdateCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for UpdateCharge {
type Output = payjp_core::Charge;
fn build(&self) -> RequestBuilder {
let charge = &self.charge;
RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}")).form(&self.inner)
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct TdsFinishCharge {
charge: payjp_core::ChargeId,
}
impl TdsFinishCharge {
pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
Self {
charge: charge.into(),
}
}
}
impl TdsFinishCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for TdsFinishCharge {
type Output = payjp_core::Charge;
fn build(&self) -> RequestBuilder {
let charge = &self.charge;
RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/tds_finish"))
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
struct RefundChargeBuilder {
amount: i64,
#[serde(skip_serializing_if = "Option::is_none")]
refund_reason: Option<String>,
}
impl RefundChargeBuilder {
fn new(amount: impl Into<i64>,) -> Self {
Self {
amount: amount.into(),refund_reason: None,
}
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct RefundCharge {
inner: RefundChargeBuilder,
charge: payjp_core::ChargeId,
}
impl RefundCharge {
pub fn new(charge:impl Into<payjp_core::ChargeId>,amount:impl Into<i64>) -> Self {
Self {
charge: charge.into(),inner: RefundChargeBuilder::new(amount.into(),)
}
}
pub fn refund_reason(mut self, refund_reason: impl Into<String>) -> Self {
self.inner.refund_reason = Some(refund_reason.into());
self
}
}
impl RefundCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for RefundCharge {
type Output = payjp_core::Charge;
fn build(&self) -> RequestBuilder {
let charge = &self.charge;
RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/refund")).form(&self.inner)
}
}
#[derive(Copy,Clone,Debug,)]#[derive(serde::Serialize)]
struct ReauthChargeBuilder {
#[serde(skip_serializing_if = "Option::is_none")]
expiry_days: Option<u32>,
}
impl ReauthChargeBuilder {
fn new() -> Self {
Self {
expiry_days: None,
}
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct ReauthCharge {
inner: ReauthChargeBuilder,
charge: payjp_core::ChargeId,
}
impl ReauthCharge {
pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
Self {
charge: charge.into(),inner: ReauthChargeBuilder::new()
}
}
pub fn expiry_days(mut self, expiry_days: impl Into<u32>) -> Self {
self.inner.expiry_days = Some(expiry_days.into());
self
}
}
impl ReauthCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for ReauthCharge {
type Output = payjp_core::Charge;
fn build(&self) -> RequestBuilder {
let charge = &self.charge;
RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/reauth")).form(&self.inner)
}
}
#[derive(Copy,Clone,Debug,)]#[derive(serde::Serialize)]
struct CaptureChargeBuilder {
#[serde(skip_serializing_if = "Option::is_none")]
amount: Option<i64>,
}
impl CaptureChargeBuilder {
fn new() -> Self {
Self {
amount: None,
}
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct CaptureCharge {
inner: CaptureChargeBuilder,
charge: payjp_core::ChargeId,
}
impl CaptureCharge {
pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
Self {
charge: charge.into(),inner: CaptureChargeBuilder::new()
}
}
pub fn amount(mut self, amount: impl Into<i64>) -> Self {
self.inner.amount = Some(amount.into());
self
}
}
impl CaptureCharge {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for CaptureCharge {
type Output = payjp_core::Charge;
fn build(&self) -> RequestBuilder {
let charge = &self.charge;
RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/capture")).form(&self.inner)
}
}