{-# LANGUAGE ExplicitForAll #-}
{-# 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 different functions to run the operation postBillingPortalSessions
module StripeAPI.Operations.PostBillingPortalSessions where

import qualified Control.Monad.Fail
import qualified Control.Monad.Trans.Reader
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.Either
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 Data.Vector
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified Network.HTTP.Client
import qualified Network.HTTP.Client as Network.HTTP.Client.Request
import qualified Network.HTTP.Client as Network.HTTP.Client.Types
import qualified Network.HTTP.Simple
import qualified Network.HTTP.Types
import qualified Network.HTTP.Types as Network.HTTP.Types.Status
import qualified Network.HTTP.Types as Network.HTTP.Types.URI
import qualified StripeAPI.Common
import StripeAPI.Types
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | > POST /v1/billing_portal/sessions
--
-- \<p>Creates a session of the customer portal.\<\/p>
postBillingPortalSessions ::
  forall m.
  StripeAPI.Common.MonadHTTP m =>
  -- | The request body to send
  PostBillingPortalSessionsRequestBody ->
  -- | Monadic computation which returns the result of the operation
  StripeAPI.Common.StripeT m (Network.HTTP.Client.Types.Response PostBillingPortalSessionsResponse)
postBillingPortalSessions :: PostBillingPortalSessionsRequestBody
-> StripeT m (Response PostBillingPortalSessionsResponse)
postBillingPortalSessions PostBillingPortalSessionsRequestBody
body =
  (Response ByteString -> Response PostBillingPortalSessionsResponse)
-> StripeT m (Response ByteString)
-> StripeT m (Response PostBillingPortalSessionsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
    ( \Response ByteString
response_0 ->
        (ByteString -> PostBillingPortalSessionsResponse)
-> Response ByteString
-> Response PostBillingPortalSessionsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
          ( (String -> PostBillingPortalSessionsResponse)
-> (PostBillingPortalSessionsResponse
    -> PostBillingPortalSessionsResponse)
-> Either String PostBillingPortalSessionsResponse
-> PostBillingPortalSessionsResponse
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
Data.Either.either String -> PostBillingPortalSessionsResponse
PostBillingPortalSessionsResponseError PostBillingPortalSessionsResponse
-> PostBillingPortalSessionsResponse
forall a. a -> a
GHC.Base.id
              (Either String PostBillingPortalSessionsResponse
 -> PostBillingPortalSessionsResponse)
-> (ByteString -> Either String PostBillingPortalSessionsResponse)
-> ByteString
-> PostBillingPortalSessionsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. ( \Response ByteString
response ByteString
body ->
                             if
                                 | (\Status
status_1 -> Status -> Int
Network.HTTP.Types.Status.statusCode Status
status_1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Int
200) (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                   BillingPortal'session -> PostBillingPortalSessionsResponse
PostBillingPortalSessionsResponse200
                                     (BillingPortal'session -> PostBillingPortalSessionsResponse)
-> Either String BillingPortal'session
-> Either String PostBillingPortalSessionsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> ( ByteString -> Either String BillingPortal'session
forall a. FromJSON a => ByteString -> Either String a
Data.Aeson.eitherDecodeStrict ByteString
body ::
                                                          Data.Either.Either
                                                            GHC.Base.String
                                                            BillingPortal'session
                                                      )
                                 | Bool -> Status -> Bool
forall a b. a -> b -> a
GHC.Base.const Bool
GHC.Types.True (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                   Error -> PostBillingPortalSessionsResponse
PostBillingPortalSessionsResponseDefault
                                     (Error -> PostBillingPortalSessionsResponse)
-> Either String Error
-> Either String PostBillingPortalSessionsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> ( ByteString -> Either String Error
forall a. FromJSON a => ByteString -> Either String a
Data.Aeson.eitherDecodeStrict ByteString
body ::
                                                          Data.Either.Either
                                                            GHC.Base.String
                                                            Error
                                                      )
                                 | Bool
GHC.Base.otherwise -> String -> Either String PostBillingPortalSessionsResponse
forall a b. a -> Either a b
Data.Either.Left String
"Missing default response type"
                         )
                Response ByteString
response_0
          )
          Response ByteString
response_0
    )
    (Text
-> Text
-> [QueryParameter]
-> Maybe PostBillingPortalSessionsRequestBody
-> RequestBodyEncoding
-> StripeT m (Response ByteString)
forall (m :: * -> *) body.
(MonadHTTP m, ToJSON body) =>
Text
-> Text
-> [QueryParameter]
-> Maybe body
-> RequestBodyEncoding
-> StripeT m (Response ByteString)
StripeAPI.Common.doBodyCallWithConfigurationM (Text -> Text
Data.Text.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
GHC.Base.$ String -> Text
Data.Text.pack String
"POST") (String -> Text
Data.Text.pack String
"/v1/billing_portal/sessions") [QueryParameter]
forall a. Monoid a => a
GHC.Base.mempty (PostBillingPortalSessionsRequestBody
-> Maybe PostBillingPortalSessionsRequestBody
forall a. a -> Maybe a
GHC.Maybe.Just PostBillingPortalSessionsRequestBody
body) RequestBodyEncoding
StripeAPI.Common.RequestBodyEncodingFormData)

-- | Defines the object schema located at @paths.\/v1\/billing_portal\/sessions.POST.requestBody.content.application\/x-www-form-urlencoded.schema@ in the specification.
data PostBillingPortalSessionsRequestBody = PostBillingPortalSessionsRequestBody
  { -- | configuration: The ID of an existing [configuration](https:\/\/stripe.com\/docs\/api\/customer_portal\/configuration) to use for this session, describing its functionality and features. If not specified, the session uses the default configuration.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyConfiguration :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | customer: The ID of an existing customer.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    PostBillingPortalSessionsRequestBody -> Text
postBillingPortalSessionsRequestBodyCustomer :: Data.Text.Internal.Text,
    -- | expand: Specifies which fields in the response should be expanded.
    PostBillingPortalSessionsRequestBody -> Maybe [Text]
postBillingPortalSessionsRequestBodyExpand :: (GHC.Maybe.Maybe ([Data.Text.Internal.Text])),
    -- | on_behalf_of: The \`on_behalf_of\` account to use for this session. When specified, only subscriptions and invoices with this \`on_behalf_of\` account appear in the portal. For more information, see the [docs](https:\/\/stripe.com\/docs\/connect\/charges-transfers\#on-behalf-of). Use the [Accounts API](https:\/\/stripe.com\/docs\/api\/accounts\/object\#account_object-settings-branding) to modify the \`on_behalf_of\` account\'s branding settings, which the portal displays.
    PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyOnBehalfOf :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | return_url: The default URL to redirect customers to when they click on the portal\'s link to return to your website.
    PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyReturnUrl :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
  }
  deriving
    ( Int -> PostBillingPortalSessionsRequestBody -> ShowS
[PostBillingPortalSessionsRequestBody] -> ShowS
PostBillingPortalSessionsRequestBody -> String
(Int -> PostBillingPortalSessionsRequestBody -> ShowS)
-> (PostBillingPortalSessionsRequestBody -> String)
-> ([PostBillingPortalSessionsRequestBody] -> ShowS)
-> Show PostBillingPortalSessionsRequestBody
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PostBillingPortalSessionsRequestBody] -> ShowS
$cshowList :: [PostBillingPortalSessionsRequestBody] -> ShowS
show :: PostBillingPortalSessionsRequestBody -> String
$cshow :: PostBillingPortalSessionsRequestBody -> String
showsPrec :: Int -> PostBillingPortalSessionsRequestBody -> ShowS
$cshowsPrec :: Int -> PostBillingPortalSessionsRequestBody -> ShowS
GHC.Show.Show,
      PostBillingPortalSessionsRequestBody
-> PostBillingPortalSessionsRequestBody -> Bool
(PostBillingPortalSessionsRequestBody
 -> PostBillingPortalSessionsRequestBody -> Bool)
-> (PostBillingPortalSessionsRequestBody
    -> PostBillingPortalSessionsRequestBody -> Bool)
-> Eq PostBillingPortalSessionsRequestBody
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostBillingPortalSessionsRequestBody
-> PostBillingPortalSessionsRequestBody -> Bool
$c/= :: PostBillingPortalSessionsRequestBody
-> PostBillingPortalSessionsRequestBody -> Bool
== :: PostBillingPortalSessionsRequestBody
-> PostBillingPortalSessionsRequestBody -> Bool
$c== :: PostBillingPortalSessionsRequestBody
-> PostBillingPortalSessionsRequestBody -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON PostBillingPortalSessionsRequestBody where
  toJSON :: PostBillingPortalSessionsRequestBody -> Value
toJSON PostBillingPortalSessionsRequestBody
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"configuration" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyConfiguration PostBillingPortalSessionsRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"customer" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Text
postBillingPortalSessionsRequestBodyCustomer PostBillingPortalSessionsRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"expand" Text -> Maybe [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe [Text]
postBillingPortalSessionsRequestBodyExpand PostBillingPortalSessionsRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"on_behalf_of" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyOnBehalfOf PostBillingPortalSessionsRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"return_url" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyReturnUrl PostBillingPortalSessionsRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: PostBillingPortalSessionsRequestBody -> Encoding
toEncoding PostBillingPortalSessionsRequestBody
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"configuration" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyConfiguration PostBillingPortalSessionsRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"customer" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Text
postBillingPortalSessionsRequestBodyCustomer PostBillingPortalSessionsRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"expand" Text -> Maybe [Text] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe [Text]
postBillingPortalSessionsRequestBodyExpand PostBillingPortalSessionsRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"on_behalf_of" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyOnBehalfOf PostBillingPortalSessionsRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"return_url" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostBillingPortalSessionsRequestBody -> Maybe Text
postBillingPortalSessionsRequestBodyReturnUrl PostBillingPortalSessionsRequestBody
obj)))))

instance Data.Aeson.Types.FromJSON.FromJSON PostBillingPortalSessionsRequestBody where
  parseJSON :: Value -> Parser PostBillingPortalSessionsRequestBody
parseJSON = String
-> (Object -> Parser PostBillingPortalSessionsRequestBody)
-> Value
-> Parser PostBillingPortalSessionsRequestBody
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"PostBillingPortalSessionsRequestBody" (\Object
obj -> (((((Maybe Text
 -> Text
 -> Maybe [Text]
 -> Maybe Text
 -> Maybe Text
 -> PostBillingPortalSessionsRequestBody)
-> Parser
     (Maybe Text
      -> Text
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> PostBillingPortalSessionsRequestBody)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Text
-> Text
-> Maybe [Text]
-> Maybe Text
-> Maybe Text
-> PostBillingPortalSessionsRequestBody
PostBillingPortalSessionsRequestBody Parser
  (Maybe Text
   -> Text
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> PostBillingPortalSessionsRequestBody)
-> Parser (Maybe Text)
-> Parser
     (Text
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> PostBillingPortalSessionsRequestBody)
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
"configuration")) Parser
  (Text
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> PostBillingPortalSessionsRequestBody)
-> Parser Text
-> Parser
     (Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> PostBillingPortalSessionsRequestBody)
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
"customer")) Parser
  (Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> PostBillingPortalSessionsRequestBody)
-> Parser (Maybe [Text])
-> Parser
     (Maybe Text -> Maybe Text -> PostBillingPortalSessionsRequestBody)
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
"expand")) Parser
  (Maybe Text -> Maybe Text -> PostBillingPortalSessionsRequestBody)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> PostBillingPortalSessionsRequestBody)
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
"on_behalf_of")) Parser (Maybe Text -> PostBillingPortalSessionsRequestBody)
-> Parser (Maybe Text)
-> Parser PostBillingPortalSessionsRequestBody
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
"return_url"))

-- | Create a new 'PostBillingPortalSessionsRequestBody' with all required fields.
mkPostBillingPortalSessionsRequestBody ::
  -- | 'postBillingPortalSessionsRequestBodyCustomer'
  Data.Text.Internal.Text ->
  PostBillingPortalSessionsRequestBody
mkPostBillingPortalSessionsRequestBody :: Text -> PostBillingPortalSessionsRequestBody
mkPostBillingPortalSessionsRequestBody Text
postBillingPortalSessionsRequestBodyCustomer =
  PostBillingPortalSessionsRequestBody :: Maybe Text
-> Text
-> Maybe [Text]
-> Maybe Text
-> Maybe Text
-> PostBillingPortalSessionsRequestBody
PostBillingPortalSessionsRequestBody
    { postBillingPortalSessionsRequestBodyConfiguration :: Maybe Text
postBillingPortalSessionsRequestBodyConfiguration = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      postBillingPortalSessionsRequestBodyCustomer :: Text
postBillingPortalSessionsRequestBodyCustomer = Text
postBillingPortalSessionsRequestBodyCustomer,
      postBillingPortalSessionsRequestBodyExpand :: Maybe [Text]
postBillingPortalSessionsRequestBodyExpand = Maybe [Text]
forall a. Maybe a
GHC.Maybe.Nothing,
      postBillingPortalSessionsRequestBodyOnBehalfOf :: Maybe Text
postBillingPortalSessionsRequestBodyOnBehalfOf = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      postBillingPortalSessionsRequestBodyReturnUrl :: Maybe Text
postBillingPortalSessionsRequestBodyReturnUrl = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
    }

-- | Represents a response of the operation 'postBillingPortalSessions'.
--
-- The response constructor is chosen by the status code of the response. If no case matches (no specific case for the response code, no range case, no default case), 'PostBillingPortalSessionsResponseError' is used.
data PostBillingPortalSessionsResponse
  = -- | Means either no matching case available or a parse error
    PostBillingPortalSessionsResponseError GHC.Base.String
  | -- | Successful response.
    PostBillingPortalSessionsResponse200 BillingPortal'session
  | -- | Error response.
    PostBillingPortalSessionsResponseDefault Error
  deriving (Int -> PostBillingPortalSessionsResponse -> ShowS
[PostBillingPortalSessionsResponse] -> ShowS
PostBillingPortalSessionsResponse -> String
(Int -> PostBillingPortalSessionsResponse -> ShowS)
-> (PostBillingPortalSessionsResponse -> String)
-> ([PostBillingPortalSessionsResponse] -> ShowS)
-> Show PostBillingPortalSessionsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PostBillingPortalSessionsResponse] -> ShowS
$cshowList :: [PostBillingPortalSessionsResponse] -> ShowS
show :: PostBillingPortalSessionsResponse -> String
$cshow :: PostBillingPortalSessionsResponse -> String
showsPrec :: Int -> PostBillingPortalSessionsResponse -> ShowS
$cshowsPrec :: Int -> PostBillingPortalSessionsResponse -> ShowS
GHC.Show.Show, PostBillingPortalSessionsResponse
-> PostBillingPortalSessionsResponse -> Bool
(PostBillingPortalSessionsResponse
 -> PostBillingPortalSessionsResponse -> Bool)
-> (PostBillingPortalSessionsResponse
    -> PostBillingPortalSessionsResponse -> Bool)
-> Eq PostBillingPortalSessionsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostBillingPortalSessionsResponse
-> PostBillingPortalSessionsResponse -> Bool
$c/= :: PostBillingPortalSessionsResponse
-> PostBillingPortalSessionsResponse -> Bool
== :: PostBillingPortalSessionsResponse
-> PostBillingPortalSessionsResponse -> Bool
$c== :: PostBillingPortalSessionsResponse
-> PostBillingPortalSessionsResponse -> Bool
GHC.Classes.Eq)