{-# LANGUAGE MultiWayIf #-}
-- CHANGE WITH CAUTION: This is a generated code file generated by https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator.
{-# LANGUAGE OverloadedStrings #-}

-- | Contains the types generated from the schema Token
module StripeAPI.Types.Token where

import qualified Control.Monad.Fail
import qualified Data.Aeson
import qualified Data.Aeson as Data.Aeson.Encoding.Internal
import qualified Data.Aeson as Data.Aeson.Types
import qualified Data.Aeson as Data.Aeson.Types.FromJSON
import qualified Data.Aeson as Data.Aeson.Types.Internal
import qualified Data.Aeson as Data.Aeson.Types.ToJSON
import qualified Data.ByteString.Char8
import qualified Data.ByteString.Char8 as Data.ByteString.Internal
import qualified Data.Functor
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text.Internal
import qualified Data.Time.Calendar as Data.Time.Calendar.Days
import qualified Data.Time.LocalTime as Data.Time.LocalTime.Internal.ZonedTime
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified StripeAPI.Common
import StripeAPI.TypeAlias
import {-# SOURCE #-} StripeAPI.Types.BankAccount
import {-# SOURCE #-} StripeAPI.Types.Card
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.token@ in the specification.
--
-- Tokenization is the process Stripe uses to collect sensitive card or bank
-- account details, or personally identifiable information (PII), directly from
-- your customers in a secure manner. A token representing this information is
-- returned to your server to use. You should use our
-- [recommended payments integrations](https:\/\/stripe.com\/docs\/payments) to perform this process
-- client-side. This ensures that no sensitive card data touches your server,
-- and allows your integration to operate in a PCI-compliant way.
--
-- If you cannot use client-side tokenization, you can also create tokens using
-- the API with either your publishable or secret API key. Keep in mind that if
-- your integration uses this method, you are responsible for any PCI compliance
-- that may be required, and you must keep your secret API key safe. Unlike with
-- client-side tokenization, your customer\'s information is not sent directly to
-- Stripe, so we cannot determine how it is handled or stored.
--
-- Tokens cannot be stored or used more than once. To store card or bank account
-- information for later use, you can create [Customer](https:\/\/stripe.com\/docs\/api\#customers)
-- objects or [Custom accounts](https:\/\/stripe.com\/docs\/api\#external_accounts). Note that
-- [Radar](https:\/\/stripe.com\/docs\/radar), our integrated solution for automatic fraud protection,
-- performs best with integrations that use client-side tokenization.
--
-- Related guide: [Accept a payment](https:\/\/stripe.com\/docs\/payments\/accept-a-payment-charges\#web-create-token)
data Token = Token
  { -- | bank_account: These bank accounts are payment methods on \`Customer\` objects.
    --
    -- On the other hand [External Accounts](https:\/\/stripe.com\/docs\/api\#external_accounts) are transfer
    -- destinations on \`Account\` objects for [Custom accounts](https:\/\/stripe.com\/docs\/connect\/custom-accounts).
    -- They can be bank accounts or debit cards as well, and are documented in the links above.
    --
    -- Related guide: [Bank Debits and Transfers](https:\/\/stripe.com\/docs\/payments\/bank-debits-transfers).
    Token -> Maybe BankAccount
tokenBankAccount :: (GHC.Maybe.Maybe BankAccount),
    -- | card: You can store multiple cards on a customer in order to charge the customer
    -- later. You can also store multiple debit cards on a recipient in order to
    -- transfer to those cards later.
    --
    -- Related guide: [Card Payments with Sources](https:\/\/stripe.com\/docs\/sources\/cards).
    Token -> Maybe Card
tokenCard :: (GHC.Maybe.Maybe Card),
    -- | client_ip: IP address of the client that generated the token.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Token -> Maybe Text
tokenClientIp :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | created: Time at which the object was created. Measured in seconds since the Unix epoch.
    Token -> Int
tokenCreated :: GHC.Types.Int,
    -- | id: Unique identifier for the object.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Token -> Text
tokenId :: Data.Text.Internal.Text,
    -- | livemode: Has the value \`true\` if the object exists in live mode or the value \`false\` if the object exists in test mode.
    Token -> Bool
tokenLivemode :: GHC.Types.Bool,
    -- | type: Type of the token: \`account\`, \`bank_account\`, \`card\`, or \`pii\`.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Token -> Text
tokenType :: Data.Text.Internal.Text,
    -- | used: Whether this token has already been used (tokens can be used only once).
    Token -> Bool
tokenUsed :: GHC.Types.Bool
  }
  deriving
    ( Int -> Token -> ShowS
[Token] -> ShowS
Token -> String
(Int -> Token -> ShowS)
-> (Token -> String) -> ([Token] -> ShowS) -> Show Token
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Token] -> ShowS
$cshowList :: [Token] -> ShowS
show :: Token -> String
$cshow :: Token -> String
showsPrec :: Int -> Token -> ShowS
$cshowsPrec :: Int -> Token -> ShowS
GHC.Show.Show,
      Token -> Token -> Bool
(Token -> Token -> Bool) -> (Token -> Token -> Bool) -> Eq Token
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Token -> Token -> Bool
$c/= :: Token -> Token -> Bool
== :: Token -> Token -> Bool
$c== :: Token -> Token -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON Token where
  toJSON :: Token -> Value
toJSON Token
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"bank_account" Text -> Maybe BankAccount -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Maybe BankAccount
tokenBankAccount Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"card" Text -> Maybe Card -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Maybe Card
tokenCard Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"client_ip" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Maybe Text
tokenClientIp Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"created" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Int
tokenCreated Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Text
tokenId Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"livemode" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Bool
tokenLivemode Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Text
tokenType Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"used" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Bool
tokenUsed Token
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"object" Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"token" Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: Token -> Encoding
toEncoding Token
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"bank_account" Text -> Maybe BankAccount -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Maybe BankAccount
tokenBankAccount Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"card" Text -> Maybe Card -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Maybe Card
tokenCard Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"client_ip" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Maybe Text
tokenClientIp Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"created" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Int
tokenCreated Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"id" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Text
tokenId Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"livemode" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Bool
tokenLivemode Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"type" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Text
tokenType Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"used" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Token -> Bool
tokenUsed Token
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"object" Text -> Value -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"token")))))))))

instance Data.Aeson.Types.FromJSON.FromJSON Token where
  parseJSON :: Value -> Parser Token
parseJSON = String -> (Object -> Parser Token) -> Value -> Parser Token
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"Token" (\Object
obj -> ((((((((Maybe BankAccount
 -> Maybe Card
 -> Maybe Text
 -> Int
 -> Text
 -> Bool
 -> Text
 -> Bool
 -> Token)
-> Parser
     (Maybe BankAccount
      -> Maybe Card
      -> Maybe Text
      -> Int
      -> Text
      -> Bool
      -> Text
      -> Bool
      -> Token)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe BankAccount
-> Maybe Card
-> Maybe Text
-> Int
-> Text
-> Bool
-> Text
-> Bool
-> Token
Token Parser
  (Maybe BankAccount
   -> Maybe Card
   -> Maybe Text
   -> Int
   -> Text
   -> Bool
   -> Text
   -> Bool
   -> Token)
-> Parser (Maybe BankAccount)
-> Parser
     (Maybe Card
      -> Maybe Text -> Int -> Text -> Bool -> Text -> Bool -> Token)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe BankAccount)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"bank_account")) Parser
  (Maybe Card
   -> Maybe Text -> Int -> Text -> Bool -> Text -> Bool -> Token)
-> Parser (Maybe Card)
-> Parser
     (Maybe Text -> Int -> Text -> Bool -> Text -> Bool -> Token)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Card)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"card")) Parser (Maybe Text -> Int -> Text -> Bool -> Text -> Bool -> Token)
-> Parser (Maybe Text)
-> Parser (Int -> Text -> Bool -> Text -> Bool -> Token)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"client_ip")) Parser (Int -> Text -> Bool -> Text -> Bool -> Token)
-> Parser Int -> Parser (Text -> Bool -> Text -> Bool -> Token)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"created")) Parser (Text -> Bool -> Text -> Bool -> Token)
-> Parser Text -> Parser (Bool -> Text -> Bool -> Token)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"id")) Parser (Bool -> Text -> Bool -> Token)
-> Parser Bool -> Parser (Text -> Bool -> Token)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"livemode")) Parser (Text -> Bool -> Token)
-> Parser Text -> Parser (Bool -> Token)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"type")) Parser (Bool -> Token) -> Parser Bool -> Parser Token
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"used"))

-- | Create a new 'Token' with all required fields.
mkToken ::
  -- | 'tokenCreated'
  GHC.Types.Int ->
  -- | 'tokenId'
  Data.Text.Internal.Text ->
  -- | 'tokenLivemode'
  GHC.Types.Bool ->
  -- | 'tokenType'
  Data.Text.Internal.Text ->
  -- | 'tokenUsed'
  GHC.Types.Bool ->
  Token
mkToken :: Int -> Text -> Bool -> Text -> Bool -> Token
mkToken Int
tokenCreated Text
tokenId Bool
tokenLivemode Text
tokenType Bool
tokenUsed =
  Token :: Maybe BankAccount
-> Maybe Card
-> Maybe Text
-> Int
-> Text
-> Bool
-> Text
-> Bool
-> Token
Token
    { tokenBankAccount :: Maybe BankAccount
tokenBankAccount = Maybe BankAccount
forall a. Maybe a
GHC.Maybe.Nothing,
      tokenCard :: Maybe Card
tokenCard = Maybe Card
forall a. Maybe a
GHC.Maybe.Nothing,
      tokenClientIp :: Maybe Text
tokenClientIp = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      tokenCreated :: Int
tokenCreated = Int
tokenCreated,
      tokenId :: Text
tokenId = Text
tokenId,
      tokenLivemode :: Bool
tokenLivemode = Bool
tokenLivemode,
      tokenType :: Text
tokenType = Text
tokenType,
      tokenUsed :: Bool
tokenUsed = Bool
tokenUsed
    }