payjp_core/charge/
requests.rs

1use payjp_client_core::{PayjpClient, BlockingClient, PayjpRequest, RequestBuilder, PayjpMethod};
2
3#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
4 struct ListChargeBuilder {
5#[serde(skip_serializing_if = "Option::is_none")]
6 limit: Option<i64>,
7#[serde(skip_serializing_if = "Option::is_none")]
8 offset: Option<i64>,
9#[serde(skip_serializing_if = "Option::is_none")]
10 since: Option<i64>,
11#[serde(skip_serializing_if = "Option::is_none")]
12 until: Option<i64>,
13#[serde(skip_serializing_if = "Option::is_none")]
14 customer: Option<String>,
15#[serde(skip_serializing_if = "Option::is_none")]
16 subscription: Option<String>,
17#[serde(skip_serializing_if = "Option::is_none")]
18 tenant: Option<String>,
19#[serde(skip_serializing_if = "Option::is_none")]
20 term: Option<String>,
21
22}
23impl ListChargeBuilder {
24     fn new() -> Self {
25    Self {
26        limit: None,offset: None,since: None,until: None,customer: None,subscription: None,tenant: None,term: None,
27    }
28}
29
30}
31        /// 生成した支払い情報のリストを取得します。
32#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
33pub struct ListCharge {
34 inner: ListChargeBuilder,
35
36}
37impl ListCharge {
38    /// Construct a new `ListCharge`.
39pub fn new() -> Self {
40    Self {
41        inner: ListChargeBuilder::new()
42    }
43}
44    /// 取得するデータ数の最大値(1~100まで)。指定がない場合は 10 となる。
45pub fn limit(mut self, limit: impl Into<i64>) -> Self {
46    self.inner.limit = Some(limit.into());
47    self
48}
49    /// 基準点からのデータ取得を行う開始位置。指定がない場合は 0 となる。
50pub fn offset(mut self, offset: impl Into<i64>) -> Self {
51    self.inner.offset = Some(offset.into());
52    self
53}
54    /// ここに指定したタイムスタンプ以降に作成されたデータを取得
55pub fn since(mut self, since: impl Into<i64>) -> Self {
56    self.inner.since = Some(since.into());
57    self
58}
59    /// ここに指定したタイムスタンプ以前に作成されたデータを取得
60pub fn until(mut self, until: impl Into<i64>) -> Self {
61    self.inner.until = Some(until.into());
62    self
63}
64    /// 絞り込みたい顧客ID
65pub fn customer(mut self, customer: impl Into<String>) -> Self {
66    self.inner.customer = Some(customer.into());
67    self
68}
69    /// 絞り込みたい定期課金ID
70pub fn subscription(mut self, subscription: impl Into<String>) -> Self {
71    self.inner.subscription = Some(subscription.into());
72    self
73}
74    /// [PAY.JP Platform](#platform-api)のみ指定可能
75    ///
76    /// 絞り込みたいテナントID
77pub fn tenant(mut self, tenant: impl Into<String>) -> Self {
78    self.inner.tenant = Some(tenant.into());
79    self
80}
81        /// [入金管理オブジェクトの刷新に伴い、2024/06/01以降に提供されます。](https://pay.jp/docs/migrate-transfer).
82    ///
83    /// 絞り込みたいTermのID
84pub fn term(mut self, term: impl Into<String>) -> Self {
85    self.inner.term = Some(term.into());
86    self
87}
88
89}
90    impl Default for ListCharge {
91    fn default() -> Self {
92        Self::new()
93    }
94}impl ListCharge {
95    /// Send the request and return the deserialized response.
96    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
97        self.customize().send(client).await
98    }
99
100    /// Send the request and return the deserialized response, blocking until completion.
101    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
102        self.customize().send_blocking(client)
103    }
104
105    pub fn paginate(&self) -> payjp_client_core::ListPaginator<payjp_types::List<payjp_core::Charge>> {
106    
107    payjp_client_core::ListPaginator::new_list("/charges", &self.inner)
108}
109
110}
111
112impl PayjpRequest for ListCharge {
113    type Output = payjp_types::List<payjp_core::Charge>;
114
115    fn build(&self) -> RequestBuilder {
116    RequestBuilder::new(PayjpMethod::Get, "/charges").query(&self.inner)
117}
118
119}
120#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
121 struct CreateChargeBuilder {
122#[serde(skip_serializing_if = "Option::is_none")]
123 amount: Option<i64>,
124#[serde(skip_serializing_if = "Option::is_none")]
125 capture: Option<bool>,
126#[serde(skip_serializing_if = "Option::is_none")]
127 card: Option<String>,
128#[serde(skip_serializing_if = "Option::is_none")]
129 currency: Option<String>,
130#[serde(skip_serializing_if = "Option::is_none")]
131 customer: Option<String>,
132#[serde(skip_serializing_if = "Option::is_none")]
133 description: Option<String>,
134#[serde(skip_serializing_if = "Option::is_none")]
135 expiry_days: Option<u32>,
136#[serde(skip_serializing_if = "Option::is_none")]
137#[serde(with = "payjp_types::with_serde_json_opt")]
138 metadata: Option<miniserde::json::Value>,
139#[serde(skip_serializing_if = "Option::is_none")]
140 platform_fee: Option<i64>,
141#[serde(skip_serializing_if = "Option::is_none")]
142 product: Option<String>,
143#[serde(skip_serializing_if = "Option::is_none")]
144 tenant: Option<String>,
145#[serde(skip_serializing_if = "Option::is_none")]
146 three_d_secure: Option<bool>,
147
148}
149impl CreateChargeBuilder {
150     fn new() -> Self {
151    Self {
152        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,
153    }
154}
155
156}
157            /// トークンIDまたはカードを保有している顧客IDを指定して支払いを作成します。.
158        /// テスト用のキーでは、本番用の決済ネットワークへは接続されず、実際の請求が行われることもありません。.
159        /// 本番用のキーでは、決済ネットワークで処理が行われ、実際の請求が行われます。.
160    ///
161        /// 支払いを確定せずに、カードの認証と支払い額のみ確保する場合は、 `capture` に `false` を指定してください。.
162        /// このとき `expiry_days` を指定することで、認証の期間を定めることができます。 `expiry_days` はデフォルトで7日となっており、1日~60日の間で設定が可能です。なお60日に設定した場合、認証期限は59日後の11:59PM(日本時間)までになります。また確保されました与信枠は、`expiry_days` で設定されました期間を過ぎると解放されるようなっております。.
163    ///
164    /// `three_d_secure` にtrueを指定することで、3Dセキュアを開始できます。
165        /// 指定した場合、支払いオブジェクトは作成されますが実際の決済処理は保留された状態になります。.
166        /// 保留中の支払いは、引数指定の内容に関わらず`captured`は`false`、`captured_at`は`null`、`expired_at`は`null`と表示されます。.
167        /// なお、支払い作成から30分を経過すると、3Dセキュアフローはタイムアウトし、処理が進められなくなります。.
168        /// 3Dセキュアの進め方は、 [支払いで3Dセキュアを実施する](https://pay.jp/docs/charge-tds) を参照してください。.
169#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
170pub struct CreateCharge {
171 inner: CreateChargeBuilder,
172
173}
174impl CreateCharge {
175    /// Construct a new `CreateCharge`.
176pub fn new() -> Self {
177    Self {
178        inner: CreateChargeBuilder::new()
179    }
180}
181    /// 50~9,999,999の整数
182pub fn amount(mut self, amount: impl Into<i64>) -> Self {
183    self.inner.amount = Some(amount.into());
184    self
185}
186    /// 支払い処理を確定するかどうか
187pub fn capture(mut self, capture: impl Into<bool>) -> Self {
188    self.inner.capture = Some(capture.into());
189    self
190}
191    /// トークンIDまたはカードID
192pub fn card(mut self, card: impl Into<String>) -> Self {
193    self.inner.card = Some(card.into());
194    self
195}
196    /// 3文字のISOコード(現状 "jpy" のみサポート)
197pub fn currency(mut self, currency: impl Into<String>) -> Self {
198    self.inner.currency = Some(currency.into());
199    self
200}
201    /// 顧客ID
202pub fn customer(mut self, customer: impl Into<String>) -> Self {
203    self.inner.customer = Some(customer.into());
204    self
205}
206    /// 概要
207pub fn description(mut self, description: impl Into<String>) -> Self {
208    self.inner.description = Some(description.into());
209    self
210}
211    /// 認証状態が失効するまでの日数
212pub fn expiry_days(mut self, expiry_days: impl Into<u32>) -> Self {
213    self.inner.expiry_days = Some(expiry_days.into());
214    self
215}
216    /// キーバリューの任意データ
217pub fn metadata(mut self, metadata: impl Into<miniserde::json::Value>) -> Self {
218    self.inner.metadata = Some(metadata.into());
219    self
220}
221    /// [PAY.JP Platform](#platform-api) のみ設定可能
222    ///
223    /// プラットフォーマーに振り分けられる入金金額。
224pub fn platform_fee(mut self, platform_fee: impl Into<i64>) -> Self {
225    self.inner.platform_fee = Some(platform_fee.into());
226    self
227}
228    /// プロダクトID
229pub fn product(mut self, product: impl Into<String>) -> Self {
230    self.inner.product = Some(product.into());
231    self
232}
233    /// [PAY.JP Platform](#platform-api) のみ設定可能
234    ///
235    /// テナントID
236pub fn tenant(mut self, tenant: impl Into<String>) -> Self {
237    self.inner.tenant = Some(tenant.into());
238    self
239}
240    /// 3Dセキュアを行うならtrue
241pub fn three_d_secure(mut self, three_d_secure: impl Into<bool>) -> Self {
242    self.inner.three_d_secure = Some(three_d_secure.into());
243    self
244}
245
246}
247    impl Default for CreateCharge {
248    fn default() -> Self {
249        Self::new()
250    }
251}impl CreateCharge {
252    /// Send the request and return the deserialized response.
253    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
254        self.customize().send(client).await
255    }
256
257    /// Send the request and return the deserialized response, blocking until completion.
258    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
259        self.customize().send_blocking(client)
260    }
261
262    
263}
264
265impl PayjpRequest for CreateCharge {
266    type Output = payjp_core::Charge;
267
268    fn build(&self) -> RequestBuilder {
269    RequestBuilder::new(PayjpMethod::Post, "/charges").form(&self.inner)
270}
271
272}
273    /// 生成された支払い情報を取得します。
274#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
275pub struct RetrieveCharge {
276 charge: payjp_core::ChargeId,
277
278}
279impl RetrieveCharge {
280    /// Construct a new `RetrieveCharge`.
281pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
282    Self {
283        charge: charge.into(),
284    }
285}
286
287}
288    impl RetrieveCharge {
289    /// Send the request and return the deserialized response.
290    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
291        self.customize().send(client).await
292    }
293
294    /// Send the request and return the deserialized response, blocking until completion.
295    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
296        self.customize().send_blocking(client)
297    }
298
299    
300}
301
302impl PayjpRequest for RetrieveCharge {
303    type Output = payjp_core::Charge;
304
305    fn build(&self) -> RequestBuilder {
306    let charge = &self.charge;
307RequestBuilder::new(PayjpMethod::Get, format!("/charges/{charge}"))
308}
309
310}
311#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
312 struct UpdateChargeBuilder {
313#[serde(skip_serializing_if = "Option::is_none")]
314 description: Option<String>,
315#[serde(skip_serializing_if = "Option::is_none")]
316#[serde(with = "payjp_types::with_serde_json_opt")]
317 metadata: Option<miniserde::json::Value>,
318
319}
320impl UpdateChargeBuilder {
321     fn new() -> Self {
322    Self {
323        description: None,metadata: None,
324    }
325}
326
327}
328        /// 支払い情報を更新します。
329#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
330pub struct UpdateCharge {
331 inner: UpdateChargeBuilder,
332 charge: payjp_core::ChargeId,
333
334}
335impl UpdateCharge {
336    /// Construct a new `UpdateCharge`.
337pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
338    Self {
339        charge: charge.into(),inner: UpdateChargeBuilder::new()
340    }
341}
342    /// 概要
343pub fn description(mut self, description: impl Into<String>) -> Self {
344    self.inner.description = Some(description.into());
345    self
346}
347    /// キーバリューの任意データ
348pub fn metadata(mut self, metadata: impl Into<miniserde::json::Value>) -> Self {
349    self.inner.metadata = Some(metadata.into());
350    self
351}
352
353}
354    impl UpdateCharge {
355    /// Send the request and return the deserialized response.
356    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
357        self.customize().send(client).await
358    }
359
360    /// Send the request and return the deserialized response, blocking until completion.
361    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
362        self.customize().send_blocking(client)
363    }
364
365    
366}
367
368impl PayjpRequest for UpdateCharge {
369    type Output = payjp_core::Charge;
370
371    fn build(&self) -> RequestBuilder {
372    let charge = &self.charge;
373RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}")).form(&self.inner)
374}
375
376}
377    /// 3Dセキュア認証が終了した支払いに対し、決済を行います。
378        /// [支払いを作成](#支払いを作成) と同様の決済処理が実行され、実際の請求が行われる状態になります。カードの状態によっては支払いに失敗し、402エラーとなる点も同様です。.
379        /// 保留中の支払いで固定値となっていた`capture`、`captured_at`、`expired_at`は、支払い作成時に指定した通りに反映されます。`captured_at`、`expired_at`の時刻は本APIにリクエストした時刻を基準として設定されます。.
380    ///
381        /// `three_d_secure_status`が`verified`、`attempted`でない支払いに対して本APIをリクエストした場合、エラーとなります。.
382#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
383pub struct TdsFinishCharge {
384 charge: payjp_core::ChargeId,
385
386}
387impl TdsFinishCharge {
388    /// Construct a new `TdsFinishCharge`.
389pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
390    Self {
391        charge: charge.into(),
392    }
393}
394
395}
396    impl TdsFinishCharge {
397    /// Send the request and return the deserialized response.
398    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
399        self.customize().send(client).await
400    }
401
402    /// Send the request and return the deserialized response, blocking until completion.
403    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
404        self.customize().send_blocking(client)
405    }
406
407    
408}
409
410impl PayjpRequest for TdsFinishCharge {
411    type Output = payjp_core::Charge;
412
413    fn build(&self) -> RequestBuilder {
414    let charge = &self.charge;
415RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/tds_finish"))
416}
417
418}
419#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
420 struct RefundChargeBuilder {
421 amount: i64,
422#[serde(skip_serializing_if = "Option::is_none")]
423 refund_reason: Option<String>,
424
425}
426impl RefundChargeBuilder {
427     fn new(amount: impl Into<i64>,) -> Self {
428    Self {
429        amount: amount.into(),refund_reason: None,
430    }
431}
432
433}
434            /// 支払い済みとなった処理を返金します。全額返金、及び `amount` を指定することで金額の部分返金を行うことができます。また確定していない支払いも取り消すことができますが `amount` を指定して部分返金をすることはできません。.
435    ///
436    /// なお返金可能な期限につきましては売上作成より`180日以内`となります。
437#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
438pub struct RefundCharge {
439 inner: RefundChargeBuilder,
440 charge: payjp_core::ChargeId,
441
442}
443impl RefundCharge {
444    /// Construct a new `RefundCharge`.
445pub fn new(charge:impl Into<payjp_core::ChargeId>,amount:impl Into<i64>) -> Self {
446    Self {
447        charge: charge.into(),inner: RefundChargeBuilder::new(amount.into(),)
448    }
449}
450    /// 返金理由 (255文字以内)
451pub fn refund_reason(mut self, refund_reason: impl Into<String>) -> Self {
452    self.inner.refund_reason = Some(refund_reason.into());
453    self
454}
455
456}
457    impl RefundCharge {
458    /// Send the request and return the deserialized response.
459    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
460        self.customize().send(client).await
461    }
462
463    /// Send the request and return the deserialized response, blocking until completion.
464    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
465        self.customize().send_blocking(client)
466    }
467
468    
469}
470
471impl PayjpRequest for RefundCharge {
472    type Output = payjp_core::Charge;
473
474    fn build(&self) -> RequestBuilder {
475    let charge = &self.charge;
476RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/refund")).form(&self.inner)
477}
478
479}
480#[derive(Copy,Clone,Debug,)]#[derive(serde::Serialize)]
481 struct ReauthChargeBuilder {
482#[serde(skip_serializing_if = "Option::is_none")]
483 expiry_days: Option<u32>,
484
485}
486impl ReauthChargeBuilder {
487     fn new() -> Self {
488    Self {
489        expiry_days: None,
490    }
491}
492
493}
494        /// **各種SDKは順次対応予定です**
495    ///
496        /// 認証状態となった処理待ちの支払いを再認証します。 `captured="false"` の支払いが対象です。.
497        /// `expiry_days` を指定することで、新たな認証の期間を定めることができます。 `expiry_days` はデフォルトで7日となっており、1日~60日の間で設定が可能です。なお60日に設定した場合、認証期限は59日後の11:59PM(日本時間)までになります。.
498    ///
499        /// **再認証が必要な場合は認証状態の charge を[返金し](#返金する)、新たに[支払いを作成](#支払いを作成) することを推奨いたします。**.
500    ///
501        /// このAPIは認証済みの与信をキャンセルせず別の与信を作るため、同じ金額で認証済みでも失敗したり、デビットカードなどでは一度目の認証(capture=falseの支払い)と含めて二重に金額が引き落とされることがあります。.
502#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
503pub struct ReauthCharge {
504 inner: ReauthChargeBuilder,
505 charge: payjp_core::ChargeId,
506
507}
508impl ReauthCharge {
509    /// Construct a new `ReauthCharge`.
510pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
511    Self {
512        charge: charge.into(),inner: ReauthChargeBuilder::new()
513    }
514}
515    /// 認証状態が失効するまでの日数
516pub fn expiry_days(mut self, expiry_days: impl Into<u32>) -> Self {
517    self.inner.expiry_days = Some(expiry_days.into());
518    self
519}
520
521}
522    impl ReauthCharge {
523    /// Send the request and return the deserialized response.
524    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
525        self.customize().send(client).await
526    }
527
528    /// Send the request and return the deserialized response, blocking until completion.
529    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
530        self.customize().send_blocking(client)
531    }
532
533    
534}
535
536impl PayjpRequest for ReauthCharge {
537    type Output = payjp_core::Charge;
538
539    fn build(&self) -> RequestBuilder {
540    let charge = &self.charge;
541RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/reauth")).form(&self.inner)
542}
543
544}
545#[derive(Copy,Clone,Debug,)]#[derive(serde::Serialize)]
546 struct CaptureChargeBuilder {
547#[serde(skip_serializing_if = "Option::is_none")]
548 amount: Option<i64>,
549
550}
551impl CaptureChargeBuilder {
552     fn new() -> Self {
553    Self {
554        amount: None,
555    }
556}
557
558}
559            /// 認証状態となった処理待ちの支払い処理を確定させます。具体的には `captured="false"` となった支払いが該当します。.
560#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
561pub struct CaptureCharge {
562 inner: CaptureChargeBuilder,
563 charge: payjp_core::ChargeId,
564
565}
566impl CaptureCharge {
567    /// Construct a new `CaptureCharge`.
568pub fn new(charge:impl Into<payjp_core::ChargeId>) -> Self {
569    Self {
570        charge: charge.into(),inner: CaptureChargeBuilder::new()
571    }
572}
573    /// 50~9,999,999の整数
574    ///
575        /// これをセットすることで、支払い生成時の金額と異なる金額の支払い処理を行うことができます。.
576        /// ただし支払い生成時の金額よりも少額である必要があるためご注意ください。.
577    ///
578        /// セットした場合、レスポンスの `amount_refunded` に認証時の `amount` との差額が入ります。.
579        /// 例えば、認証時に `amount=500` で作成し、 `amount=400` で支払い確定を行った場合、 `amount_refunded=100` となり、確定金額が400円に変更された状態で支払いが確定されます。.
580pub fn amount(mut self, amount: impl Into<i64>) -> Self {
581    self.inner.amount = Some(amount.into());
582    self
583}
584
585}
586    impl CaptureCharge {
587    /// Send the request and return the deserialized response.
588    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
589        self.customize().send(client).await
590    }
591
592    /// Send the request and return the deserialized response, blocking until completion.
593    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
594        self.customize().send_blocking(client)
595    }
596
597    
598}
599
600impl PayjpRequest for CaptureCharge {
601    type Output = payjp_core::Charge;
602
603    fn build(&self) -> RequestBuilder {
604    let charge = &self.charge;
605RequestBuilder::new(PayjpMethod::Post, format!("/charges/{charge}/capture")).form(&self.inner)
606}
607
608}
609