payjp_core/token/
requests.rs

1use payjp_client_core::{PayjpClient, BlockingClient, PayjpRequest, RequestBuilder, PayjpMethod};
2
3#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
4 struct CreateTokenBuilder {
5#[serde(rename = "card[address_city]")]
6#[serde(skip_serializing_if = "Option::is_none")]
7 card_address_city: Option<String>,
8#[serde(rename = "card[address_line1]")]
9#[serde(skip_serializing_if = "Option::is_none")]
10 card_address_line1: Option<String>,
11#[serde(rename = "card[address_line2]")]
12#[serde(skip_serializing_if = "Option::is_none")]
13 card_address_line2: Option<String>,
14#[serde(rename = "card[address_state]")]
15#[serde(skip_serializing_if = "Option::is_none")]
16 card_address_state: Option<String>,
17#[serde(rename = "card[address_zip]")]
18#[serde(skip_serializing_if = "Option::is_none")]
19 card_address_zip: Option<String>,
20#[serde(rename = "card[country]")]
21#[serde(skip_serializing_if = "Option::is_none")]
22 card_country: Option<String>,
23#[serde(rename = "card[cvc]")]
24 card_cvc: String,
25#[serde(rename = "card[email]")]
26#[serde(skip_serializing_if = "Option::is_none")]
27 card_email: Option<String>,
28#[serde(rename = "card[exp_month]")]
29 card_exp_month: String,
30#[serde(rename = "card[exp_year]")]
31 card_exp_year: String,
32#[serde(rename = "card[name]")]
33 card_name: String,
34#[serde(rename = "card[number]")]
35 card_number: String,
36#[serde(rename = "card[phone]")]
37#[serde(skip_serializing_if = "Option::is_none")]
38 card_phone: Option<String>,
39#[serde(skip_serializing_if = "Option::is_none")]
40 tenant: Option<String>,
41#[serde(skip_serializing_if = "Option::is_none")]
42 three_d_secure: Option<bool>,
43
44}
45impl CreateTokenBuilder {
46     fn new(card_cvc: impl Into<String>,card_exp_month: impl Into<String>,card_exp_year: impl Into<String>,card_name: impl Into<String>,card_number: impl Into<String>,) -> Self {
47    Self {
48        card_address_city: None,card_address_line1: None,card_address_line2: None,card_address_state: None,card_address_zip: None,card_country: None,card_cvc: card_cvc.into(),card_email: None,card_exp_month: card_exp_month.into(),card_exp_year: card_exp_year.into(),card_name: card_name.into(),card_number: card_number.into(),card_phone: None,tenant: None,three_d_secure: None,
49    }
50}
51
52}
53        /// Create new token
54#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
55pub struct CreateToken {
56 inner: CreateTokenBuilder,
57
58}
59impl CreateToken {
60    /// Construct a new `CreateToken`.
61pub fn new(card_cvc:impl Into<String>,card_exp_month:impl Into<String>,card_exp_year:impl Into<String>,card_name:impl Into<String>,card_number:impl Into<String>) -> Self {
62    Self {
63        inner: CreateTokenBuilder::new(card_cvc.into(),card_exp_month.into(),card_exp_year.into(),card_name.into(),card_number.into(),)
64    }
65}
66pub fn card_address_city(mut self, card_address_city: impl Into<String>) -> Self {
67    self.inner.card_address_city = Some(card_address_city.into());
68    self
69}
70pub fn card_address_line1(mut self, card_address_line1: impl Into<String>) -> Self {
71    self.inner.card_address_line1 = Some(card_address_line1.into());
72    self
73}
74pub fn card_address_line2(mut self, card_address_line2: impl Into<String>) -> Self {
75    self.inner.card_address_line2 = Some(card_address_line2.into());
76    self
77}
78pub fn card_address_state(mut self, card_address_state: impl Into<String>) -> Self {
79    self.inner.card_address_state = Some(card_address_state.into());
80    self
81}
82pub fn card_address_zip(mut self, card_address_zip: impl Into<String>) -> Self {
83    self.inner.card_address_zip = Some(card_address_zip.into());
84    self
85}
86pub fn card_country(mut self, card_country: impl Into<String>) -> Self {
87    self.inner.card_country = Some(card_country.into());
88    self
89}
90    /// メールアドレス
91        /// 2024年8月以降、3Dセキュア認証の際にphoneまたはemailのデータ入力が求められます。.
92pub fn card_email(mut self, card_email: impl Into<String>) -> Self {
93    self.inner.card_email = Some(card_email.into());
94    self
95}
96    /// E.164形式の電話番号 (e.g. 090-0123-4567(日本) => "+819001234567")
97        /// 2024年8月以降、3Dセキュア認証の際にphoneまたはemailのデータ入力が求められます。.
98pub fn card_phone(mut self, card_phone: impl Into<String>) -> Self {
99    self.inner.card_phone = Some(card_phone.into());
100    self
101}
102    /// テナントID
103pub fn tenant(mut self, tenant: impl Into<String>) -> Self {
104    self.inner.tenant = Some(tenant.into());
105    self
106}
107    /// 3Dセキュアを開始するかどうか
108        /// 管理画面でトークン3Dセキュアを実施するモードが有効になっている時は無視されます。.
109pub fn three_d_secure(mut self, three_d_secure: impl Into<bool>) -> Self {
110    self.inner.three_d_secure = Some(three_d_secure.into());
111    self
112}
113
114}
115    impl CreateToken {
116    /// Send the request and return the deserialized response.
117    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
118        self.customize().send(client).await
119    }
120
121    /// Send the request and return the deserialized response, blocking until completion.
122    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
123        self.customize().send_blocking(client)
124    }
125
126    
127}
128
129impl PayjpRequest for CreateToken {
130    type Output = payjp_core::Token;
131
132    fn build(&self) -> RequestBuilder {
133    RequestBuilder::new(PayjpMethod::Post, "/tokens").form(&self.inner)
134}
135
136}
137    /// Info for a specific token
138#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
139pub struct RetrieveToken {
140 token: payjp_core::TokenId,
141
142}
143impl RetrieveToken {
144    /// Construct a new `RetrieveToken`.
145pub fn new(token:impl Into<payjp_core::TokenId>) -> Self {
146    Self {
147        token: token.into(),
148    }
149}
150
151}
152    impl RetrieveToken {
153    /// Send the request and return the deserialized response.
154    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
155        self.customize().send(client).await
156    }
157
158    /// Send the request and return the deserialized response, blocking until completion.
159    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
160        self.customize().send_blocking(client)
161    }
162
163    
164}
165
166impl PayjpRequest for RetrieveToken {
167    type Output = payjp_core::Token;
168
169    fn build(&self) -> RequestBuilder {
170    let token = &self.token;
171RequestBuilder::new(PayjpMethod::Get, format!("/tokens/{token}"))
172}
173
174}
175