tosspayments/api/
cancel_payment.rs1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3use typed_builder::TypedBuilder;
4
5use crate::data::{Account, Payment};
6use crate::endpoint::Endpoint;
7
8#[derive(Clone, Debug, Serialize, Deserialize, TypedBuilder)]
9#[serde(rename_all = "camelCase")]
10pub struct CancelPayment {
11 pub payment_key: String,
12 pub body: CancelPaymentBody,
13 #[builder(default)]
14 pub idempotency_key: Option<String>,
15}
16
17#[derive(Clone, Debug, Serialize, Deserialize, TypedBuilder)]
18#[serde(rename_all = "camelCase")]
19pub struct CancelPaymentBody {
20 pub cancel_reason: String,
21 #[builder(default)]
22 pub cancel_amount: Option<i32>,
23 #[builder(default)]
24 pub refund_receive_account: Option<Account>,
25 #[builder(default)]
26 pub tax_free_amount: Option<i32>,
27}
28
29impl Endpoint for CancelPayment {
30 type Query = ();
31 type Body = CancelPaymentBody;
32 type Response = Payment;
33
34 fn relative_path(&self) -> String {
35 format!("/v1/payments/{}/cancel", self.payment_key)
36 }
37
38 fn method(&self) -> Method {
39 Method::POST
40 }
41
42 fn body(&self) -> Option<&Self::Body> {
43 Some(&self.body)
44 }
45
46 fn idempotency_key(&self) -> Option<String> {
47 self.idempotency_key.clone()
48 }
49}