{-# LANGUAGE GADTs #-}

-- | Look up information about a payment.
--
-- <https://developer.paypal.com/docs/classic/api/adaptive-payments/PaymentDetails_API_Operation/>

module PayPal.Adaptive.Lookup where

import Control.Applicative
import Data.Aeson
import PayPal.Adaptive.Core

data LookupPayment a where
  LookupTrID   :: TransactionId -> LookupPayment TransactionId
  LookupPayKey :: PayKey        -> LookupPayment PayKey

instance ToJSON (LookupPayment a) where
  toJSON (LookupTrID (TransactionId p)) =
    object [ "transactionId"   .= p
           , "requestEnvelope" .= requestEnvelope
           ]
  toJSON (LookupPayKey (PayKey p)) =
    object [ "payKey"          .= p
           , "requestEnvelope" .= requestEnvelope
           ]

req :: Client -> LookupPayment a -> IO (Either AdaptiveErr PayResp)
req c l = (>>= ppDecode) <$> ppPost c "PaymentDetails" l