module TD.Data.PaymentProvider
(PaymentProvider(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data PaymentProvider
= PaymentProviderSmartGlocal
{ PaymentProvider -> Maybe Text
public_token :: Maybe T.Text
, PaymentProvider -> Maybe Text
tokenize_url :: Maybe T.Text
}
| PaymentProviderStripe
{ PaymentProvider -> Maybe Text
publishable_key :: Maybe T.Text
, PaymentProvider -> Maybe Bool
need_country :: Maybe Bool
, PaymentProvider -> Maybe Bool
need_postal_code :: Maybe Bool
, PaymentProvider -> Maybe Bool
need_cardholder_name :: Maybe Bool
}
| PaymentProviderOther
{ PaymentProvider -> Maybe Text
url :: Maybe T.Text
}
deriving (PaymentProvider -> PaymentProvider -> Bool
(PaymentProvider -> PaymentProvider -> Bool)
-> (PaymentProvider -> PaymentProvider -> Bool)
-> Eq PaymentProvider
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PaymentProvider -> PaymentProvider -> Bool
== :: PaymentProvider -> PaymentProvider -> Bool
$c/= :: PaymentProvider -> PaymentProvider -> Bool
/= :: PaymentProvider -> PaymentProvider -> Bool
Eq, Int -> PaymentProvider -> ShowS
[PaymentProvider] -> ShowS
PaymentProvider -> String
(Int -> PaymentProvider -> ShowS)
-> (PaymentProvider -> String)
-> ([PaymentProvider] -> ShowS)
-> Show PaymentProvider
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PaymentProvider -> ShowS
showsPrec :: Int -> PaymentProvider -> ShowS
$cshow :: PaymentProvider -> String
show :: PaymentProvider -> String
$cshowList :: [PaymentProvider] -> ShowS
showList :: [PaymentProvider] -> ShowS
Show)
instance I.ShortShow PaymentProvider where
shortShow :: PaymentProvider -> String
shortShow PaymentProviderSmartGlocal
{ public_token :: PaymentProvider -> Maybe Text
public_token = Maybe Text
public_token_
, tokenize_url :: PaymentProvider -> Maybe Text
tokenize_url = Maybe Text
tokenize_url_
}
= String
"PaymentProviderSmartGlocal"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"public_token" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
public_token_
, String
"tokenize_url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
tokenize_url_
]
shortShow PaymentProviderStripe
{ publishable_key :: PaymentProvider -> Maybe Text
publishable_key = Maybe Text
publishable_key_
, need_country :: PaymentProvider -> Maybe Bool
need_country = Maybe Bool
need_country_
, need_postal_code :: PaymentProvider -> Maybe Bool
need_postal_code = Maybe Bool
need_postal_code_
, need_cardholder_name :: PaymentProvider -> Maybe Bool
need_cardholder_name = Maybe Bool
need_cardholder_name_
}
= String
"PaymentProviderStripe"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"publishable_key" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
publishable_key_
, String
"need_country" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
need_country_
, String
"need_postal_code" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
need_postal_code_
, String
"need_cardholder_name" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
need_cardholder_name_
]
shortShow PaymentProviderOther
{ url :: PaymentProvider -> Maybe Text
url = Maybe Text
url_
}
= String
"PaymentProviderOther"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
]
instance AT.FromJSON PaymentProvider where
parseJSON :: Value -> Parser PaymentProvider
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
"paymentProviderSmartGlocal" -> Value -> Parser PaymentProvider
parsePaymentProviderSmartGlocal Value
v
String
"paymentProviderStripe" -> Value -> Parser PaymentProvider
parsePaymentProviderStripe Value
v
String
"paymentProviderOther" -> Value -> Parser PaymentProvider
parsePaymentProviderOther Value
v
String
_ -> Parser PaymentProvider
forall a. Monoid a => a
mempty
where
parsePaymentProviderSmartGlocal :: A.Value -> AT.Parser PaymentProvider
parsePaymentProviderSmartGlocal :: Value -> Parser PaymentProvider
parsePaymentProviderSmartGlocal = String
-> (Object -> Parser PaymentProvider)
-> Value
-> Parser PaymentProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaymentProviderSmartGlocal" ((Object -> Parser PaymentProvider)
-> Value -> Parser PaymentProvider)
-> (Object -> Parser PaymentProvider)
-> Value
-> Parser PaymentProvider
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
public_token_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"public_token"
Maybe Text
tokenize_url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"tokenize_url"
PaymentProvider -> Parser PaymentProvider
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaymentProvider -> Parser PaymentProvider)
-> PaymentProvider -> Parser PaymentProvider
forall a b. (a -> b) -> a -> b
$ PaymentProviderSmartGlocal
{ public_token :: Maybe Text
public_token = Maybe Text
public_token_
, tokenize_url :: Maybe Text
tokenize_url = Maybe Text
tokenize_url_
}
parsePaymentProviderStripe :: A.Value -> AT.Parser PaymentProvider
parsePaymentProviderStripe :: Value -> Parser PaymentProvider
parsePaymentProviderStripe = String
-> (Object -> Parser PaymentProvider)
-> Value
-> Parser PaymentProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaymentProviderStripe" ((Object -> Parser PaymentProvider)
-> Value -> Parser PaymentProvider)
-> (Object -> Parser PaymentProvider)
-> Value
-> Parser PaymentProvider
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
publishable_key_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"publishable_key"
Maybe Bool
need_country_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"need_country"
Maybe Bool
need_postal_code_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"need_postal_code"
Maybe Bool
need_cardholder_name_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"need_cardholder_name"
PaymentProvider -> Parser PaymentProvider
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaymentProvider -> Parser PaymentProvider)
-> PaymentProvider -> Parser PaymentProvider
forall a b. (a -> b) -> a -> b
$ PaymentProviderStripe
{ publishable_key :: Maybe Text
publishable_key = Maybe Text
publishable_key_
, need_country :: Maybe Bool
need_country = Maybe Bool
need_country_
, need_postal_code :: Maybe Bool
need_postal_code = Maybe Bool
need_postal_code_
, need_cardholder_name :: Maybe Bool
need_cardholder_name = Maybe Bool
need_cardholder_name_
}
parsePaymentProviderOther :: A.Value -> AT.Parser PaymentProvider
parsePaymentProviderOther :: Value -> Parser PaymentProvider
parsePaymentProviderOther = String
-> (Object -> Parser PaymentProvider)
-> Value
-> Parser PaymentProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaymentProviderOther" ((Object -> Parser PaymentProvider)
-> Value -> Parser PaymentProvider)
-> (Object -> Parser PaymentProvider)
-> Value
-> Parser PaymentProvider
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
PaymentProvider -> Parser PaymentProvider
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaymentProvider -> Parser PaymentProvider)
-> PaymentProvider -> Parser PaymentProvider
forall a b. (a -> b) -> a -> b
$ PaymentProviderOther
{ url :: Maybe Text
url = Maybe Text
url_
}
parseJSON Value
_ = Parser PaymentProvider
forall a. Monoid a => a
mempty