{-# 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 Discount module StripeAPI.Types.Discount 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.PromotionCode import qualified Prelude as GHC.Integer.Type import qualified Prelude as GHC.Maybe -- | Defines the object schema located at @components.schemas.discount@ in the specification. -- -- A discount represents the actual application of a coupon to a particular -- customer. It contains information about when the discount began and when it -- will end. -- -- Related guide: [Applying Discounts to Subscriptions](https:\/\/stripe.com\/docs\/billing\/subscriptions\/discounts). data Discount = Discount { -- | checkout_session: The Checkout session that this coupon is applied to, if it is applied to a particular session in payment mode. Will not be present for subscription mode. -- -- Constraints: -- -- * Maximum length of 5000 discountCheckoutSession :: (GHC.Maybe.Maybe 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). discountCoupon :: Coupon, -- | customer: The ID of the customer associated with this discount. discountCustomer :: (GHC.Maybe.Maybe DiscountCustomer'Variants), -- | end: If the coupon has a duration of \`repeating\`, the date that this discount will end. If the coupon has a duration of \`once\` or \`forever\`, this attribute will be null. discountEnd :: (GHC.Maybe.Maybe GHC.Types.Int), -- | id: The ID of the discount object. Discounts cannot be fetched by ID. Use \`expand[]=discounts\` in API calls to expand discount IDs in an array. -- -- Constraints: -- -- * Maximum length of 5000 discountId :: Data.Text.Internal.Text, -- | invoice: The invoice that the discount\'s coupon was applied to, if it was applied directly to a particular invoice. -- -- Constraints: -- -- * Maximum length of 5000 discountInvoice :: (GHC.Maybe.Maybe Data.Text.Internal.Text), -- | invoice_item: The invoice item \`id\` (or invoice line item \`id\` for invoice line items of type=\'subscription\') that the discount\'s coupon was applied to, if it was applied directly to a particular invoice item or invoice line item. -- -- Constraints: -- -- * Maximum length of 5000 discountInvoiceItem :: (GHC.Maybe.Maybe Data.Text.Internal.Text), -- | promotion_code: The promotion code applied to create this discount. discountPromotionCode :: (GHC.Maybe.Maybe DiscountPromotionCode'Variants), -- | start: Date that the coupon was applied. discountStart :: GHC.Types.Int, -- | subscription: The subscription that this coupon is applied to, if it is applied to a particular subscription. -- -- Constraints: -- -- * Maximum length of 5000 discountSubscription :: (GHC.Maybe.Maybe Data.Text.Internal.Text) } deriving ( GHC.Show.Show, GHC.Classes.Eq ) instance Data.Aeson.Types.ToJSON.ToJSON Discount where toJSON obj = Data.Aeson.Types.Internal.object ("checkout_session" Data.Aeson.Types.ToJSON..= discountCheckoutSession obj : "coupon" Data.Aeson.Types.ToJSON..= discountCoupon obj : "customer" Data.Aeson.Types.ToJSON..= discountCustomer obj : "end" Data.Aeson.Types.ToJSON..= discountEnd obj : "id" Data.Aeson.Types.ToJSON..= discountId obj : "invoice" Data.Aeson.Types.ToJSON..= discountInvoice obj : "invoice_item" Data.Aeson.Types.ToJSON..= discountInvoiceItem obj : "promotion_code" Data.Aeson.Types.ToJSON..= discountPromotionCode obj : "start" Data.Aeson.Types.ToJSON..= discountStart obj : "subscription" Data.Aeson.Types.ToJSON..= discountSubscription obj : "object" Data.Aeson.Types.ToJSON..= Data.Aeson.Types.Internal.String "discount" : GHC.Base.mempty) toEncoding obj = Data.Aeson.Encoding.Internal.pairs (("checkout_session" Data.Aeson.Types.ToJSON..= discountCheckoutSession obj) GHC.Base.<> (("coupon" Data.Aeson.Types.ToJSON..= discountCoupon obj) GHC.Base.<> (("customer" Data.Aeson.Types.ToJSON..= discountCustomer obj) GHC.Base.<> (("end" Data.Aeson.Types.ToJSON..= discountEnd obj) GHC.Base.<> (("id" Data.Aeson.Types.ToJSON..= discountId obj) GHC.Base.<> (("invoice" Data.Aeson.Types.ToJSON..= discountInvoice obj) GHC.Base.<> (("invoice_item" Data.Aeson.Types.ToJSON..= discountInvoiceItem obj) GHC.Base.<> (("promotion_code" Data.Aeson.Types.ToJSON..= discountPromotionCode obj) GHC.Base.<> (("start" Data.Aeson.Types.ToJSON..= discountStart obj) GHC.Base.<> (("subscription" Data.Aeson.Types.ToJSON..= discountSubscription obj) GHC.Base.<> ("object" Data.Aeson.Types.ToJSON..= Data.Aeson.Types.Internal.String "discount"))))))))))) instance Data.Aeson.Types.FromJSON.FromJSON Discount where parseJSON = Data.Aeson.Types.FromJSON.withObject "Discount" (\obj -> (((((((((GHC.Base.pure Discount GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "checkout_session")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "coupon")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "customer")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "end")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "id")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "invoice")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "invoice_item")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "promotion_code")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..: "start")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "subscription")) -- | Create a new 'Discount' with all required fields. mkDiscount :: -- | 'discountCoupon' Coupon -> -- | 'discountId' Data.Text.Internal.Text -> -- | 'discountStart' GHC.Types.Int -> Discount mkDiscount discountCoupon discountId discountStart = Discount { discountCheckoutSession = GHC.Maybe.Nothing, discountCoupon = discountCoupon, discountCustomer = GHC.Maybe.Nothing, discountEnd = GHC.Maybe.Nothing, discountId = discountId, discountInvoice = GHC.Maybe.Nothing, discountInvoiceItem = GHC.Maybe.Nothing, discountPromotionCode = GHC.Maybe.Nothing, discountStart = discountStart, discountSubscription = GHC.Maybe.Nothing } -- | Defines the oneOf schema located at @components.schemas.discount.properties.customer.anyOf@ in the specification. -- -- The ID of the customer associated with this discount. data DiscountCustomer'Variants = DiscountCustomer'Text Data.Text.Internal.Text | DiscountCustomer'Customer Customer | DiscountCustomer'DeletedCustomer DeletedCustomer deriving (GHC.Show.Show, GHC.Classes.Eq) instance Data.Aeson.Types.ToJSON.ToJSON DiscountCustomer'Variants where toJSON (DiscountCustomer'Text a) = Data.Aeson.Types.ToJSON.toJSON a toJSON (DiscountCustomer'Customer a) = Data.Aeson.Types.ToJSON.toJSON a toJSON (DiscountCustomer'DeletedCustomer a) = Data.Aeson.Types.ToJSON.toJSON a instance Data.Aeson.Types.FromJSON.FromJSON DiscountCustomer'Variants where parseJSON val = case (DiscountCustomer'Text Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((DiscountCustomer'Customer Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((DiscountCustomer'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 -- | Defines the oneOf schema located at @components.schemas.discount.properties.promotion_code.anyOf@ in the specification. -- -- The promotion code applied to create this discount. data DiscountPromotionCode'Variants = DiscountPromotionCode'Text Data.Text.Internal.Text | DiscountPromotionCode'PromotionCode PromotionCode deriving (GHC.Show.Show, GHC.Classes.Eq) instance Data.Aeson.Types.ToJSON.ToJSON DiscountPromotionCode'Variants where toJSON (DiscountPromotionCode'Text a) = Data.Aeson.Types.ToJSON.toJSON a toJSON (DiscountPromotionCode'PromotionCode a) = Data.Aeson.Types.ToJSON.toJSON a instance Data.Aeson.Types.FromJSON.FromJSON DiscountPromotionCode'Variants where parseJSON val = case (DiscountPromotionCode'Text Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((DiscountPromotionCode'PromotionCode 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