{-# 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 create_pending_purchase
module RecurlyClient.Operations.Create_pending_purchase 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
import qualified Data.ByteString as Data.ByteString.Internal
import qualified Data.ByteString as Data.ByteString.Internal.Type
import qualified Data.Either
import qualified Data.Foldable
import qualified Data.Functor
import qualified Data.Maybe
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text as 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 RecurlyClient.Common
import RecurlyClient.Types
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

{- | > POST /purchases/pending

A purchase is a hybrid checkout containing at least one or more subscriptions or one-time charges (adjustments) and supports both coupon and gift card redemptions. All items purchased will be on one invoice and paid for with one transaction. A purchase is only a request data type and is not persistent in Recurly and an invoice collection will be the returned type.

Use for **Adyen HPP** and **Online Banking** transaction requests.
This runs the validations but not the transactions.
The API request allows the inclusion of the following field: **external_hpp_type** with \`\'adyen\'\` in the **billing_info** object.

For additional information regarding shipping fees, please see https:\/\/docs.recurly.com\/docs\/shipping

Note: an email address is required on the account for a Pending Purchase.
-}
create_pending_purchase ::
    forall m.
    (RecurlyClient.Common.MonadHTTP m) =>
    -- | The request body to send
    PurchaseCreate ->
    -- | Monadic computation which returns the result of the operation
    RecurlyClient.Common.ClientT m (Network.HTTP.Client.Types.Response Create_pending_purchaseResponse)
create_pending_purchase :: forall (m :: * -> *).
MonadHTTP m =>
PurchaseCreate
-> ClientT m (Response Create_pending_purchaseResponse)
create_pending_purchase PurchaseCreate
body =
    (Response ByteString -> Response Create_pending_purchaseResponse)
-> ClientT m (Response ByteString)
-> ClientT m (Response Create_pending_purchaseResponse)
forall a b. (a -> b) -> ClientT m a -> ClientT m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
        ( \Response ByteString
response_0 ->
            (ByteString -> Create_pending_purchaseResponse)
-> Response ByteString -> Response Create_pending_purchaseResponse
forall a b. (a -> b) -> Response a -> Response b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
                ( (String -> Create_pending_purchaseResponse)
-> (Create_pending_purchaseResponse
    -> Create_pending_purchaseResponse)
-> Either String Create_pending_purchaseResponse
-> Create_pending_purchaseResponse
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
Data.Either.either String -> Create_pending_purchaseResponse
Create_pending_purchaseResponseError Create_pending_purchaseResponse -> Create_pending_purchaseResponse
forall a. a -> a
GHC.Base.id
                    (Either String Create_pending_purchaseResponse
 -> Create_pending_purchaseResponse)
-> (ByteString -> Either String Create_pending_purchaseResponse)
-> ByteString
-> Create_pending_purchaseResponse
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) ->
                                            InvoiceCollection -> Create_pending_purchaseResponse
Create_pending_purchaseResponse200
                                                (InvoiceCollection -> Create_pending_purchaseResponse)
-> Either String InvoiceCollection
-> Either String Create_pending_purchaseResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> ( ByteString -> Either String InvoiceCollection
forall a. FromJSON a => ByteString -> Either String a
Data.Aeson.eitherDecodeStrict ByteString
body ::
                                                                    Data.Either.Either
                                                                        GHC.Base.String
                                                                        InvoiceCollection
                                                                 )
                                        | (\Status
status_2 -> Status -> Int
Network.HTTP.Types.Status.statusCode Status
status_2 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Int
400) (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                            Error -> Create_pending_purchaseResponse
Create_pending_purchaseResponse400
                                                (Error -> Create_pending_purchaseResponse)
-> Either String Error
-> Either String Create_pending_purchaseResponse
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
                                                                 )
                                        | (\Status
status_3 -> Status -> Int
Network.HTTP.Types.Status.statusCode Status
status_3 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Int
422) (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                            Error -> Create_pending_purchaseResponse
Create_pending_purchaseResponse422
                                                (Error -> Create_pending_purchaseResponse)
-> Either String Error
-> Either String Create_pending_purchaseResponse
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 -> 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 -> Create_pending_purchaseResponse
Create_pending_purchaseResponseDefault
                                                (Error -> Create_pending_purchaseResponse)
-> Either String Error
-> Either String Create_pending_purchaseResponse
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 Create_pending_purchaseResponse
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 PurchaseCreate
-> RequestBodyEncoding
-> ClientT m (Response ByteString)
forall (m :: * -> *) body.
(MonadHTTP m, ToJSON body) =>
Text
-> Text
-> [QueryParameter]
-> Maybe body
-> RequestBodyEncoding
-> ClientT m (Response ByteString)
RecurlyClient.Common.doBodyCallWithConfigurationM (Text -> Text
Data.Text.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
GHC.Base.$ String -> Text
Data.Text.Internal.pack String
"POST") Text
"/purchases/pending" [QueryParameter]
forall a. Monoid a => a
GHC.Base.mempty (PurchaseCreate -> Maybe PurchaseCreate
forall a. a -> Maybe a
GHC.Maybe.Just PurchaseCreate
body) RequestBodyEncoding
RecurlyClient.Common.RequestBodyEncodingJSON)

{- | Represents a response of the operation 'create_pending_purchase'.

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), 'Create_pending_purchaseResponseError' is used.
-}
data Create_pending_purchaseResponse
    = -- | Means either no matching case available or a parse error
      Create_pending_purchaseResponseError GHC.Base.String
    | -- | Returns the pending invoice
      Create_pending_purchaseResponse200 InvoiceCollection
    | -- | Bad request; perhaps missing or invalid parameters.
      Create_pending_purchaseResponse400 Error
    | -- | Pending purchase cannot be completed for the specified reason.
      Create_pending_purchaseResponse422 Error
    | -- | Unexpected error.
      Create_pending_purchaseResponseDefault Error
    deriving (Int -> Create_pending_purchaseResponse -> ShowS
[Create_pending_purchaseResponse] -> ShowS
Create_pending_purchaseResponse -> String
(Int -> Create_pending_purchaseResponse -> ShowS)
-> (Create_pending_purchaseResponse -> String)
-> ([Create_pending_purchaseResponse] -> ShowS)
-> Show Create_pending_purchaseResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Create_pending_purchaseResponse -> ShowS
showsPrec :: Int -> Create_pending_purchaseResponse -> ShowS
$cshow :: Create_pending_purchaseResponse -> String
show :: Create_pending_purchaseResponse -> String
$cshowList :: [Create_pending_purchaseResponse] -> ShowS
showList :: [Create_pending_purchaseResponse] -> ShowS
GHC.Show.Show, Create_pending_purchaseResponse
-> Create_pending_purchaseResponse -> Bool
(Create_pending_purchaseResponse
 -> Create_pending_purchaseResponse -> Bool)
-> (Create_pending_purchaseResponse
    -> Create_pending_purchaseResponse -> Bool)
-> Eq Create_pending_purchaseResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Create_pending_purchaseResponse
-> Create_pending_purchaseResponse -> Bool
== :: Create_pending_purchaseResponse
-> Create_pending_purchaseResponse -> Bool
$c/= :: Create_pending_purchaseResponse
-> Create_pending_purchaseResponse -> Bool
/= :: Create_pending_purchaseResponse
-> Create_pending_purchaseResponse -> Bool
GHC.Classes.Eq)

{- | > POST /purchases/pending

The same as 'create_pending_purchase' but accepts an explicit configuration.
-}
create_pending_purchaseWithConfiguration ::
    forall m.
    (RecurlyClient.Common.MonadHTTP m) =>
    -- | The configuration to use in the request
    RecurlyClient.Common.Configuration ->
    -- | The request body to send
    PurchaseCreate ->
    -- | Monadic computation which returns the result of the operation
    m (Network.HTTP.Client.Types.Response Create_pending_purchaseResponse)
create_pending_purchaseWithConfiguration :: forall (m :: * -> *).
MonadHTTP m =>
Configuration
-> PurchaseCreate -> m (Response Create_pending_purchaseResponse)
create_pending_purchaseWithConfiguration
    Configuration
config
    PurchaseCreate
body =
        (Response ByteString -> Response Create_pending_purchaseResponse)
-> m (Response ByteString)
-> m (Response Create_pending_purchaseResponse)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
            ( \Response ByteString
response_4 ->
                (ByteString -> Create_pending_purchaseResponse)
-> Response ByteString -> Response Create_pending_purchaseResponse
forall a b. (a -> b) -> Response a -> Response b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
                    ( (String -> Create_pending_purchaseResponse)
-> (Create_pending_purchaseResponse
    -> Create_pending_purchaseResponse)
-> Either String Create_pending_purchaseResponse
-> Create_pending_purchaseResponse
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
Data.Either.either String -> Create_pending_purchaseResponse
Create_pending_purchaseResponseError Create_pending_purchaseResponse -> Create_pending_purchaseResponse
forall a. a -> a
GHC.Base.id
                        (Either String Create_pending_purchaseResponse
 -> Create_pending_purchaseResponse)
-> (ByteString -> Either String Create_pending_purchaseResponse)
-> ByteString
-> Create_pending_purchaseResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. ( \Response ByteString
response ByteString
body ->
                                        if
                                            | (\Status
status_5 -> Status -> Int
Network.HTTP.Types.Status.statusCode Status
status_5 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) ->
                                                InvoiceCollection -> Create_pending_purchaseResponse
Create_pending_purchaseResponse200
                                                    (InvoiceCollection -> Create_pending_purchaseResponse)
-> Either String InvoiceCollection
-> Either String Create_pending_purchaseResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> ( ByteString -> Either String InvoiceCollection
forall a. FromJSON a => ByteString -> Either String a
Data.Aeson.eitherDecodeStrict ByteString
body ::
                                                                        Data.Either.Either
                                                                            GHC.Base.String
                                                                            InvoiceCollection
                                                                     )
                                            | (\Status
status_6 -> Status -> Int
Network.HTTP.Types.Status.statusCode Status
status_6 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Int
400) (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                                Error -> Create_pending_purchaseResponse
Create_pending_purchaseResponse400
                                                    (Error -> Create_pending_purchaseResponse)
-> Either String Error
-> Either String Create_pending_purchaseResponse
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
                                                                     )
                                            | (\Status
status_7 -> Status -> Int
Network.HTTP.Types.Status.statusCode Status
status_7 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Int
422) (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                                Error -> Create_pending_purchaseResponse
Create_pending_purchaseResponse422
                                                    (Error -> Create_pending_purchaseResponse)
-> Either String Error
-> Either String Create_pending_purchaseResponse
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 -> 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 -> Create_pending_purchaseResponse
Create_pending_purchaseResponseDefault
                                                    (Error -> Create_pending_purchaseResponse)
-> Either String Error
-> Either String Create_pending_purchaseResponse
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 Create_pending_purchaseResponse
forall a b. a -> Either a b
Data.Either.Left String
"Missing default response type"
                                   )
                            Response ByteString
response_4
                    )
                    Response ByteString
response_4
            )
            (Configuration
-> Text
-> Text
-> [QueryParameter]
-> Maybe PurchaseCreate
-> RequestBodyEncoding
-> m (Response ByteString)
forall (m :: * -> *) body.
(MonadHTTP m, ToJSON body) =>
Configuration
-> Text
-> Text
-> [QueryParameter]
-> Maybe body
-> RequestBodyEncoding
-> m (Response ByteString)
RecurlyClient.Common.doBodyCallWithConfiguration Configuration
config (Text -> Text
Data.Text.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
GHC.Base.$ String -> Text
Data.Text.Internal.pack String
"POST") Text
"/purchases/pending" [QueryParameter]
forall a. Monoid a => a
GHC.Base.mempty (PurchaseCreate -> Maybe PurchaseCreate
forall a. a -> Maybe a
GHC.Maybe.Just PurchaseCreate
body) RequestBodyEncoding
RecurlyClient.Common.RequestBodyEncodingJSON)

{- | > POST /purchases/pending

The same as 'create_pending_purchase' but returns the raw 'Data.ByteString.ByteString'.
-}
create_pending_purchaseRaw ::
    forall m.
    (RecurlyClient.Common.MonadHTTP m) =>
    -- | The request body to send
    PurchaseCreate ->
    -- | Monadic computation which returns the result of the operation
    RecurlyClient.Common.ClientT m (Network.HTTP.Client.Types.Response Data.ByteString.Internal.Type.ByteString)
create_pending_purchaseRaw :: forall (m :: * -> *).
MonadHTTP m =>
PurchaseCreate -> ClientT m (Response ByteString)
create_pending_purchaseRaw PurchaseCreate
body = ClientT m (Response ByteString) -> ClientT m (Response ByteString)
forall a. a -> a
GHC.Base.id (Text
-> Text
-> [QueryParameter]
-> Maybe PurchaseCreate
-> RequestBodyEncoding
-> ClientT m (Response ByteString)
forall (m :: * -> *) body.
(MonadHTTP m, ToJSON body) =>
Text
-> Text
-> [QueryParameter]
-> Maybe body
-> RequestBodyEncoding
-> ClientT m (Response ByteString)
RecurlyClient.Common.doBodyCallWithConfigurationM (Text -> Text
Data.Text.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
GHC.Base.$ String -> Text
Data.Text.Internal.pack String
"POST") Text
"/purchases/pending" [QueryParameter]
forall a. Monoid a => a
GHC.Base.mempty (PurchaseCreate -> Maybe PurchaseCreate
forall a. a -> Maybe a
GHC.Maybe.Just PurchaseCreate
body) RequestBodyEncoding
RecurlyClient.Common.RequestBodyEncodingJSON)

{- | > POST /purchases/pending

The same as 'create_pending_purchase' but accepts an explicit configuration and returns the raw 'Data.ByteString.ByteString'.
-}
create_pending_purchaseWithConfigurationRaw ::
    forall m.
    (RecurlyClient.Common.MonadHTTP m) =>
    -- | The configuration to use in the request
    RecurlyClient.Common.Configuration ->
    -- | The request body to send
    PurchaseCreate ->
    -- | Monadic computation which returns the result of the operation
    m (Network.HTTP.Client.Types.Response Data.ByteString.Internal.Type.ByteString)
create_pending_purchaseWithConfigurationRaw :: forall (m :: * -> *).
MonadHTTP m =>
Configuration -> PurchaseCreate -> m (Response ByteString)
create_pending_purchaseWithConfigurationRaw
    Configuration
config
    PurchaseCreate
body = m (Response ByteString) -> m (Response ByteString)
forall a. a -> a
GHC.Base.id (Configuration
-> Text
-> Text
-> [QueryParameter]
-> Maybe PurchaseCreate
-> RequestBodyEncoding
-> m (Response ByteString)
forall (m :: * -> *) body.
(MonadHTTP m, ToJSON body) =>
Configuration
-> Text
-> Text
-> [QueryParameter]
-> Maybe body
-> RequestBodyEncoding
-> m (Response ByteString)
RecurlyClient.Common.doBodyCallWithConfiguration Configuration
config (Text -> Text
Data.Text.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
GHC.Base.$ String -> Text
Data.Text.Internal.pack String
"POST") Text
"/purchases/pending" [QueryParameter]
forall a. Monoid a => a
GHC.Base.mempty (PurchaseCreate -> Maybe PurchaseCreate
forall a. a -> Maybe a
GHC.Maybe.Just PurchaseCreate
body) RequestBodyEncoding
RecurlyClient.Common.RequestBodyEncodingJSON)