{-# 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 postChargesChargeRefund
module StripeAPI.Operations.PostChargesChargeRefund 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/charges/{charge}/refund
--
-- \<p>When you create a new refund, you must specify a Charge or a PaymentIntent object on which to create it.\<\/p>
--
-- \<p>Creating a new refund will refund a charge that has previously been created but not yet refunded.
-- Funds will be refunded to the credit or debit card that was originally charged.\<\/p>
--
-- \<p>You can optionally refund only part of a charge.
-- You can do so multiple times, until the entire charge has been refunded.\<\/p>
--
-- \<p>Once entirely refunded, a charge can’t be refunded again.
-- This method will raise an error when called on an already-refunded charge,
-- or when trying to refund more money than is left on a charge.\<\/p>
postChargesChargeRefund ::
  forall m.
  StripeAPI.Common.MonadHTTP m =>
  -- | charge | Constraints: Maximum length of 5000
  Data.Text.Internal.Text ->
  -- | The request body to send
  GHC.Maybe.Maybe PostChargesChargeRefundRequestBody ->
  -- | Monadic computation which returns the result of the operation
  StripeAPI.Common.StripeT m (Network.HTTP.Client.Types.Response PostChargesChargeRefundResponse)
postChargesChargeRefund :: Text
-> Maybe PostChargesChargeRefundRequestBody
-> StripeT m (Response PostChargesChargeRefundResponse)
postChargesChargeRefund
  Text
charge
  Maybe PostChargesChargeRefundRequestBody
body =
    (Response ByteString -> Response PostChargesChargeRefundResponse)
-> StripeT m (Response ByteString)
-> StripeT m (Response PostChargesChargeRefundResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
      ( \Response ByteString
response_0 ->
          (ByteString -> PostChargesChargeRefundResponse)
-> Response ByteString -> Response PostChargesChargeRefundResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
            ( (String -> PostChargesChargeRefundResponse)
-> (PostChargesChargeRefundResponse
    -> PostChargesChargeRefundResponse)
-> Either String PostChargesChargeRefundResponse
-> PostChargesChargeRefundResponse
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
Data.Either.either String -> PostChargesChargeRefundResponse
PostChargesChargeRefundResponseError PostChargesChargeRefundResponse -> PostChargesChargeRefundResponse
forall a. a -> a
GHC.Base.id
                (Either String PostChargesChargeRefundResponse
 -> PostChargesChargeRefundResponse)
-> (ByteString -> Either String PostChargesChargeRefundResponse)
-> ByteString
-> PostChargesChargeRefundResponse
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) ->
                                     Charge -> PostChargesChargeRefundResponse
PostChargesChargeRefundResponse200
                                       (Charge -> PostChargesChargeRefundResponse)
-> Either String Charge
-> Either String PostChargesChargeRefundResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> ( ByteString -> Either String Charge
forall a. FromJSON a => ByteString -> Either String a
Data.Aeson.eitherDecodeStrict ByteString
body ::
                                                            Data.Either.Either
                                                              GHC.Base.String
                                                              Charge
                                                        )
                                   | 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 -> PostChargesChargeRefundResponse
PostChargesChargeRefundResponseDefault
                                       (Error -> PostChargesChargeRefundResponse)
-> Either String Error
-> Either String PostChargesChargeRefundResponse
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 PostChargesChargeRefundResponse
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 PostChargesChargeRefundRequestBody
-> 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/charges/" String -> String -> String
forall a. [a] -> [a] -> [a]
GHC.Base.++ (ByteString -> String
Data.ByteString.Char8.unpack (Bool -> ByteString -> ByteString
Network.HTTP.Types.URI.urlEncode Bool
GHC.Types.True (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
GHC.Base.$ (String -> ByteString
Data.ByteString.Char8.pack (String -> ByteString) -> String -> ByteString
forall a b. (a -> b) -> a -> b
GHC.Base.$ Text -> String
forall a. StringifyModel a => a -> String
StripeAPI.Common.stringifyModel Text
charge)) String -> String -> String
forall a. [a] -> [a] -> [a]
GHC.Base.++ String
"/refund"))) [QueryParameter]
forall a. Monoid a => a
GHC.Base.mempty Maybe PostChargesChargeRefundRequestBody
body RequestBodyEncoding
StripeAPI.Common.RequestBodyEncodingFormData)

-- | Defines the object schema located at @paths.\/v1\/charges\/{charge}\/refund.POST.requestBody.content.application\/x-www-form-urlencoded.schema@ in the specification.
data PostChargesChargeRefundRequestBody = PostChargesChargeRefundRequestBody
  { -- | amount
    PostChargesChargeRefundRequestBody -> Maybe Int
postChargesChargeRefundRequestBodyAmount :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | expand: Specifies which fields in the response should be expanded.
    PostChargesChargeRefundRequestBody -> Maybe [Text]
postChargesChargeRefundRequestBodyExpand :: (GHC.Maybe.Maybe ([Data.Text.Internal.Text])),
    -- | metadata: Set of [key-value pairs](https:\/\/stripe.com\/docs\/api\/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to \`metadata\`.
    PostChargesChargeRefundRequestBody
-> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
postChargesChargeRefundRequestBodyMetadata :: (GHC.Maybe.Maybe PostChargesChargeRefundRequestBodyMetadata'Variants),
    -- | payment_intent
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    PostChargesChargeRefundRequestBody -> Maybe Text
postChargesChargeRefundRequestBodyPaymentIntent :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | reason
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    PostChargesChargeRefundRequestBody
-> Maybe PostChargesChargeRefundRequestBodyReason'
postChargesChargeRefundRequestBodyReason :: (GHC.Maybe.Maybe PostChargesChargeRefundRequestBodyReason'),
    -- | refund_application_fee
    PostChargesChargeRefundRequestBody -> Maybe Bool
postChargesChargeRefundRequestBodyRefundApplicationFee :: (GHC.Maybe.Maybe GHC.Types.Bool),
    -- | reverse_transfer
    PostChargesChargeRefundRequestBody -> Maybe Bool
postChargesChargeRefundRequestBodyReverseTransfer :: (GHC.Maybe.Maybe GHC.Types.Bool)
  }
  deriving
    ( Int -> PostChargesChargeRefundRequestBody -> String -> String
[PostChargesChargeRefundRequestBody] -> String -> String
PostChargesChargeRefundRequestBody -> String
(Int -> PostChargesChargeRefundRequestBody -> String -> String)
-> (PostChargesChargeRefundRequestBody -> String)
-> ([PostChargesChargeRefundRequestBody] -> String -> String)
-> Show PostChargesChargeRefundRequestBody
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [PostChargesChargeRefundRequestBody] -> String -> String
$cshowList :: [PostChargesChargeRefundRequestBody] -> String -> String
show :: PostChargesChargeRefundRequestBody -> String
$cshow :: PostChargesChargeRefundRequestBody -> String
showsPrec :: Int -> PostChargesChargeRefundRequestBody -> String -> String
$cshowsPrec :: Int -> PostChargesChargeRefundRequestBody -> String -> String
GHC.Show.Show,
      PostChargesChargeRefundRequestBody
-> PostChargesChargeRefundRequestBody -> Bool
(PostChargesChargeRefundRequestBody
 -> PostChargesChargeRefundRequestBody -> Bool)
-> (PostChargesChargeRefundRequestBody
    -> PostChargesChargeRefundRequestBody -> Bool)
-> Eq PostChargesChargeRefundRequestBody
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostChargesChargeRefundRequestBody
-> PostChargesChargeRefundRequestBody -> Bool
$c/= :: PostChargesChargeRefundRequestBody
-> PostChargesChargeRefundRequestBody -> Bool
== :: PostChargesChargeRefundRequestBody
-> PostChargesChargeRefundRequestBody -> Bool
$c== :: PostChargesChargeRefundRequestBody
-> PostChargesChargeRefundRequestBody -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON PostChargesChargeRefundRequestBody where
  toJSON :: PostChargesChargeRefundRequestBody -> Value
toJSON PostChargesChargeRefundRequestBody
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"amount" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Int
postChargesChargeRefundRequestBodyAmount PostChargesChargeRefundRequestBody
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..= PostChargesChargeRefundRequestBody -> Maybe [Text]
postChargesChargeRefundRequestBodyExpand PostChargesChargeRefundRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"metadata" Text
-> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
-> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody
-> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
postChargesChargeRefundRequestBodyMetadata PostChargesChargeRefundRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"payment_intent" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Text
postChargesChargeRefundRequestBodyPaymentIntent PostChargesChargeRefundRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"reason" Text -> Maybe PostChargesChargeRefundRequestBodyReason' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody
-> Maybe PostChargesChargeRefundRequestBodyReason'
postChargesChargeRefundRequestBodyReason PostChargesChargeRefundRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"refund_application_fee" Text -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Bool
postChargesChargeRefundRequestBodyRefundApplicationFee PostChargesChargeRefundRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"reverse_transfer" Text -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Bool
postChargesChargeRefundRequestBodyReverseTransfer PostChargesChargeRefundRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: PostChargesChargeRefundRequestBody -> Encoding
toEncoding PostChargesChargeRefundRequestBody
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"amount" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Int
postChargesChargeRefundRequestBodyAmount PostChargesChargeRefundRequestBody
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..= PostChargesChargeRefundRequestBody -> Maybe [Text]
postChargesChargeRefundRequestBodyExpand PostChargesChargeRefundRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"metadata" Text
-> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
-> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody
-> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
postChargesChargeRefundRequestBodyMetadata PostChargesChargeRefundRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"payment_intent" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Text
postChargesChargeRefundRequestBodyPaymentIntent PostChargesChargeRefundRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"reason" Text -> Maybe PostChargesChargeRefundRequestBodyReason' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody
-> Maybe PostChargesChargeRefundRequestBodyReason'
postChargesChargeRefundRequestBodyReason PostChargesChargeRefundRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"refund_application_fee" Text -> Maybe Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Bool
postChargesChargeRefundRequestBodyRefundApplicationFee PostChargesChargeRefundRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"reverse_transfer" Text -> Maybe Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostChargesChargeRefundRequestBody -> Maybe Bool
postChargesChargeRefundRequestBodyReverseTransfer PostChargesChargeRefundRequestBody
obj)))))))

instance Data.Aeson.Types.FromJSON.FromJSON PostChargesChargeRefundRequestBody where
  parseJSON :: Value -> Parser PostChargesChargeRefundRequestBody
parseJSON = String
-> (Object -> Parser PostChargesChargeRefundRequestBody)
-> Value
-> Parser PostChargesChargeRefundRequestBody
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"PostChargesChargeRefundRequestBody" (\Object
obj -> (((((((Maybe Int
 -> Maybe [Text]
 -> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
 -> Maybe Text
 -> Maybe PostChargesChargeRefundRequestBodyReason'
 -> Maybe Bool
 -> Maybe Bool
 -> PostChargesChargeRefundRequestBody)
-> Parser
     (Maybe Int
      -> Maybe [Text]
      -> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
      -> Maybe Text
      -> Maybe PostChargesChargeRefundRequestBodyReason'
      -> Maybe Bool
      -> Maybe Bool
      -> PostChargesChargeRefundRequestBody)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Int
-> Maybe [Text]
-> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
-> Maybe Text
-> Maybe PostChargesChargeRefundRequestBodyReason'
-> Maybe Bool
-> Maybe Bool
-> PostChargesChargeRefundRequestBody
PostChargesChargeRefundRequestBody Parser
  (Maybe Int
   -> Maybe [Text]
   -> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
   -> Maybe Text
   -> Maybe PostChargesChargeRefundRequestBodyReason'
   -> Maybe Bool
   -> Maybe Bool
   -> PostChargesChargeRefundRequestBody)
-> Parser (Maybe Int)
-> Parser
     (Maybe [Text]
      -> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
      -> Maybe Text
      -> Maybe PostChargesChargeRefundRequestBodyReason'
      -> Maybe Bool
      -> Maybe Bool
      -> PostChargesChargeRefundRequestBody)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"amount")) Parser
  (Maybe [Text]
   -> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
   -> Maybe Text
   -> Maybe PostChargesChargeRefundRequestBodyReason'
   -> Maybe Bool
   -> Maybe Bool
   -> PostChargesChargeRefundRequestBody)
-> Parser (Maybe [Text])
-> Parser
     (Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
      -> Maybe Text
      -> Maybe PostChargesChargeRefundRequestBodyReason'
      -> Maybe Bool
      -> Maybe Bool
      -> PostChargesChargeRefundRequestBody)
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 PostChargesChargeRefundRequestBodyMetadata'Variants
   -> Maybe Text
   -> Maybe PostChargesChargeRefundRequestBodyReason'
   -> Maybe Bool
   -> Maybe Bool
   -> PostChargesChargeRefundRequestBody)
-> Parser
     (Maybe PostChargesChargeRefundRequestBodyMetadata'Variants)
-> Parser
     (Maybe Text
      -> Maybe PostChargesChargeRefundRequestBodyReason'
      -> Maybe Bool
      -> Maybe Bool
      -> PostChargesChargeRefundRequestBody)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object
-> Text
-> Parser
     (Maybe PostChargesChargeRefundRequestBodyMetadata'Variants)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"metadata")) Parser
  (Maybe Text
   -> Maybe PostChargesChargeRefundRequestBodyReason'
   -> Maybe Bool
   -> Maybe Bool
   -> PostChargesChargeRefundRequestBody)
-> Parser (Maybe Text)
-> Parser
     (Maybe PostChargesChargeRefundRequestBodyReason'
      -> Maybe Bool -> Maybe Bool -> PostChargesChargeRefundRequestBody)
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
"payment_intent")) Parser
  (Maybe PostChargesChargeRefundRequestBodyReason'
   -> Maybe Bool -> Maybe Bool -> PostChargesChargeRefundRequestBody)
-> Parser (Maybe PostChargesChargeRefundRequestBodyReason')
-> Parser
     (Maybe Bool -> Maybe Bool -> PostChargesChargeRefundRequestBody)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object
-> Text -> Parser (Maybe PostChargesChargeRefundRequestBodyReason')
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"reason")) Parser
  (Maybe Bool -> Maybe Bool -> PostChargesChargeRefundRequestBody)
-> Parser (Maybe Bool)
-> Parser (Maybe Bool -> PostChargesChargeRefundRequestBody)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"refund_application_fee")) Parser (Maybe Bool -> PostChargesChargeRefundRequestBody)
-> Parser (Maybe Bool) -> Parser PostChargesChargeRefundRequestBody
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"reverse_transfer"))

-- | Create a new 'PostChargesChargeRefundRequestBody' with all required fields.
mkPostChargesChargeRefundRequestBody :: PostChargesChargeRefundRequestBody
mkPostChargesChargeRefundRequestBody :: PostChargesChargeRefundRequestBody
mkPostChargesChargeRefundRequestBody =
  PostChargesChargeRefundRequestBody :: Maybe Int
-> Maybe [Text]
-> Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
-> Maybe Text
-> Maybe PostChargesChargeRefundRequestBodyReason'
-> Maybe Bool
-> Maybe Bool
-> PostChargesChargeRefundRequestBody
PostChargesChargeRefundRequestBody
    { postChargesChargeRefundRequestBodyAmount :: Maybe Int
postChargesChargeRefundRequestBodyAmount = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      postChargesChargeRefundRequestBodyExpand :: Maybe [Text]
postChargesChargeRefundRequestBodyExpand = Maybe [Text]
forall a. Maybe a
GHC.Maybe.Nothing,
      postChargesChargeRefundRequestBodyMetadata :: Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
postChargesChargeRefundRequestBodyMetadata = Maybe PostChargesChargeRefundRequestBodyMetadata'Variants
forall a. Maybe a
GHC.Maybe.Nothing,
      postChargesChargeRefundRequestBodyPaymentIntent :: Maybe Text
postChargesChargeRefundRequestBodyPaymentIntent = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      postChargesChargeRefundRequestBodyReason :: Maybe PostChargesChargeRefundRequestBodyReason'
postChargesChargeRefundRequestBodyReason = Maybe PostChargesChargeRefundRequestBodyReason'
forall a. Maybe a
GHC.Maybe.Nothing,
      postChargesChargeRefundRequestBodyRefundApplicationFee :: Maybe Bool
postChargesChargeRefundRequestBodyRefundApplicationFee = Maybe Bool
forall a. Maybe a
GHC.Maybe.Nothing,
      postChargesChargeRefundRequestBodyReverseTransfer :: Maybe Bool
postChargesChargeRefundRequestBodyReverseTransfer = Maybe Bool
forall a. Maybe a
GHC.Maybe.Nothing
    }

-- | Defines the oneOf schema located at @paths.\/v1\/charges\/{charge}\/refund.POST.requestBody.content.application\/x-www-form-urlencoded.schema.properties.metadata.anyOf@ in the specification.
--
-- Set of [key-value pairs](https:\/\/stripe.com\/docs\/api\/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to \`metadata\`.
data PostChargesChargeRefundRequestBodyMetadata'Variants
  = -- | Represents the JSON value @""@
    PostChargesChargeRefundRequestBodyMetadata'EmptyString
  | PostChargesChargeRefundRequestBodyMetadata'Object Data.Aeson.Types.Internal.Object
  deriving (Int
-> PostChargesChargeRefundRequestBodyMetadata'Variants
-> String
-> String
[PostChargesChargeRefundRequestBodyMetadata'Variants]
-> String -> String
PostChargesChargeRefundRequestBodyMetadata'Variants -> String
(Int
 -> PostChargesChargeRefundRequestBodyMetadata'Variants
 -> String
 -> String)
-> (PostChargesChargeRefundRequestBodyMetadata'Variants -> String)
-> ([PostChargesChargeRefundRequestBodyMetadata'Variants]
    -> String -> String)
-> Show PostChargesChargeRefundRequestBodyMetadata'Variants
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [PostChargesChargeRefundRequestBodyMetadata'Variants]
-> String -> String
$cshowList :: [PostChargesChargeRefundRequestBodyMetadata'Variants]
-> String -> String
show :: PostChargesChargeRefundRequestBodyMetadata'Variants -> String
$cshow :: PostChargesChargeRefundRequestBodyMetadata'Variants -> String
showsPrec :: Int
-> PostChargesChargeRefundRequestBodyMetadata'Variants
-> String
-> String
$cshowsPrec :: Int
-> PostChargesChargeRefundRequestBodyMetadata'Variants
-> String
-> String
GHC.Show.Show, PostChargesChargeRefundRequestBodyMetadata'Variants
-> PostChargesChargeRefundRequestBodyMetadata'Variants -> Bool
(PostChargesChargeRefundRequestBodyMetadata'Variants
 -> PostChargesChargeRefundRequestBodyMetadata'Variants -> Bool)
-> (PostChargesChargeRefundRequestBodyMetadata'Variants
    -> PostChargesChargeRefundRequestBodyMetadata'Variants -> Bool)
-> Eq PostChargesChargeRefundRequestBodyMetadata'Variants
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostChargesChargeRefundRequestBodyMetadata'Variants
-> PostChargesChargeRefundRequestBodyMetadata'Variants -> Bool
$c/= :: PostChargesChargeRefundRequestBodyMetadata'Variants
-> PostChargesChargeRefundRequestBodyMetadata'Variants -> Bool
== :: PostChargesChargeRefundRequestBodyMetadata'Variants
-> PostChargesChargeRefundRequestBodyMetadata'Variants -> Bool
$c== :: PostChargesChargeRefundRequestBodyMetadata'Variants
-> PostChargesChargeRefundRequestBodyMetadata'Variants -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON PostChargesChargeRefundRequestBodyMetadata'Variants where
  toJSON :: PostChargesChargeRefundRequestBodyMetadata'Variants -> Value
toJSON (PostChargesChargeRefundRequestBodyMetadata'Object Object
a) = Object -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Object
a
  toJSON (PostChargesChargeRefundRequestBodyMetadata'Variants
PostChargesChargeRefundRequestBodyMetadata'EmptyString) = Value
""

instance Data.Aeson.Types.FromJSON.FromJSON PostChargesChargeRefundRequestBodyMetadata'Variants where
  parseJSON :: Value -> Parser PostChargesChargeRefundRequestBodyMetadata'Variants
parseJSON Value
val =
    if
        | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"" -> PostChargesChargeRefundRequestBodyMetadata'Variants
-> Parser PostChargesChargeRefundRequestBodyMetadata'Variants
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure PostChargesChargeRefundRequestBodyMetadata'Variants
PostChargesChargeRefundRequestBodyMetadata'EmptyString
        | Bool
GHC.Base.otherwise -> case (Object -> PostChargesChargeRefundRequestBodyMetadata'Variants
PostChargesChargeRefundRequestBodyMetadata'Object (Object -> PostChargesChargeRefundRequestBodyMetadata'Variants)
-> Result Object
-> Result PostChargesChargeRefundRequestBodyMetadata'Variants
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> Value -> Result Object
forall a. FromJSON a => Value -> Result a
Data.Aeson.Types.FromJSON.fromJSON Value
val) Result PostChargesChargeRefundRequestBodyMetadata'Variants
-> Result PostChargesChargeRefundRequestBodyMetadata'Variants
-> Result PostChargesChargeRefundRequestBodyMetadata'Variants
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
GHC.Base.<|> String
-> Result PostChargesChargeRefundRequestBodyMetadata'Variants
forall a. String -> Result a
Data.Aeson.Types.Internal.Error String
"No variant matched" of
          Data.Aeson.Types.Internal.Success PostChargesChargeRefundRequestBodyMetadata'Variants
a -> PostChargesChargeRefundRequestBodyMetadata'Variants
-> Parser PostChargesChargeRefundRequestBodyMetadata'Variants
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure PostChargesChargeRefundRequestBodyMetadata'Variants
a
          Data.Aeson.Types.Internal.Error String
a -> String
-> Parser PostChargesChargeRefundRequestBodyMetadata'Variants
forall (m :: * -> *) a. MonadFail m => String -> m a
Control.Monad.Fail.fail String
a

-- | Defines the enum schema located at @paths.\/v1\/charges\/{charge}\/refund.POST.requestBody.content.application\/x-www-form-urlencoded.schema.properties.reason@ in the specification.
data PostChargesChargeRefundRequestBodyReason'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    PostChargesChargeRefundRequestBodyReason'Other Data.Aeson.Types.Internal.Value
  | -- | This constructor can be used to send values to the server which are not present in the specification yet.
    PostChargesChargeRefundRequestBodyReason'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"duplicate"@
    PostChargesChargeRefundRequestBodyReason'EnumDuplicate
  | -- | Represents the JSON value @"fraudulent"@
    PostChargesChargeRefundRequestBodyReason'EnumFraudulent
  | -- | Represents the JSON value @"requested_by_customer"@
    PostChargesChargeRefundRequestBodyReason'EnumRequestedByCustomer
  deriving (Int
-> PostChargesChargeRefundRequestBodyReason' -> String -> String
[PostChargesChargeRefundRequestBodyReason'] -> String -> String
PostChargesChargeRefundRequestBodyReason' -> String
(Int
 -> PostChargesChargeRefundRequestBodyReason' -> String -> String)
-> (PostChargesChargeRefundRequestBodyReason' -> String)
-> ([PostChargesChargeRefundRequestBodyReason']
    -> String -> String)
-> Show PostChargesChargeRefundRequestBodyReason'
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [PostChargesChargeRefundRequestBodyReason'] -> String -> String
$cshowList :: [PostChargesChargeRefundRequestBodyReason'] -> String -> String
show :: PostChargesChargeRefundRequestBodyReason' -> String
$cshow :: PostChargesChargeRefundRequestBodyReason' -> String
showsPrec :: Int
-> PostChargesChargeRefundRequestBodyReason' -> String -> String
$cshowsPrec :: Int
-> PostChargesChargeRefundRequestBodyReason' -> String -> String
GHC.Show.Show, PostChargesChargeRefundRequestBodyReason'
-> PostChargesChargeRefundRequestBodyReason' -> Bool
(PostChargesChargeRefundRequestBodyReason'
 -> PostChargesChargeRefundRequestBodyReason' -> Bool)
-> (PostChargesChargeRefundRequestBodyReason'
    -> PostChargesChargeRefundRequestBodyReason' -> Bool)
-> Eq PostChargesChargeRefundRequestBodyReason'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostChargesChargeRefundRequestBodyReason'
-> PostChargesChargeRefundRequestBodyReason' -> Bool
$c/= :: PostChargesChargeRefundRequestBodyReason'
-> PostChargesChargeRefundRequestBodyReason' -> Bool
== :: PostChargesChargeRefundRequestBodyReason'
-> PostChargesChargeRefundRequestBodyReason' -> Bool
$c== :: PostChargesChargeRefundRequestBodyReason'
-> PostChargesChargeRefundRequestBodyReason' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON PostChargesChargeRefundRequestBodyReason' where
  toJSON :: PostChargesChargeRefundRequestBodyReason' -> Value
toJSON (PostChargesChargeRefundRequestBodyReason'Other Value
val) = Value
val
  toJSON (PostChargesChargeRefundRequestBodyReason'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (PostChargesChargeRefundRequestBodyReason'
PostChargesChargeRefundRequestBodyReason'EnumDuplicate) = Value
"duplicate"
  toJSON (PostChargesChargeRefundRequestBodyReason'
PostChargesChargeRefundRequestBodyReason'EnumFraudulent) = Value
"fraudulent"
  toJSON (PostChargesChargeRefundRequestBodyReason'
PostChargesChargeRefundRequestBodyReason'EnumRequestedByCustomer) = Value
"requested_by_customer"

instance Data.Aeson.Types.FromJSON.FromJSON PostChargesChargeRefundRequestBodyReason' where
  parseJSON :: Value -> Parser PostChargesChargeRefundRequestBodyReason'
parseJSON Value
val =
    PostChargesChargeRefundRequestBodyReason'
-> Parser PostChargesChargeRefundRequestBodyReason'
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure
      ( if
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"duplicate" -> PostChargesChargeRefundRequestBodyReason'
PostChargesChargeRefundRequestBodyReason'EnumDuplicate
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"fraudulent" -> PostChargesChargeRefundRequestBodyReason'
PostChargesChargeRefundRequestBodyReason'EnumFraudulent
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"requested_by_customer" -> PostChargesChargeRefundRequestBodyReason'
PostChargesChargeRefundRequestBodyReason'EnumRequestedByCustomer
            | Bool
GHC.Base.otherwise -> Value -> PostChargesChargeRefundRequestBodyReason'
PostChargesChargeRefundRequestBodyReason'Other Value
val
      )

-- | Represents a response of the operation 'postChargesChargeRefund'.
--
-- 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), 'PostChargesChargeRefundResponseError' is used.
data PostChargesChargeRefundResponse
  = -- | Means either no matching case available or a parse error
    PostChargesChargeRefundResponseError GHC.Base.String
  | -- | Successful response.
    PostChargesChargeRefundResponse200 Charge
  | -- | Error response.
    PostChargesChargeRefundResponseDefault Error
  deriving (Int -> PostChargesChargeRefundResponse -> String -> String
[PostChargesChargeRefundResponse] -> String -> String
PostChargesChargeRefundResponse -> String
(Int -> PostChargesChargeRefundResponse -> String -> String)
-> (PostChargesChargeRefundResponse -> String)
-> ([PostChargesChargeRefundResponse] -> String -> String)
-> Show PostChargesChargeRefundResponse
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [PostChargesChargeRefundResponse] -> String -> String
$cshowList :: [PostChargesChargeRefundResponse] -> String -> String
show :: PostChargesChargeRefundResponse -> String
$cshow :: PostChargesChargeRefundResponse -> String
showsPrec :: Int -> PostChargesChargeRefundResponse -> String -> String
$cshowsPrec :: Int -> PostChargesChargeRefundResponse -> String -> String
GHC.Show.Show, PostChargesChargeRefundResponse
-> PostChargesChargeRefundResponse -> Bool
(PostChargesChargeRefundResponse
 -> PostChargesChargeRefundResponse -> Bool)
-> (PostChargesChargeRefundResponse
    -> PostChargesChargeRefundResponse -> Bool)
-> Eq PostChargesChargeRefundResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostChargesChargeRefundResponse
-> PostChargesChargeRefundResponse -> Bool
$c/= :: PostChargesChargeRefundResponse
-> PostChargesChargeRefundResponse -> Bool
== :: PostChargesChargeRefundResponse
-> PostChargesChargeRefundResponse -> Bool
$c== :: PostChargesChargeRefundResponse
-> PostChargesChargeRefundResponse -> Bool
GHC.Classes.Eq)