payjp_core/
merchant.rs

1/// Merchantオブジェクト
2///
3/// For more details see <<https://pay.jp/docs/api>>.
4#[derive(Clone,Debug,)]#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct Merchant {
6    /// 入金先銀行口座情報が設定済みかどうか
7pub bank_enabled: bool,
8    /// 本番環境で利用可能なカードブランドのリスト
9pub brands_accepted: Vec<MerchantBrandsAccepted>,
10    /// 業務形態
11pub business_type: Option<String>,
12    /// 支払い方法種別のリスト
13pub charge_type: Option<Vec<String>>,
14    /// 所在国
15pub country: String,
16    /// 登録日時
17pub created: i64,
18    /// 対応通貨のリスト
19pub currencies_supported: Vec<MerchantCurrenciesSupported>,
20    /// 3文字のISOコード(現状 "jpy" のみサポート)
21pub default_currency: MerchantDefaultCurrency,
22    /// 本番環境申請情報が提出済みかどうか
23pub details_submitted: bool,
24    /// acct_mch_で始まる一意なオブジェクトを示す文字列
25pub id: payjp_core::MerchantId,
26    /// 本番環境が許可された日時のUTCタイムスタンプ
27pub livemode_activated_at: Option<i64>,
28    /// 本番環境が有効かどうか
29pub livemode_enabled: bool,
30    /// 販売商品名
31pub product_name: Option<String>,
32    /// 販売商品の種類リスト
33pub product_type: Option<Vec<String>>,
34    /// 申請対象のサイトがオープン済みかどうか
35pub site_published: Option<bool>,
36
37}
38#[doc(hidden)]
39pub struct MerchantBuilder {
40    bank_enabled: Option<bool>,
41brands_accepted: Option<Vec<MerchantBrandsAccepted>>,
42business_type: Option<Option<String>>,
43charge_type: Option<Option<Vec<String>>>,
44country: Option<String>,
45created: Option<i64>,
46currencies_supported: Option<Vec<MerchantCurrenciesSupported>>,
47default_currency: Option<MerchantDefaultCurrency>,
48details_submitted: Option<bool>,
49id: Option<payjp_core::MerchantId>,
50livemode_activated_at: Option<Option<i64>>,
51livemode_enabled: Option<bool>,
52product_name: Option<Option<String>>,
53product_type: Option<Option<Vec<String>>>,
54site_published: Option<Option<bool>>,
55
56}
57
58#[allow(unused_variables, irrefutable_let_patterns, clippy::let_unit_value, clippy::match_single_binding, clippy::single_match)]
59const _: () = {
60    use miniserde::de::{Map, Visitor};
61    use miniserde::json::Value;
62    use miniserde::{make_place, Deserialize, Result};
63    use payjp_types::{MapBuilder, ObjectDeser};
64    use payjp_types::miniserde_helpers::FromValueOpt;
65
66    make_place!(Place);
67
68    impl Deserialize for Merchant {
69    fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
70       Place::new(out)
71    }
72}
73
74struct Builder<'a> {
75    out: &'a mut Option<Merchant>,
76    builder: MerchantBuilder,
77}
78
79impl Visitor for Place<Merchant> {
80    fn map(&mut self) -> Result<Box<dyn Map + '_>> {
81        Ok(Box::new(Builder {
82            out: &mut self.out,
83            builder: MerchantBuilder::deser_default(),
84        }))
85    }
86}
87
88impl MapBuilder for MerchantBuilder {
89    type Out = Merchant;
90    fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
91        Ok(match k {
92            "bank_enabled" => Deserialize::begin(&mut self.bank_enabled),
93"brands_accepted" => Deserialize::begin(&mut self.brands_accepted),
94"business_type" => Deserialize::begin(&mut self.business_type),
95"charge_type" => Deserialize::begin(&mut self.charge_type),
96"country" => Deserialize::begin(&mut self.country),
97"created" => Deserialize::begin(&mut self.created),
98"currencies_supported" => Deserialize::begin(&mut self.currencies_supported),
99"default_currency" => Deserialize::begin(&mut self.default_currency),
100"details_submitted" => Deserialize::begin(&mut self.details_submitted),
101"id" => Deserialize::begin(&mut self.id),
102"livemode_activated_at" => Deserialize::begin(&mut self.livemode_activated_at),
103"livemode_enabled" => Deserialize::begin(&mut self.livemode_enabled),
104"product_name" => Deserialize::begin(&mut self.product_name),
105"product_type" => Deserialize::begin(&mut self.product_type),
106"site_published" => Deserialize::begin(&mut self.site_published),
107
108            _ => <dyn Visitor>::ignore(),
109        })
110    }
111
112    fn deser_default() -> Self {
113        Self {
114            bank_enabled: Deserialize::default(),
115brands_accepted: Deserialize::default(),
116business_type: Deserialize::default(),
117charge_type: Deserialize::default(),
118country: Deserialize::default(),
119created: Deserialize::default(),
120currencies_supported: Deserialize::default(),
121default_currency: Deserialize::default(),
122details_submitted: Deserialize::default(),
123id: Deserialize::default(),
124livemode_activated_at: Deserialize::default(),
125livemode_enabled: Deserialize::default(),
126product_name: Deserialize::default(),
127product_type: Deserialize::default(),
128site_published: Deserialize::default(),
129
130        }
131    }
132
133    fn take_out(&mut self) -> Option<Self::Out> {
134        let (Some(bank_enabled),
135Some(brands_accepted),
136Some(business_type),
137Some(charge_type),
138Some(country),
139Some(created),
140Some(currencies_supported),
141Some(default_currency),
142Some(details_submitted),
143Some(id),
144Some(livemode_activated_at),
145Some(livemode_enabled),
146Some(product_name),
147Some(product_type),
148Some(site_published),
149) = (self.bank_enabled,
150self.brands_accepted.take(),
151self.business_type.take(),
152self.charge_type.take(),
153self.country.take(),
154self.created,
155self.currencies_supported.take(),
156self.default_currency,
157self.details_submitted,
158self.id.take(),
159self.livemode_activated_at,
160self.livemode_enabled,
161self.product_name.take(),
162self.product_type.take(),
163self.site_published,
164) else {
165            return None;
166        };
167        Some(Self::Out { bank_enabled,brands_accepted,business_type,charge_type,country,created,currencies_supported,default_currency,details_submitted,id,livemode_activated_at,livemode_enabled,product_name,product_type,site_published })
168    }
169}
170
171impl<'a> Map for Builder<'a> {
172    fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
173        self.builder.key(k)
174    }
175
176    fn finish(&mut self) -> Result<()> {
177        *self.out = self.builder.take_out();
178        Ok(())
179    }
180}
181
182impl ObjectDeser for Merchant {
183    type Builder = MerchantBuilder;
184}
185
186impl FromValueOpt for Merchant {
187    fn from_value(v: Value) -> Option<Self> {
188        let Value::Object(obj) = v else {
189            return None;
190        };
191        let mut b = MerchantBuilder::deser_default();
192        for (k, v) in obj {
193            match k.as_str() {
194                "bank_enabled" => b.bank_enabled = FromValueOpt::from_value(v),
195"brands_accepted" => b.brands_accepted = FromValueOpt::from_value(v),
196"business_type" => b.business_type = FromValueOpt::from_value(v),
197"charge_type" => b.charge_type = FromValueOpt::from_value(v),
198"country" => b.country = FromValueOpt::from_value(v),
199"created" => b.created = FromValueOpt::from_value(v),
200"currencies_supported" => b.currencies_supported = FromValueOpt::from_value(v),
201"default_currency" => b.default_currency = FromValueOpt::from_value(v),
202"details_submitted" => b.details_submitted = FromValueOpt::from_value(v),
203"id" => b.id = FromValueOpt::from_value(v),
204"livemode_activated_at" => b.livemode_activated_at = FromValueOpt::from_value(v),
205"livemode_enabled" => b.livemode_enabled = FromValueOpt::from_value(v),
206"product_name" => b.product_name = FromValueOpt::from_value(v),
207"product_type" => b.product_type = FromValueOpt::from_value(v),
208"site_published" => b.site_published = FromValueOpt::from_value(v),
209
210                _ => {}
211            }
212        }
213        b.take_out()
214    }
215}
216
217};
218#[cfg(feature = "serialize")]
219impl serde::Serialize for Merchant {
220    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
221        use serde::ser::SerializeStruct;
222        let mut s = s.serialize_struct("Merchant", 16)?;
223        s.serialize_field("bank_enabled", &self.bank_enabled)?;
224s.serialize_field("brands_accepted", &self.brands_accepted)?;
225s.serialize_field("business_type", &self.business_type)?;
226s.serialize_field("charge_type", &self.charge_type)?;
227s.serialize_field("country", &self.country)?;
228s.serialize_field("created", &self.created)?;
229s.serialize_field("currencies_supported", &self.currencies_supported)?;
230s.serialize_field("default_currency", &self.default_currency)?;
231s.serialize_field("details_submitted", &self.details_submitted)?;
232s.serialize_field("id", &self.id)?;
233s.serialize_field("livemode_activated_at", &self.livemode_activated_at)?;
234s.serialize_field("livemode_enabled", &self.livemode_enabled)?;
235s.serialize_field("product_name", &self.product_name)?;
236s.serialize_field("product_type", &self.product_type)?;
237s.serialize_field("site_published", &self.site_published)?;
238
239        s.serialize_field("object", "merchant")?;
240        s.end()
241    }
242}
243/// 本番環境で利用可能なカードブランドのリスト
244#[derive(Copy,Clone,Eq, PartialEq,)]pub enum MerchantBrandsAccepted {
245Visa,
246MasterCard,
247Jcb,
248AmericanExpress,
249DinersClub,
250Discover,
251
252}
253impl MerchantBrandsAccepted {
254    pub fn as_str(self) -> &'static str {
255        use MerchantBrandsAccepted::*;
256        match self {
257Visa => "Visa",
258MasterCard => "MasterCard",
259Jcb => "JCB",
260AmericanExpress => "American Express",
261DinersClub => "Diners Club",
262Discover => "Discover",
263
264        }
265    }
266}
267
268impl std::str::FromStr for MerchantBrandsAccepted {
269    type Err = payjp_types::ParseError;
270    fn from_str(s: &str) -> Result<Self, Self::Err> {
271        use MerchantBrandsAccepted::*;
272        match s {
273    "Visa" => Ok(Visa),
274"MasterCard" => Ok(MasterCard),
275"JCB" => Ok(Jcb),
276"American Express" => Ok(AmericanExpress),
277"Diners Club" => Ok(DinersClub),
278"Discover" => Ok(Discover),
279_ => Err(payjp_types::ParseError)
280
281        }
282    }
283}
284impl std::fmt::Display for MerchantBrandsAccepted {
285    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
286        f.write_str(self.as_str())
287    }
288}
289
290impl std::fmt::Debug for MerchantBrandsAccepted {
291    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
292        f.write_str(self.as_str())
293    }
294}
295#[cfg(feature = "serialize")]
296impl serde::Serialize for MerchantBrandsAccepted {
297    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
298        serializer.serialize_str(self.as_str())
299    }
300}
301impl miniserde::Deserialize for MerchantBrandsAccepted {
302    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
303        crate::Place::new(out)
304    }
305}
306
307impl miniserde::de::Visitor for crate::Place<MerchantBrandsAccepted> {
308    fn string(&mut self, s: &str) -> miniserde::Result<()> {
309        use std::str::FromStr;
310        self.out = Some(MerchantBrandsAccepted::from_str(s).map_err(|_| miniserde::Error)?);
311        Ok(())
312    }
313}
314
315payjp_types::impl_from_val_with_from_str!(MerchantBrandsAccepted);
316#[cfg(feature = "deserialize")]
317impl<'de> serde::Deserialize<'de> for MerchantBrandsAccepted {
318    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
319        use std::str::FromStr;
320        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
321        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for MerchantBrandsAccepted"))
322    }
323}
324/// 対応通貨のリスト
325#[derive(Copy,Clone,Eq, PartialEq,)]pub enum MerchantCurrenciesSupported {
326Jpy,
327
328}
329impl MerchantCurrenciesSupported {
330    pub fn as_str(self) -> &'static str {
331        use MerchantCurrenciesSupported::*;
332        match self {
333Jpy => "jpy",
334
335        }
336    }
337}
338
339impl std::str::FromStr for MerchantCurrenciesSupported {
340    type Err = payjp_types::ParseError;
341    fn from_str(s: &str) -> Result<Self, Self::Err> {
342        use MerchantCurrenciesSupported::*;
343        match s {
344    "jpy" => Ok(Jpy),
345_ => Err(payjp_types::ParseError)
346
347        }
348    }
349}
350impl std::fmt::Display for MerchantCurrenciesSupported {
351    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
352        f.write_str(self.as_str())
353    }
354}
355
356impl std::fmt::Debug for MerchantCurrenciesSupported {
357    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
358        f.write_str(self.as_str())
359    }
360}
361#[cfg(feature = "serialize")]
362impl serde::Serialize for MerchantCurrenciesSupported {
363    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
364        serializer.serialize_str(self.as_str())
365    }
366}
367impl miniserde::Deserialize for MerchantCurrenciesSupported {
368    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
369        crate::Place::new(out)
370    }
371}
372
373impl miniserde::de::Visitor for crate::Place<MerchantCurrenciesSupported> {
374    fn string(&mut self, s: &str) -> miniserde::Result<()> {
375        use std::str::FromStr;
376        self.out = Some(MerchantCurrenciesSupported::from_str(s).map_err(|_| miniserde::Error)?);
377        Ok(())
378    }
379}
380
381payjp_types::impl_from_val_with_from_str!(MerchantCurrenciesSupported);
382#[cfg(feature = "deserialize")]
383impl<'de> serde::Deserialize<'de> for MerchantCurrenciesSupported {
384    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
385        use std::str::FromStr;
386        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
387        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for MerchantCurrenciesSupported"))
388    }
389}
390/// 3文字のISOコード(現状 "jpy" のみサポート)
391#[derive(Copy,Clone,Eq, PartialEq,)]pub enum MerchantDefaultCurrency {
392Jpy,
393
394}
395impl MerchantDefaultCurrency {
396    pub fn as_str(self) -> &'static str {
397        use MerchantDefaultCurrency::*;
398        match self {
399Jpy => "jpy",
400
401        }
402    }
403}
404
405impl std::str::FromStr for MerchantDefaultCurrency {
406    type Err = payjp_types::ParseError;
407    fn from_str(s: &str) -> Result<Self, Self::Err> {
408        use MerchantDefaultCurrency::*;
409        match s {
410    "jpy" => Ok(Jpy),
411_ => Err(payjp_types::ParseError)
412
413        }
414    }
415}
416impl std::fmt::Display for MerchantDefaultCurrency {
417    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
418        f.write_str(self.as_str())
419    }
420}
421
422impl std::fmt::Debug for MerchantDefaultCurrency {
423    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
424        f.write_str(self.as_str())
425    }
426}
427#[cfg(feature = "serialize")]
428impl serde::Serialize for MerchantDefaultCurrency {
429    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
430        serializer.serialize_str(self.as_str())
431    }
432}
433impl miniserde::Deserialize for MerchantDefaultCurrency {
434    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
435        crate::Place::new(out)
436    }
437}
438
439impl miniserde::de::Visitor for crate::Place<MerchantDefaultCurrency> {
440    fn string(&mut self, s: &str) -> miniserde::Result<()> {
441        use std::str::FromStr;
442        self.out = Some(MerchantDefaultCurrency::from_str(s).map_err(|_| miniserde::Error)?);
443        Ok(())
444    }
445}
446
447payjp_types::impl_from_val_with_from_str!(MerchantDefaultCurrency);
448#[cfg(feature = "deserialize")]
449impl<'de> serde::Deserialize<'de> for MerchantDefaultCurrency {
450    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
451        use std::str::FromStr;
452        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
453        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for MerchantDefaultCurrency"))
454    }
455}
456impl payjp_types::Object for Merchant {
457    type Id = payjp_core::MerchantId;
458    fn id(&self) -> &Self::Id {
459        &self.id
460    }
461
462    fn into_id(self) -> Self::Id {
463        self.id
464    }
465}
466payjp_types::def_id!(MerchantId);