# LANGUAGE FlexibleInstances      #
# LANGUAGE MultiParamTypeClasses #
# LANGUAGE OverloadedStrings      #
# LANGUAGE TypeFamilies           #
-------------------------------------------
-- |
-- Module      : Web.Stripe.Dispute
  Copyright    : ( c )   , 2014
-- Maintainer  : 
-- Stability   : experimental
-- Portability : POSIX
--
  < https:/\/\stripe.com / docs / api#diputes >
--
-- @
  { -\ # LANGUAGE OverloadedStrings \#- }
  import Web . Stripe
  import Web . Stripe . Charge
  import Web . Stripe . Dispute
--
-- main :: IO ()
-- main = do
    let config = StripeConfig ( StripeKey " secret_key " )
    result < - stripe config   ( ChargeId " charge_id " )
--   case result of
--     (Left stripeError) -> print stripeError
--     (Right (Charge { chargeDispute = dispute })) ->
--       case dispute of
--        (Just dispute) -> print dispute
--        Nothing        -> print "no dispute on this charge"
-- @
module Web.Stripe.Dispute
    ( -- * API
      UpdateDispute
    , updateDispute
    , CloseDispute
    , closeDispute
      -- * Types
    , ChargeId      (..)
    , Dispute       (..)
    , DisputeReason (..)
    , DisputeStatus (..)
    , Evidence      (..)
    , MetaData      (..)
    ) where

import           Web.Stripe.StripeRequest (Method (POST),
                                           StripeHasParam, StripeRequest (..),
                                           StripeReturn,
                                           mkStripeRequest)
import           Web.Stripe.Util          ((</>))
import           Web.Stripe.Types         (ChargeId (..), Dispute (..),
                                           DisputeReason (..),
                                           DisputeStatus (..),
                                           Evidence (..), MetaData(..))
import           Web.Stripe.Types.Util    (getChargeId)

------------------------------------------------------------------------------
-- | `Dispute` to be updated
updateDispute
    :: ChargeId        -- ^ The ID of the Charge being disputed
    -> StripeRequest UpdateDispute
updateDispute
  chargeId = request
  where request = mkStripeRequest POST url params
        url     = "charges" </> getChargeId chargeId </> "dispute"
        params  = []

data UpdateDispute
type instance StripeReturn UpdateDispute = Dispute
instance StripeHasParam UpdateDispute Evidence
instance StripeHasParam UpdateDispute MetaData

------------------------------------------------------------------------------
-- | `Dispute` to be closed
closeDispute
    :: ChargeId  -- ^ The ID of the Charge being disputed
    -> StripeRequest CloseDispute
closeDispute
    chargeId = request
  where request = mkStripeRequest POST url params
        url     = "charges" </> getChargeId chargeId </> "dispute" </> "close"
        params  = []

data CloseDispute
type instance StripeReturn CloseDispute = Dispute

-----------------------------------------
 |
 Module      : Web.Stripe.Dispute
 Maintainer  : 
 Stability   : experimental
 Portability : POSIX


 @

 main :: IO ()
 main = do
   case result of
     (Left stripeError) -> print stripeError
     (Right (Charge { chargeDispute = dispute })) ->
       case dispute of
        (Just dispute) -> print dispute
        Nothing        -> print "no dispute on this charge"
 @
 * API
 * Types
----------------------------------------------------------------------------
 | `Dispute` to be updated
 ^ The ID of the Charge being disputed
----------------------------------------------------------------------------
 | `Dispute` to be closed
 ^ The ID of the Charge being disputed
# LANGUAGE FlexibleInstances      #
# LANGUAGE MultiParamTypeClasses #
# LANGUAGE OverloadedStrings      #
# LANGUAGE TypeFamilies           #
  Copyright    : ( c )   , 2014
  < https:/\/\stripe.com / docs / api#diputes >
  { -\ # LANGUAGE OverloadedStrings \#- }
  import Web . Stripe
  import Web . Stripe . Charge
  import Web . Stripe . Dispute
    let config = StripeConfig ( StripeKey " secret_key " )
    result < - stripe config   ( ChargeId " charge_id " )
module Web.Stripe.Dispute
      UpdateDispute
    , updateDispute
    , CloseDispute
    , closeDispute
    , ChargeId      (..)
    , Dispute       (..)
    , DisputeReason (..)
    , DisputeStatus (..)
    , Evidence      (..)
    , MetaData      (..)
    ) where

import           Web.Stripe.StripeRequest (Method (POST),
                                           StripeHasParam, StripeRequest (..),
                                           StripeReturn,
                                           mkStripeRequest)
import           Web.Stripe.Util          ((</>))
import           Web.Stripe.Types         (ChargeId (..), Dispute (..),
                                           DisputeReason (..),
                                           DisputeStatus (..),
                                           Evidence (..), MetaData(..))
import           Web.Stripe.Types.Util    (getChargeId)

updateDispute
    -> StripeRequest UpdateDispute
updateDispute
  chargeId = request
  where request = mkStripeRequest POST url params
        url     = "charges" </> getChargeId chargeId </> "dispute"
        params  = []

data UpdateDispute
type instance StripeReturn UpdateDispute = Dispute
instance StripeHasParam UpdateDispute Evidence
instance StripeHasParam UpdateDispute MetaData

closeDispute
    -> StripeRequest CloseDispute
closeDispute
    chargeId = request
  where request = mkStripeRequest POST url params
        url     = "charges" </> getChargeId chargeId </> "dispute" </> "close"
        params  = []

data CloseDispute
type instance StripeReturn CloseDispute = Dispute
