{-# LANGUAGE MultiWayIf #-} -- CHANGE WITH CAUTION: This is a generated code file generated by https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator. {-# LANGUAGE OverloadedStrings #-} -- | Contains the types generated from the schema PromotionCode module StripeAPI.Types.PromotionCode where import qualified Control.Monad.Fail import qualified Data.Aeson import qualified Data.Aeson as Data.Aeson.Encoding.Internal import qualified Data.Aeson as Data.Aeson.Types import qualified Data.Aeson as Data.Aeson.Types.FromJSON import qualified Data.Aeson as Data.Aeson.Types.Internal import qualified Data.Aeson as Data.Aeson.Types.ToJSON import qualified Data.ByteString.Char8 import qualified Data.ByteString.Char8 as Data.ByteString.Internal import qualified Data.Functor import qualified Data.Scientific import qualified Data.Text import qualified Data.Text.Internal import qualified Data.Time.Calendar as Data.Time.Calendar.Days import qualified Data.Time.LocalTime as Data.Time.LocalTime.Internal.ZonedTime import qualified GHC.Base import qualified GHC.Classes import qualified GHC.Int import qualified GHC.Show import qualified GHC.Types import qualified StripeAPI.Common import StripeAPI.TypeAlias import {-# SOURCE #-} StripeAPI.Types.Coupon import {-# SOURCE #-} StripeAPI.Types.Customer import {-# SOURCE #-} StripeAPI.Types.DeletedCustomer import {-# SOURCE #-} StripeAPI.Types.PromotionCodesResourceRestrictions import qualified Prelude as GHC.Integer.Type import qualified Prelude as GHC.Maybe -- | Defines the object schema located at @components.schemas.promotion_code@ in the specification. -- -- A Promotion Code represents a customer-redeemable code for a coupon. It can be used to -- create multiple codes for a single coupon. data PromotionCode = PromotionCode { -- | active: Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid. promotionCodeActive :: GHC.Types.Bool, -- | code: The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for each customer. -- -- Constraints: -- -- * Maximum length of 5000 promotionCodeCode :: Data.Text.Internal.Text, -- | coupon: A coupon contains information about a percent-off or amount-off discount you -- might want to apply to a customer. Coupons may be applied to [invoices](https:\/\/stripe.com\/docs\/api\#invoices) or -- [orders](https:\/\/stripe.com\/docs\/api\#create_order-coupon). Coupons do not work with conventional one-off [charges](https:\/\/stripe.com\/docs\/api\#create_charge). promotionCodeCoupon :: Coupon, -- | created: Time at which the object was created. Measured in seconds since the Unix epoch. promotionCodeCreated :: GHC.Types.Int, -- | customer: The customer that this promotion code can be used by. promotionCodeCustomer :: (GHC.Maybe.Maybe PromotionCodeCustomer'Variants), -- | expires_at: Date at which the promotion code can no longer be redeemed. promotionCodeExpiresAt :: (GHC.Maybe.Maybe GHC.Types.Int), -- | id: Unique identifier for the object. -- -- Constraints: -- -- * Maximum length of 5000 promotionCodeId :: Data.Text.Internal.Text, -- | livemode: Has the value \`true\` if the object exists in live mode or the value \`false\` if the object exists in test mode. promotionCodeLivemode :: GHC.Types.Bool, -- | max_redemptions: Maximum number of times this promotion code can be redeemed. promotionCodeMaxRedemptions :: (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. promotionCodeMetadata :: (GHC.Maybe.Maybe Data.Aeson.Types.Internal.Object), -- | restrictions: promotionCodeRestrictions :: PromotionCodesResourceRestrictions, -- | times_redeemed: Number of times this promotion code has been used. promotionCodeTimesRedeemed :: GHC.Types.Int } deriving ( GHC.Show.Show, GHC.Classes.Eq ) instance Data.Aeson.Types.ToJSON.ToJSON PromotionCode where toJSON obj = Data.Aeson.Types.Internal.object ("active" Data.Aeson.Types.ToJSON..= promotionCodeActive obj : "code" Data.Aeson.Types.ToJSON..= promotionCodeCode obj : "coupon" Data.Aeson.Types.ToJSON..= promotionCodeCoupon obj : "created" Data.Aeson.Types.ToJSON..= promotionCodeCreated obj : "customer" Data.Aeson.Types.ToJSON..= promotionCodeCustomer obj : "expires_at" Data.Aeson.Types.ToJSON..= promotionCodeExpiresAt obj : "id" Data.Aeson.Types.ToJSON..= promotionCodeId obj : "livemode" Data.Aeson.Types.ToJSON..= promotionCodeLivemode obj : "max_redemptions" Data.Aeson.Types.ToJSON..= promotionCodeMaxRedemptions obj : "metadata" Data.Aeson.Types.ToJSON..= promotionCodeMetadata obj : "restrictions" Data.Aeson.Types.ToJSON..= promotionCodeRestrictions obj : "times_redeemed" Data.Aeson.Types.ToJSON..= promotionCodeTimesRedeemed obj : "object" Data.Aeson.Types.ToJSON..= Data.Aeson.Types.Internal.String "promotion_code" : GHC.Base.mempty) toEncoding obj = Data.Aeson.Encoding.Internal.pairs (("active" Data.Aeson.Types.ToJSON..= promotionCodeActive obj) GHC.Base.<> (("code" Data.Aeson.Types.ToJSON..= promotionCodeCode obj) GHC.Base.<> (("coupon" Data.Aeson.Types.ToJSON..= promotionCodeCoupon obj) GHC.Base.<> (("created" Data.Aeson.Types.ToJSON..= promotionCodeCreated obj) GHC.Base.<> (("customer" Data.Aeson.Types.ToJSON..= promotionCodeCustomer obj) GHC.Base.<> (("expires_at" Data.Aeson.Types.ToJSON..= promotionCodeExpiresAt obj) GHC.Base.<> (("id" Data.Aeson.Types.ToJSON..= promotionCodeId obj) GHC.Base.<> (("livemode" Data.Aeson.Types.ToJSON..= promotionCodeLivemode obj) GHC.Base.<> (("max_redemptions" Data.Aeson.Types.ToJSON..= promotionCodeMaxRedemptions obj) GHC.Base.<> (("metadata" Data.Aeson.Types.ToJSON..= promotionCodeMetadata obj) GHC.Base.<> (("restrictions" Data.Aeson.Types.ToJSON..= promotionCodeRestrictions obj) GHC.Base.<> (("times_redeemed" Data.Aeson.Types.ToJSON..= promotionCodeTimesRedeemed obj) GHC.Base.<> ("object" Data.Aeson.Types.ToJSON..= Data.Aeson.Types.Internal.String "promotion_code"))))))))))))) instance Data.Aeson.Types.FromJSON.FromJSON PromotionCode where parseJSON = Data.Aeson.Types.FromJSON.withObject "PromotionCode" (\obj -> (((((((((((GHC.Base.pure PromotionCode GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "active")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "code")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "coupon")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "created")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "customer")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "expires_at")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "id")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "livemode")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "max_redemptions")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "metadata")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "restrictions")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "times_redeemed")) -- | Create a new 'PromotionCode' with all required fields. mkPromotionCode :: -- | 'promotionCodeActive' GHC.Types.Bool -> -- | 'promotionCodeCode' Data.Text.Internal.Text -> -- | 'promotionCodeCoupon' Coupon -> -- | 'promotionCodeCreated' GHC.Types.Int -> -- | 'promotionCodeId' Data.Text.Internal.Text -> -- | 'promotionCodeLivemode' GHC.Types.Bool -> -- | 'promotionCodeRestrictions' PromotionCodesResourceRestrictions -> -- | 'promotionCodeTimesRedeemed' GHC.Types.Int -> PromotionCode mkPromotionCode promotionCodeActive promotionCodeCode promotionCodeCoupon promotionCodeCreated promotionCodeId promotionCodeLivemode promotionCodeRestrictions promotionCodeTimesRedeemed = PromotionCode { promotionCodeActive = promotionCodeActive, promotionCodeCode = promotionCodeCode, promotionCodeCoupon = promotionCodeCoupon, promotionCodeCreated = promotionCodeCreated, promotionCodeCustomer = GHC.Maybe.Nothing, promotionCodeExpiresAt = GHC.Maybe.Nothing, promotionCodeId = promotionCodeId, promotionCodeLivemode = promotionCodeLivemode, promotionCodeMaxRedemptions = GHC.Maybe.Nothing, promotionCodeMetadata = GHC.Maybe.Nothing, promotionCodeRestrictions = promotionCodeRestrictions, promotionCodeTimesRedeemed = promotionCodeTimesRedeemed } -- | Defines the oneOf schema located at @components.schemas.promotion_code.properties.customer.anyOf@ in the specification. -- -- The customer that this promotion code can be used by. data PromotionCodeCustomer'Variants = PromotionCodeCustomer'Text Data.Text.Internal.Text | PromotionCodeCustomer'Customer Customer | PromotionCodeCustomer'DeletedCustomer DeletedCustomer deriving (GHC.Show.Show, GHC.Classes.Eq) instance Data.Aeson.Types.ToJSON.ToJSON PromotionCodeCustomer'Variants where toJSON (PromotionCodeCustomer'Text a) = Data.Aeson.Types.ToJSON.toJSON a toJSON (PromotionCodeCustomer'Customer a) = Data.Aeson.Types.ToJSON.toJSON a toJSON (PromotionCodeCustomer'DeletedCustomer a) = Data.Aeson.Types.ToJSON.toJSON a instance Data.Aeson.Types.FromJSON.FromJSON PromotionCodeCustomer'Variants where parseJSON val = case (PromotionCodeCustomer'Text Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((PromotionCodeCustomer'Customer Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((PromotionCodeCustomer'DeletedCustomer 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