<commit_before>{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TypeFamilies          #-}
-------------------------------------------
-- |
-- Module      : Web.Stripe.Invoice
-- Copyright   : (c) <NAME>, 2014
-- Maintainer  : <EMAIL>
-- Stability   : experimental
-- Portability : POSIX
--
-- < https:/\/\stripe.com/docs/api#invoices >
--
-- @
-- {-\# LANGUAGE OverloadedStrings \#-}
-- import Web.Stripe
-- import Web.Stripe.Customer
-- import Web.Stripe.Invoice
-- import Web.Stripe.InvoiceItem
-- import Web.Stripe.Plan
--
-- main :: IO ()
-- main = do
--   let config = StripeConfig (SecretKey "secret_key")
--   result <- stripe config createCustomer
--   case result of
--     (Left stripeError) -> print stripeError
--     (Right (Customer { customerId = cid })) ->
--       do result <- stripe config $
--            createPlan (PlanId "planid") (Amount 20) USD Day (PlanName "testplan")
--          case result of
--            (Left stripeError) -> print stripeError
--            (Right (Plan {})) ->
--              do result <- stripe config $
--                   createInvoiceItem cid (Amount 100) USD
--                 case result of
--                   (Left stripeError)  -> print stripeError
--                   (Right invoiceItem) ->
--                      do result <- stripe config $ createInvoice cid
--                         case result of
--                           (Left  stripeError) -> print stripeError
--                           (Right invoice)     -> print invoice
-- @
module Web.Stripe.Invoice
    ( -- * API
      CreateInvoice
    , createInvoice
    , GetInvoice
    , getInvoice
    , GetInvoiceLineItems
    , getInvoiceLineItems
    , GetUpcomingInvoice
    , getUpcomingInvoice
    , UpdateInvoice
    , updateInvoice
    , PayInvoice
    , payInvoice
    , GetInvoices
    , getInvoices
       -- * Types
    , ApplicationFeeId    (..)
    , Closed              (..)
    , CustomerId          (..)
    , Description         (..)
    , Discount            (..)
    , EndingBefore        (..)
    , ExpandParams        (..)
    , Forgiven            (..)
    , Invoice             (..)
    , InvoiceId           (..)
    , InvoiceLineItem     (..)
    , InvoiceLineItemId   (..)
    , InvoiceLineItemType (..)
    , Limit               (..)
    , MetaData            (..)
    , Period              (..)
    , StatementDescription(..)
    , StartingAfter       (..)
    , StripeList          (..)
    , SubscriptionId      (..)
    ) where

import           Web.Stripe.StripeRequest (Method(GET, POST), StripeRequest(..),
                                           StripeReturn, StripeHasParam,
                                           toStripeParam, mkStripeRequest)
import           Web.Stripe.Util          ((</>))
import           Web.Stripe.Types         (ApplicationFeeId(..), Closed(..),
                                           CustomerId(..), Description(..),
                                           Discount(..), EndingBefore(..),
                                           ExpandParams(..), Forgiven(..),
                                           Invoice(..),InvoiceId(..),
                                           InvoiceLineItem(..),
                                           InvoiceLineItemId(..),
                                           InvoiceLineItemType(..),
                                           Limit(..), MetaData(..), Period(..),
                                           SubscriptionId(..), StartingAfter(..),
                                           StatementDescription(..),
                                           StripeList(..))
import           Web.Stripe.Types.Util    (getInvoiceId)

------------------------------------------------------------------------------
-- | The `Invoice` to be created for a `Customer`
createInvoice
    :: CustomerId -- ^ `CustomerId` of `Customer` to `Invoice`
    -> StripeRequest CreateInvoice
createInvoice
    customerid
                = request
  where request = mkStripeRequest POST url params
        url     = "invoices"
        params  = toStripeParam customerid $
                  []

data CreateInvoice
type instance StripeReturn CreateInvoice = Invoice
instance StripeHasParam CreateInvoice ApplicationFeeId
instance StripeHasParam CreateInvoice Description
instance StripeHasParam CreateInvoice MetaData
instance StripeHasParam CreateInvoice StatementDescription
instance StripeHasParam CreateInvoice SubscriptionId

------------------------------------------------------------------------------
-- | Retrieve an `Invoice` by `InvoiceId`
getInvoice
    :: InvoiceId -- ^ Get an `Invoice` by `InvoiceId`
    -> StripeRequest GetInvoice
getInvoice
    invoiceid = request
  where request = mkStripeRequest GET url params
        url     = "invoices" </> getInvoiceId invoiceid
        params  = []

data GetInvoice
type instance StripeReturn GetInvoice = Invoice
instance StripeHasParam GetInvoice ExpandParams

------------------------------------------------------------------------------
-- | Retrieve a `StripeList` of `Invoice`s
getInvoices
    :: StripeRequest GetInvoices
getInvoices = request
  where request = mkStripeRequest GET url params
        url     = "invoices"
        params  = []

data GetInvoices
type instance StripeReturn GetInvoices = StripeList Invoice
instance StripeHasParam GetInvoices ExpandParams
instance StripeHasParam GetInvoices (EndingBefore InvoiceId)
instance StripeHasParam GetInvoices Limit
instance StripeHasParam GetInvoices (StartingAfter InvoiceId)

------------------------------------------------------------------------------
-- | Retrieve an `InvoiceLineItem`s by `InvoiceId`
getInvoiceLineItems
    :: InvoiceId                       -- ^ Get an `Invoice` by `InvoiceId`
    -> StripeRequest GetInvoiceLineItems
getInvoiceLineItems
    invoiceid   = request
  where request = mkStripeRequest GET url params
        url     = "invoices" </> getInvoiceId invoiceid </> "lines"
        params  = []

data GetInvoiceLineItems
type instance StripeReturn GetInvoiceLineItems = StripeList InvoiceLineItem
instance StripeHasParam GetInvoiceLineItems CustomerId
instance StripeHasParam GetInvoiceLineItems (EndingBefore InvoiceLineItemId)
instance StripeHasParam GetInvoiceLineItems Limit
instance StripeHasParam GetInvoiceLineItems (StartingAfter InvoiceLineItemId)
instance StripeHasParam GetInvoiceLineItems SubscriptionId

------------------------------------------------------------------------------
-- | Retrieve an upcoming `Invoice` for a `Customer` by `CustomerId`
getUpcomingInvoice
    :: CustomerId -- ^ The `InvoiceId` of the `Invoice` to retrieve
    -> StripeRequest GetUpcomingInvoice
getUpcomingInvoice<commit_msg>Add `CustomerId` parameter to `getInvoices`.<commit_after>{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TypeFamilies          #-}
-------------------------------------------
-- |
-- Module      : Web.Stripe.Invoice
-- Copyright   : (c) <NAME>, 2014
-- Maintainer  : <EMAIL>
-- Stability   : experimental
-- Portability : POSIX
--
-- < https:/\/\stripe.com/docs/api#invoices >
--
-- @
-- {-\# LANGUAGE OverloadedStrings \#-}
-- import Web.Stripe
-- import Web.Stripe.Customer
-- import Web.Stripe.Invoice
-- import Web.Stripe.InvoiceItem
-- import Web.Stripe.Plan
--
-- main :: IO ()
-- main = do
--   let config = StripeConfig (SecretKey "secret_key")
--   result <- stripe config createCustomer
--   case result of
--     (Left stripeError) -> print stripeError
--     (Right (Customer { customerId = cid })) ->
--       do result <- stripe config $
--            createPlan (PlanId "planid") (Amount 20) USD Day (PlanName "testplan")
--          case result of
--            (Left stripeError) -> print stripeError
--            (Right (Plan {})) ->
--              do result <- stripe config $
--                   createInvoiceItem cid (Amount 100) USD
--                 case result of
--                   (Left stripeError)  -> print stripeError
--                   (Right invoiceItem) ->
--                      do result <- stripe config $ createInvoice cid
--                         case result of
--                           (Left  stripeError) -> print stripeError
--                           (Right invoice)     -> print invoice
-- @
module Web.Stripe.Invoice
    ( -- * API
      CreateInvoice
    , createInvoice
    , GetInvoice
    , getInvoice
    , GetInvoiceLineItems
    , getInvoiceLineItems
    , GetUpcomingInvoice
    , getUpcomingInvoice
    , UpdateInvoice
    , updateInvoice
    , PayInvoice
    , payInvoice
    , GetInvoices
    , getInvoices
       -- * Types
    , ApplicationFeeId    (..)
    , Closed              (..)
    , CustomerId          (..)
    , Description         (..)
    , Discount            (..)
    , EndingBefore        (..)
    , ExpandParams        (..)
    , Forgiven            (..)
    , Invoice             (..)
    , InvoiceId           (..)
    , InvoiceLineItem     (..)
    , InvoiceLineItemId   (..)
    , InvoiceLineItemType (..)
    , Limit               (..)
    , MetaData            (..)
    , Period              (..)
    , StatementDescription(..)
    , StartingAfter       (..)
    , StripeList          (..)
    , SubscriptionId      (..)
    ) where

import           Web.Stripe.StripeRequest (Method(GET, POST), StripeRequest(..),
                                           StripeReturn, StripeHasParam,
                                           toStripeParam, mkStripeRequest)
import           Web.Stripe.Util          ((</>))
import           Web.Stripe.Types         (ApplicationFeeId(..), Closed(..),
                                           CustomerId(..), Description(..),
                                           Discount(..), EndingBefore(..),
                                           ExpandParams(..), Forgiven(..),
                                           Invoice(..),InvoiceId(..),
                                           InvoiceLineItem(..),
                                           InvoiceLineItemId(..),
                                           InvoiceLineItemType(..),
                                           Limit(..), MetaData(..), Period(..),
                                           SubscriptionId(..), StartingAfter(..),
                                           StatementDescription(..),
                                           StripeList(..))
import           Web.Stripe.Types.Util    (getInvoiceId)

------------------------------------------------------------------------------
-- | The `Invoice` to be created for a `Customer`
createInvoice
    :: CustomerId -- ^ `CustomerId` of `Customer` to `Invoice`
    -> StripeRequest CreateInvoice
createInvoice
    customerid
                = request
  where request = mkStripeRequest POST url params
        url     = "invoices"
        params  = toStripeParam customerid $
                  []

data CreateInvoice
type instance StripeReturn CreateInvoice = Invoice
instance StripeHasParam CreateInvoice ApplicationFeeId
instance StripeHasParam CreateInvoice Description
instance StripeHasParam CreateInvoice MetaData
instance StripeHasParam CreateInvoice StatementDescription
instance StripeHasParam CreateInvoice SubscriptionId

------------------------------------------------------------------------------
-- | Retrieve an `Invoice` by `InvoiceId`
getInvoice
    :: InvoiceId -- ^ Get an `Invoice` by `InvoiceId`
    -> StripeRequest GetInvoice
getInvoice
    invoiceid = request
  where request = mkStripeRequest GET url params
        url     = "invoices" </> getInvoiceId invoiceid
        params  = []

data GetInvoice
type instance StripeReturn GetInvoice = Invoice
instance StripeHasParam GetInvoice ExpandParams

------------------------------------------------------------------------------
-- | Retrieve a `StripeList` of `Invoice`s
getInvoices
    :: StripeRequest GetInvoices
getInvoices = request
  where request = mkStripeRequest GET url params
        url     = "invoices"
        params  = []

data GetInvoices
type instance StripeReturn GetInvoices = StripeList Invoice
instance StripeHasParam GetInvoices ExpandParams
instance StripeHasParam GetInvoices (EndingBefore InvoiceId)
instance StripeHasParam GetInvoices Limit
instance StripeHasParam GetInvoices CustomerId
instance StripeHasParam GetInvoices (StartingAfter InvoiceId)

------------------------------------------------------------------------------
-- | Retrieve an `InvoiceLineItem`s by `InvoiceId`
getInvoiceLineItems
    :: InvoiceId                       -- ^ Get an `Invoice` by `InvoiceId`
    -> StripeRequest GetInvoiceLineItems
getInvoiceLineItems
    invoiceid   = request
  where request = mkStripeRequest GET url params
        url     = "invoices" </> getInvoiceId invoiceid </> "lines"
        params  = []

data GetInvoiceLineItems
type instance StripeReturn GetInvoiceLineItems = StripeList InvoiceLineItem
instance StripeHasParam GetInvoiceLineItems CustomerId
instance StripeHasParam GetInvoiceLineItems (EndingBefore InvoiceLineItemId)
instance StripeHasParam GetInvoiceLineItems Limit
instance StripeHasParam GetInvoiceLineItems (StartingAfter InvoiceLineItemId)
instance StripeHasParam GetInvoiceLineItems SubscriptionId

------------------------------------------------------------------------------
-- | Retrieve an upcoming `Invoice` for a `Customer` by `CustomerId`
getUpcomingInvoice
    :: CustomerId -- ^ The `InvoiceId` of the `Invoice` to retrieve
    -> StripeRequest GetUpcomingInvoice
getUpcomingInvoice
{'fraction_non_alphanumeric': 0.15454944411936805, 'fraction_numerical': 0.0013165593914569924, 'mean_word_length': 1.5301628423390081, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 52, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2633411', 'n_tokens_mistral': 3648, 'n_tokens_neox': 3442, 'n_words': 829}