module TD.Data.PaymentFormType
(PaymentFormType(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.Invoice as Invoice
import qualified TD.Data.PaymentProvider as PaymentProvider
import qualified TD.Data.PaymentOption as PaymentOption
import qualified TD.Data.OrderInfo as OrderInfo
import qualified TD.Data.SavedCredentials as SavedCredentials
data PaymentFormType
= PaymentFormTypeRegular
{ PaymentFormType -> Maybe Invoice
invoice :: Maybe Invoice.Invoice
, PaymentFormType -> Maybe Int
payment_provider_user_id :: Maybe Int
, PaymentFormType -> Maybe PaymentProvider
payment_provider :: Maybe PaymentProvider.PaymentProvider
, PaymentFormType -> Maybe [PaymentOption]
additional_payment_options :: Maybe [PaymentOption.PaymentOption]
, PaymentFormType -> Maybe OrderInfo
saved_order_info :: Maybe OrderInfo.OrderInfo
, PaymentFormType -> Maybe [SavedCredentials]
saved_credentials :: Maybe [SavedCredentials.SavedCredentials]
, PaymentFormType -> Maybe Bool
can_save_credentials :: Maybe Bool
, PaymentFormType -> Maybe Bool
need_password :: Maybe Bool
}
| PaymentFormTypeStars
{ PaymentFormType -> Maybe Int
star_count :: Maybe Int
}
deriving (PaymentFormType -> PaymentFormType -> Bool
(PaymentFormType -> PaymentFormType -> Bool)
-> (PaymentFormType -> PaymentFormType -> Bool)
-> Eq PaymentFormType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PaymentFormType -> PaymentFormType -> Bool
== :: PaymentFormType -> PaymentFormType -> Bool
$c/= :: PaymentFormType -> PaymentFormType -> Bool
/= :: PaymentFormType -> PaymentFormType -> Bool
Eq, Int -> PaymentFormType -> ShowS
[PaymentFormType] -> ShowS
PaymentFormType -> String
(Int -> PaymentFormType -> ShowS)
-> (PaymentFormType -> String)
-> ([PaymentFormType] -> ShowS)
-> Show PaymentFormType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PaymentFormType -> ShowS
showsPrec :: Int -> PaymentFormType -> ShowS
$cshow :: PaymentFormType -> String
show :: PaymentFormType -> String
$cshowList :: [PaymentFormType] -> ShowS
showList :: [PaymentFormType] -> ShowS
Show)
instance I.ShortShow PaymentFormType where
shortShow :: PaymentFormType -> String
shortShow PaymentFormTypeRegular
{ invoice :: PaymentFormType -> Maybe Invoice
invoice = Maybe Invoice
invoice_
, payment_provider_user_id :: PaymentFormType -> Maybe Int
payment_provider_user_id = Maybe Int
payment_provider_user_id_
, payment_provider :: PaymentFormType -> Maybe PaymentProvider
payment_provider = Maybe PaymentProvider
payment_provider_
, additional_payment_options :: PaymentFormType -> Maybe [PaymentOption]
additional_payment_options = Maybe [PaymentOption]
additional_payment_options_
, saved_order_info :: PaymentFormType -> Maybe OrderInfo
saved_order_info = Maybe OrderInfo
saved_order_info_
, saved_credentials :: PaymentFormType -> Maybe [SavedCredentials]
saved_credentials = Maybe [SavedCredentials]
saved_credentials_
, can_save_credentials :: PaymentFormType -> Maybe Bool
can_save_credentials = Maybe Bool
can_save_credentials_
, need_password :: PaymentFormType -> Maybe Bool
need_password = Maybe Bool
need_password_
}
= String
"PaymentFormTypeRegular"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"invoice" String -> Maybe Invoice -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Invoice
invoice_
, String
"payment_provider_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
payment_provider_user_id_
, String
"payment_provider" String -> Maybe PaymentProvider -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe PaymentProvider
payment_provider_
, String
"additional_payment_options" String -> Maybe [PaymentOption] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [PaymentOption]
additional_payment_options_
, String
"saved_order_info" String -> Maybe OrderInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe OrderInfo
saved_order_info_
, String
"saved_credentials" String -> Maybe [SavedCredentials] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [SavedCredentials]
saved_credentials_
, String
"can_save_credentials" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_save_credentials_
, String
"need_password" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
need_password_
]
shortShow PaymentFormTypeStars
{ star_count :: PaymentFormType -> Maybe Int
star_count = Maybe Int
star_count_
}
= String
"PaymentFormTypeStars"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
]
instance AT.FromJSON PaymentFormType where
parseJSON :: Value -> Parser PaymentFormType
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"paymentFormTypeRegular" -> Value -> Parser PaymentFormType
parsePaymentFormTypeRegular Value
v
String
"paymentFormTypeStars" -> Value -> Parser PaymentFormType
parsePaymentFormTypeStars Value
v
String
_ -> Parser PaymentFormType
forall a. Monoid a => a
mempty
where
parsePaymentFormTypeRegular :: A.Value -> AT.Parser PaymentFormType
parsePaymentFormTypeRegular :: Value -> Parser PaymentFormType
parsePaymentFormTypeRegular = String
-> (Object -> Parser PaymentFormType)
-> Value
-> Parser PaymentFormType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaymentFormTypeRegular" ((Object -> Parser PaymentFormType)
-> Value -> Parser PaymentFormType)
-> (Object -> Parser PaymentFormType)
-> Value
-> Parser PaymentFormType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Invoice
invoice_ <- Object
o Object -> Key -> Parser (Maybe Invoice)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"invoice"
Maybe Int
payment_provider_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"payment_provider_user_id"
Maybe PaymentProvider
payment_provider_ <- Object
o Object -> Key -> Parser (Maybe PaymentProvider)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"payment_provider"
Maybe [PaymentOption]
additional_payment_options_ <- Object
o Object -> Key -> Parser (Maybe [PaymentOption])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"additional_payment_options"
Maybe OrderInfo
saved_order_info_ <- Object
o Object -> Key -> Parser (Maybe OrderInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"saved_order_info"
Maybe [SavedCredentials]
saved_credentials_ <- Object
o Object -> Key -> Parser (Maybe [SavedCredentials])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"saved_credentials"
Maybe Bool
can_save_credentials_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_save_credentials"
Maybe Bool
need_password_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"need_password"
PaymentFormType -> Parser PaymentFormType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaymentFormType -> Parser PaymentFormType)
-> PaymentFormType -> Parser PaymentFormType
forall a b. (a -> b) -> a -> b
$ PaymentFormTypeRegular
{ invoice :: Maybe Invoice
invoice = Maybe Invoice
invoice_
, payment_provider_user_id :: Maybe Int
payment_provider_user_id = Maybe Int
payment_provider_user_id_
, payment_provider :: Maybe PaymentProvider
payment_provider = Maybe PaymentProvider
payment_provider_
, additional_payment_options :: Maybe [PaymentOption]
additional_payment_options = Maybe [PaymentOption]
additional_payment_options_
, saved_order_info :: Maybe OrderInfo
saved_order_info = Maybe OrderInfo
saved_order_info_
, saved_credentials :: Maybe [SavedCredentials]
saved_credentials = Maybe [SavedCredentials]
saved_credentials_
, can_save_credentials :: Maybe Bool
can_save_credentials = Maybe Bool
can_save_credentials_
, need_password :: Maybe Bool
need_password = Maybe Bool
need_password_
}
parsePaymentFormTypeStars :: A.Value -> AT.Parser PaymentFormType
parsePaymentFormTypeStars :: Value -> Parser PaymentFormType
parsePaymentFormTypeStars = String
-> (Object -> Parser PaymentFormType)
-> Value
-> Parser PaymentFormType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaymentFormTypeStars" ((Object -> Parser PaymentFormType)
-> Value -> Parser PaymentFormType)
-> (Object -> Parser PaymentFormType)
-> Value
-> Parser PaymentFormType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
star_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"star_count"
PaymentFormType -> Parser PaymentFormType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaymentFormType -> Parser PaymentFormType)
-> PaymentFormType -> Parser PaymentFormType
forall a b. (a -> b) -> a -> b
$ PaymentFormTypeStars
{ star_count :: Maybe Int
star_count = Maybe Int
star_count_
}
parseJSON Value
_ = Parser PaymentFormType
forall a. Monoid a => a
mempty