packages feed

paypal-adaptive-hoops 0.5.3.0 → 0.6.0.0

raw patch · 3 files changed

+24/−8 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Web.PayPal.Adaptive: AeInvalidCredentials :: AdaptiveErr
+ Web.PayPal.Adaptive: AeNoSuchEmail :: AdaptiveErr

Files

paypal-adaptive-hoops.cabal view
@@ -1,5 +1,5 @@ name:                 paypal-adaptive-hoops-version:              0.5.3.0+version:              0.6.0.0 author:               Ian Grant Jeffries maintainer:           ian@housejeffries.com category:             Web@@ -20,6 +20,7 @@   default-language:   Haskell2010   ghc-options:        -Wall   other-extensions:   GADTs+                    , MultiWayIf                     , OverloadedStrings                     , TemplateHaskell 
src/Web/PayPal/Adaptive.hs view
@@ -6,6 +6,7 @@   , ReceiverList     (..)   , SendPayment      (..)   , CreatePayment    (..)+  , approvalUrl   , LookupPayment    (..)   , PayResp          (..)   , PayExecStatus    (..)@@ -15,7 +16,6 @@   , TransactionId    (..)   , TransactionStatus(..)   , Money            (..)-  , approvalUrl   , m2Currency   , m2PayPal   ) where
src/Web/PayPal/Adaptive/Core.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE GADTs             #-}+{-# LANGUAGE MultiWayIf        #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell   #-} @@ -19,8 +20,8 @@ import           Data.Monoid import           Data.Text            (Text) import qualified Data.Text            as T-import           Data.Text.Read import           Data.Text.Encoding+import           Data.Text.Read import           Data.Traversable import qualified Data.Vector          as V import           Network.HTTP.Client  (HttpException (NoResponseDataReceived))@@ -80,10 +81,17 @@   in case eitherDecode b of     Right d -> Right d     Left  e -> -- If the response isn't a PayResp, it might be a PayPal error message.-      case eitherDecode b of-        Right (AeErrCodes cs) -> Left $ AeErrCodes cs-        _                     -> Left $ AeDecodeFailed b (T.pack e)+      case decode b of+        Just (AeErrCodes codes) -> Left $ codeErr codes+        _ -> Left $ AeDecodeFailed b (T.pack e) +  where+    codeErr :: [Int] -> AdaptiveErr+    codeErr cs =+      if | elem 520003 cs -> AeInvalidCredentials+         | elem 589039 cs -> AeNoSuchEmail+         | otherwise      -> AeErrCodes cs+ -------------------------------------------------- -- Errors --------------------------------------------------@@ -93,10 +101,15 @@ -- AeShouldNotHappen is meant to cover PayPal responses to API requests -- that this library doesn't support sending in the first place. -- TODO: is this actually how we're using it?+--+-- AeNoSuchEmail is raised when the CreatePayment sender+-- email doesn't exist. data AdaptiveErr   = AeNoResponse   | AeConnectionErr   Text   | AeDecodeFailed    ByteString Text+  | AeInvalidCredentials+  | AeNoSuchEmail   | AeErrCodes        [Int]   | AePending         PayResp   | AeRefused         PayResp@@ -199,13 +212,15 @@             let infos = _prPayInfo a             in if length infos /= 1               then Left $ AeShouldNotHappen a "sendPayment expects one PayInfo in reponse"-              else case _piTransactionStatus (head infos) of+              else+                let info = head infos+                in case _piTransactionStatus info of                 Just TsCompleted  -> Right a                 Just TsPending    -> Left $ AePending a                 Just TsProcessing -> Left $ AePending a                 Just TsDenied     -> Left $ AeRefused a                 Just TsFailed     -> Left $ AeRefused a-                _            -> Left $ AeShouldNotHappen a "got unsupported TransactionStatus"+                _ -> Left $ AeShouldNotHappen a "got unsupported TransactionStatus"           _ -> Left $ AeShouldNotHappen a "got unsupported PayExecStatus"  --------------------------------------------------