{-# 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 postCoupons module StripeAPI.Operations.PostCoupons 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/coupons -- -- \

You can create coupons easily via the \coupon management\<\/a> page of the Stripe dashboard. Coupon creation is also accessible via the API if you need to create coupons on the fly.\<\/p> -- -- \

A coupon has either a \percent_off\<\/code> or an \amount_off\<\/code> and \currency\<\/code>. If you set an \amount_off\<\/code>, that amount will be subtracted from any invoice’s subtotal. For example, an invoice with a subtotal of \100\<\/currency> will have a final total of \0\<\/currency> if a coupon with an \amount_off\<\/code> of \200\<\/amount> is applied to it and an invoice with a subtotal of \300\<\/currency> will have a final total of \100\<\/currency> if a coupon with an \amount_off\<\/code> of \200\<\/amount> is applied to it.\<\/p> postCoupons :: forall m. StripeAPI.Common.MonadHTTP m => -- | The request body to send GHC.Maybe.Maybe PostCouponsRequestBody -> -- | Monadic computation which returns the result of the operation StripeAPI.Common.ClientT m (Network.HTTP.Client.Types.Response PostCouponsResponse) postCoupons body = GHC.Base.fmap ( \response_0 -> GHC.Base.fmap ( Data.Either.either PostCouponsResponseError GHC.Base.id GHC.Base.. ( \response body -> if | (\status_1 -> Network.HTTP.Types.Status.statusCode status_1 GHC.Classes.== 200) (Network.HTTP.Client.Types.responseStatus response) -> PostCouponsResponse200 Data.Functor.<$> ( Data.Aeson.eitherDecodeStrict body :: Data.Either.Either GHC.Base.String Coupon ) | GHC.Base.const GHC.Types.True (Network.HTTP.Client.Types.responseStatus response) -> PostCouponsResponseDefault Data.Functor.<$> ( Data.Aeson.eitherDecodeStrict body :: Data.Either.Either GHC.Base.String Error ) | GHC.Base.otherwise -> Data.Either.Left "Missing default response type" ) response_0 ) response_0 ) (StripeAPI.Common.doBodyCallWithConfigurationM (Data.Text.toUpper GHC.Base.$ Data.Text.pack "POST") (Data.Text.pack "/v1/coupons") GHC.Base.mempty body StripeAPI.Common.RequestBodyEncodingFormData) -- | Defines the object schema located at @paths.\/v1\/coupons.POST.requestBody.content.application\/x-www-form-urlencoded.schema@ in the specification. data PostCouponsRequestBody = PostCouponsRequestBody { -- | amount_off: A positive integer representing the amount to subtract from an invoice total (required if \`percent_off\` is not passed). postCouponsRequestBodyAmountOff :: (GHC.Maybe.Maybe GHC.Types.Int), -- | applies_to: A hash containing directions for what this Coupon will apply discounts to. postCouponsRequestBodyAppliesTo :: (GHC.Maybe.Maybe PostCouponsRequestBodyAppliesTo'), -- | currency: Three-letter [ISO code for the currency](https:\/\/stripe.com\/docs\/currencies) of the \`amount_off\` parameter (required if \`amount_off\` is passed). postCouponsRequestBodyCurrency :: (GHC.Maybe.Maybe Data.Text.Internal.Text), -- | duration: Specifies how long the discount will be in effect if used on a subscription. Can be \`forever\`, \`once\`, or \`repeating\`. Defaults to \`once\`. postCouponsRequestBodyDuration :: (GHC.Maybe.Maybe PostCouponsRequestBodyDuration'), -- | duration_in_months: Required only if \`duration\` is \`repeating\`, in which case it must be a positive integer that specifies the number of months the discount will be in effect. postCouponsRequestBodyDurationInMonths :: (GHC.Maybe.Maybe GHC.Types.Int), -- | expand: Specifies which fields in the response should be expanded. postCouponsRequestBodyExpand :: (GHC.Maybe.Maybe ([Data.Text.Internal.Text])), -- | id: Unique string of your choice that will be used to identify this coupon when applying it to a customer. If you don\'t want to specify a particular code, you can leave the ID blank and we\'ll generate a random code for you. -- -- Constraints: -- -- * Maximum length of 5000 postCouponsRequestBodyId :: (GHC.Maybe.Maybe Data.Text.Internal.Text), -- | max_redemptions: A positive integer specifying the number of times the coupon can be redeemed before it\'s no longer valid. For example, you might have a 50% off coupon that the first 20 readers of your blog can use. postCouponsRequestBodyMaxRedemptions :: (GHC.Maybe.Maybe GHC.Types.Int), -- | 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\`. postCouponsRequestBodyMetadata :: (GHC.Maybe.Maybe PostCouponsRequestBodyMetadata'Variants), -- | name: Name of the coupon displayed to customers on, for instance invoices, or receipts. By default the \`id\` is shown if \`name\` is not set. -- -- Constraints: -- -- * Maximum length of 40 postCouponsRequestBodyName :: (GHC.Maybe.Maybe Data.Text.Internal.Text), -- | percent_off: A positive float larger than 0, and smaller or equal to 100, that represents the discount the coupon will apply (required if \`amount_off\` is not passed). postCouponsRequestBodyPercentOff :: (GHC.Maybe.Maybe GHC.Types.Double), -- | redeem_by: Unix timestamp specifying the last time at which the coupon can be redeemed. After the redeem_by date, the coupon can no longer be applied to new customers. postCouponsRequestBodyRedeemBy :: (GHC.Maybe.Maybe GHC.Types.Int) } deriving ( GHC.Show.Show, GHC.Classes.Eq ) instance Data.Aeson.Types.ToJSON.ToJSON PostCouponsRequestBody where toJSON obj = Data.Aeson.Types.Internal.object ("amount_off" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyAmountOff obj : "applies_to" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyAppliesTo obj : "currency" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyCurrency obj : "duration" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyDuration obj : "duration_in_months" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyDurationInMonths obj : "expand" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyExpand obj : "id" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyId obj : "max_redemptions" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyMaxRedemptions obj : "metadata" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyMetadata obj : "name" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyName obj : "percent_off" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyPercentOff obj : "redeem_by" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyRedeemBy obj : GHC.Base.mempty) toEncoding obj = Data.Aeson.Encoding.Internal.pairs (("amount_off" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyAmountOff obj) GHC.Base.<> (("applies_to" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyAppliesTo obj) GHC.Base.<> (("currency" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyCurrency obj) GHC.Base.<> (("duration" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyDuration obj) GHC.Base.<> (("duration_in_months" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyDurationInMonths obj) GHC.Base.<> (("expand" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyExpand obj) GHC.Base.<> (("id" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyId obj) GHC.Base.<> (("max_redemptions" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyMaxRedemptions obj) GHC.Base.<> (("metadata" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyMetadata obj) GHC.Base.<> (("name" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyName obj) GHC.Base.<> (("percent_off" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyPercentOff obj) GHC.Base.<> ("redeem_by" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyRedeemBy obj)))))))))))) instance Data.Aeson.Types.FromJSON.FromJSON PostCouponsRequestBody where parseJSON = Data.Aeson.Types.FromJSON.withObject "PostCouponsRequestBody" (\obj -> (((((((((((GHC.Base.pure PostCouponsRequestBody GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "amount_off")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "applies_to")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "currency")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "duration")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "duration_in_months")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "expand")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "id")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "max_redemptions")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "metadata")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "name")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "percent_off")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "redeem_by")) -- | Create a new 'PostCouponsRequestBody' with all required fields. mkPostCouponsRequestBody :: PostCouponsRequestBody mkPostCouponsRequestBody = PostCouponsRequestBody { postCouponsRequestBodyAmountOff = GHC.Maybe.Nothing, postCouponsRequestBodyAppliesTo = GHC.Maybe.Nothing, postCouponsRequestBodyCurrency = GHC.Maybe.Nothing, postCouponsRequestBodyDuration = GHC.Maybe.Nothing, postCouponsRequestBodyDurationInMonths = GHC.Maybe.Nothing, postCouponsRequestBodyExpand = GHC.Maybe.Nothing, postCouponsRequestBodyId = GHC.Maybe.Nothing, postCouponsRequestBodyMaxRedemptions = GHC.Maybe.Nothing, postCouponsRequestBodyMetadata = GHC.Maybe.Nothing, postCouponsRequestBodyName = GHC.Maybe.Nothing, postCouponsRequestBodyPercentOff = GHC.Maybe.Nothing, postCouponsRequestBodyRedeemBy = GHC.Maybe.Nothing } -- | Defines the object schema located at @paths.\/v1\/coupons.POST.requestBody.content.application\/x-www-form-urlencoded.schema.properties.applies_to@ in the specification. -- -- A hash containing directions for what this Coupon will apply discounts to. data PostCouponsRequestBodyAppliesTo' = PostCouponsRequestBodyAppliesTo' { -- | products postCouponsRequestBodyAppliesTo'Products :: (GHC.Maybe.Maybe ([Data.Text.Internal.Text])) } deriving ( GHC.Show.Show, GHC.Classes.Eq ) instance Data.Aeson.Types.ToJSON.ToJSON PostCouponsRequestBodyAppliesTo' where toJSON obj = Data.Aeson.Types.Internal.object ("products" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyAppliesTo'Products obj : GHC.Base.mempty) toEncoding obj = Data.Aeson.Encoding.Internal.pairs ("products" Data.Aeson.Types.ToJSON..= postCouponsRequestBodyAppliesTo'Products obj) instance Data.Aeson.Types.FromJSON.FromJSON PostCouponsRequestBodyAppliesTo' where parseJSON = Data.Aeson.Types.FromJSON.withObject "PostCouponsRequestBodyAppliesTo'" (\obj -> GHC.Base.pure PostCouponsRequestBodyAppliesTo' GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "products")) -- | Create a new 'PostCouponsRequestBodyAppliesTo'' with all required fields. mkPostCouponsRequestBodyAppliesTo' :: PostCouponsRequestBodyAppliesTo' mkPostCouponsRequestBodyAppliesTo' = PostCouponsRequestBodyAppliesTo' {postCouponsRequestBodyAppliesTo'Products = GHC.Maybe.Nothing} -- | Defines the enum schema located at @paths.\/v1\/coupons.POST.requestBody.content.application\/x-www-form-urlencoded.schema.properties.duration@ in the specification. -- -- Specifies how long the discount will be in effect if used on a subscription. Can be \`forever\`, \`once\`, or \`repeating\`. Defaults to \`once\`. data PostCouponsRequestBodyDuration' = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification. PostCouponsRequestBodyDuration'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. PostCouponsRequestBodyDuration'Typed Data.Text.Internal.Text | -- | Represents the JSON value @"forever"@ PostCouponsRequestBodyDuration'EnumForever | -- | Represents the JSON value @"once"@ PostCouponsRequestBodyDuration'EnumOnce | -- | Represents the JSON value @"repeating"@ PostCouponsRequestBodyDuration'EnumRepeating deriving (GHC.Show.Show, GHC.Classes.Eq) instance Data.Aeson.Types.ToJSON.ToJSON PostCouponsRequestBodyDuration' where toJSON (PostCouponsRequestBodyDuration'Other val) = val toJSON (PostCouponsRequestBodyDuration'Typed val) = Data.Aeson.Types.ToJSON.toJSON val toJSON (PostCouponsRequestBodyDuration'EnumForever) = "forever" toJSON (PostCouponsRequestBodyDuration'EnumOnce) = "once" toJSON (PostCouponsRequestBodyDuration'EnumRepeating) = "repeating" instance Data.Aeson.Types.FromJSON.FromJSON PostCouponsRequestBodyDuration' where parseJSON val = GHC.Base.pure ( if | val GHC.Classes.== "forever" -> PostCouponsRequestBodyDuration'EnumForever | val GHC.Classes.== "once" -> PostCouponsRequestBodyDuration'EnumOnce | val GHC.Classes.== "repeating" -> PostCouponsRequestBodyDuration'EnumRepeating | GHC.Base.otherwise -> PostCouponsRequestBodyDuration'Other val ) -- | Defines the oneOf schema located at @paths.\/v1\/coupons.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 PostCouponsRequestBodyMetadata'Variants = -- | Represents the JSON value @""@ PostCouponsRequestBodyMetadata'EmptyString | PostCouponsRequestBodyMetadata'Object Data.Aeson.Types.Internal.Object deriving (GHC.Show.Show, GHC.Classes.Eq) instance Data.Aeson.Types.ToJSON.ToJSON PostCouponsRequestBodyMetadata'Variants where toJSON (PostCouponsRequestBodyMetadata'Object a) = Data.Aeson.Types.ToJSON.toJSON a toJSON (PostCouponsRequestBodyMetadata'EmptyString) = "" instance Data.Aeson.Types.FromJSON.FromJSON PostCouponsRequestBodyMetadata'Variants where parseJSON val = if | val GHC.Classes.== "" -> GHC.Base.pure PostCouponsRequestBodyMetadata'EmptyString | GHC.Base.otherwise -> case (PostCouponsRequestBodyMetadata'Object Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> Data.Aeson.Types.Internal.Error "No variant matched" of Data.Aeson.Types.Internal.Success a -> GHC.Base.pure a Data.Aeson.Types.Internal.Error a -> Control.Monad.Fail.fail a -- | Represents a response of the operation 'postCoupons'. -- -- 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), 'PostCouponsResponseError' is used. data PostCouponsResponse = -- | Means either no matching case available or a parse error PostCouponsResponseError GHC.Base.String | -- | Successful response. PostCouponsResponse200 Coupon | -- | Error response. PostCouponsResponseDefault Error deriving (GHC.Show.Show, GHC.Classes.Eq)