{-# 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 SourceRedirectFlow
module StripeAPI.Types.SourceRedirectFlow 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 qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.source_redirect_flow@ in the specification.
data SourceRedirectFlow = SourceRedirectFlow
  { -- | failure_reason: The failure reason for the redirect, either \`user_abort\` (the customer aborted or dropped out of the redirect flow), \`declined\` (the authentication failed or the transaction was declined), or \`processing_error\` (the redirect failed due to a technical error). Present only if the redirect status is \`failed\`.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    SourceRedirectFlow -> Maybe Text
sourceRedirectFlowFailureReason :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | return_url: The URL you provide to redirect the customer to after they authenticated their payment.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    SourceRedirectFlow -> Text
sourceRedirectFlowReturnUrl :: Data.Text.Internal.Text,
    -- | status: The status of the redirect, either \`pending\` (ready to be used by your customer to authenticate the transaction), \`succeeded\` (succesful authentication, cannot be reused) or \`not_required\` (redirect should not be used) or \`failed\` (failed authentication, cannot be reused).
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    SourceRedirectFlow -> Text
sourceRedirectFlowStatus :: Data.Text.Internal.Text,
    -- | url: The URL provided to you to redirect a customer to as part of a \`redirect\` authentication flow.
    --
    -- Constraints:
    --
    -- * Maximum length of 2048
    SourceRedirectFlow -> Text
sourceRedirectFlowUrl :: Data.Text.Internal.Text
  }
  deriving
    ( Int -> SourceRedirectFlow -> ShowS
[SourceRedirectFlow] -> ShowS
SourceRedirectFlow -> String
(Int -> SourceRedirectFlow -> ShowS)
-> (SourceRedirectFlow -> String)
-> ([SourceRedirectFlow] -> ShowS)
-> Show SourceRedirectFlow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceRedirectFlow] -> ShowS
$cshowList :: [SourceRedirectFlow] -> ShowS
show :: SourceRedirectFlow -> String
$cshow :: SourceRedirectFlow -> String
showsPrec :: Int -> SourceRedirectFlow -> ShowS
$cshowsPrec :: Int -> SourceRedirectFlow -> ShowS
GHC.Show.Show,
      SourceRedirectFlow -> SourceRedirectFlow -> Bool
(SourceRedirectFlow -> SourceRedirectFlow -> Bool)
-> (SourceRedirectFlow -> SourceRedirectFlow -> Bool)
-> Eq SourceRedirectFlow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceRedirectFlow -> SourceRedirectFlow -> Bool
$c/= :: SourceRedirectFlow -> SourceRedirectFlow -> Bool
== :: SourceRedirectFlow -> SourceRedirectFlow -> Bool
$c== :: SourceRedirectFlow -> SourceRedirectFlow -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON SourceRedirectFlow where
  toJSON :: SourceRedirectFlow -> Value
toJSON SourceRedirectFlow
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"failure_reason" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Maybe Text
sourceRedirectFlowFailureReason SourceRedirectFlow
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"return_url" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Text
sourceRedirectFlowReturnUrl SourceRedirectFlow
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"status" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Text
sourceRedirectFlowStatus SourceRedirectFlow
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"url" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Text
sourceRedirectFlowUrl SourceRedirectFlow
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: SourceRedirectFlow -> Encoding
toEncoding SourceRedirectFlow
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"failure_reason" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Maybe Text
sourceRedirectFlowFailureReason SourceRedirectFlow
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"return_url" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Text
sourceRedirectFlowReturnUrl SourceRedirectFlow
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"status" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Text
sourceRedirectFlowStatus SourceRedirectFlow
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"url" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SourceRedirectFlow -> Text
sourceRedirectFlowUrl SourceRedirectFlow
obj))))

instance Data.Aeson.Types.FromJSON.FromJSON SourceRedirectFlow where
  parseJSON :: Value -> Parser SourceRedirectFlow
parseJSON = String
-> (Object -> Parser SourceRedirectFlow)
-> Value
-> Parser SourceRedirectFlow
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"SourceRedirectFlow" (\Object
obj -> ((((Maybe Text -> Text -> Text -> Text -> SourceRedirectFlow)
-> Parser
     (Maybe Text -> Text -> Text -> Text -> SourceRedirectFlow)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Text -> Text -> Text -> Text -> SourceRedirectFlow
SourceRedirectFlow Parser (Maybe Text -> Text -> Text -> Text -> SourceRedirectFlow)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> Text -> SourceRedirectFlow)
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
"failure_reason")) Parser (Text -> Text -> Text -> SourceRedirectFlow)
-> Parser Text -> Parser (Text -> Text -> SourceRedirectFlow)
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
"return_url")) Parser (Text -> Text -> SourceRedirectFlow)
-> Parser Text -> Parser (Text -> SourceRedirectFlow)
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
"status")) Parser (Text -> SourceRedirectFlow)
-> Parser Text -> Parser SourceRedirectFlow
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
"url"))

-- | Create a new 'SourceRedirectFlow' with all required fields.
mkSourceRedirectFlow ::
  -- | 'sourceRedirectFlowReturnUrl'
  Data.Text.Internal.Text ->
  -- | 'sourceRedirectFlowStatus'
  Data.Text.Internal.Text ->
  -- | 'sourceRedirectFlowUrl'
  Data.Text.Internal.Text ->
  SourceRedirectFlow
mkSourceRedirectFlow :: Text -> Text -> Text -> SourceRedirectFlow
mkSourceRedirectFlow Text
sourceRedirectFlowReturnUrl Text
sourceRedirectFlowStatus Text
sourceRedirectFlowUrl =
  SourceRedirectFlow :: Maybe Text -> Text -> Text -> Text -> SourceRedirectFlow
SourceRedirectFlow
    { sourceRedirectFlowFailureReason :: Maybe Text
sourceRedirectFlowFailureReason = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      sourceRedirectFlowReturnUrl :: Text
sourceRedirectFlowReturnUrl = Text
sourceRedirectFlowReturnUrl,
      sourceRedirectFlowStatus :: Text
sourceRedirectFlowStatus = Text
sourceRedirectFlowStatus,
      sourceRedirectFlowUrl :: Text
sourceRedirectFlowUrl = Text
sourceRedirectFlowUrl
    }