mangopay 1.10.2 → 1.11
raw patch · 7 files changed
+38/−34 lines, 7 filesdep −attoparsec-conduitdep ~conduit
Dependencies removed: attoparsec-conduit
Dependency ranges changed: conduit
Files
- mangopay.cabal +4/−17
- src/Web/MangoPay.hs +1/−0
- src/Web/MangoPay/Accounts.hs +16/−5
- src/Web/MangoPay/Monad.hs +10/−9
- test/Web/MangoPay/AccountsTest.hs +3/−0
- test/Web/MangoPay/PayinsTest.hs +1/−2
- test/Web/MangoPay/WalletsTest.hs +3/−1
mangopay.cabal view
@@ -1,5 +1,5 @@ name: mangopay-version: 1.10.2+version: 1.11 cabal-version: >= 1.8 build-type: Simple author: JP Moresmau <jpmoresmau@gmail.com>@@ -25,9 +25,6 @@ default: False description: Print debugging info. -flag conduit11- description: conduit >= 1.1- library hs-source-dirs: src build-depends:@@ -38,6 +35,8 @@ , transformers-base , monad-control , resourcet+ , conduit == 1.2.*+ , conduit-extra == 1.1.* , http-types , http-conduit >= 2.0 && < 2.2 , attoparsec >= 0.10 && < 0.13@@ -67,14 +66,6 @@ , connection , x509-system - if flag(conduit11)- build-depends:- conduit == 1.1.*- , conduit-extra == 1.1.*- else- build-depends:- conduit == 1.0.*- , attoparsec-conduit == 1.0.* ghc-options: -Wall other-modules: Web.MangoPay.Access@@ -115,7 +106,7 @@ build-depends: base, aeson, async, attoparsec, base16-bytestring, base64-bytestring, blaze-builder, bytestring,- case-insensitive, conduit, data-default, http-conduit,+ case-insensitive, conduit, conduit-extra, data-default, http-conduit, http-types, HUnit, lifted-base, monad-control, monad-logger, resourcet, template-haskell, text, time, transformers, transformers-base, unordered-containers, utf8-string,@@ -124,10 +115,6 @@ , tls, connection, x509-system , HTF > 0.9- if flag(conduit11)- build-depends: conduit-extra- else- build-depends: attoparsec-conduit other-modules: Web.MangoPay.UsersTest, Web.MangoPay.WalletsTest,
src/Web/MangoPay.hs view
@@ -114,6 +114,7 @@ ,createAccount ,fetchAccount ,listAccounts+ ,accountCountry -- Payins ,PaymentExecution(..)
src/Web/MangoPay/Accounts.hs view
@@ -8,7 +8,7 @@ import Web.MangoPay.Types import Web.MangoPay.Users -import Data.Text+import Data.Text as T import Data.Text.Encoding (encodeUtf8) import Data.Typeable (Typeable) import Data.Aeson@@ -16,9 +16,9 @@ import Data.Maybe (fromMaybe) import Data.Time.Clock.POSIX (POSIXTime) import Control.Applicative-import qualified Data.ByteString as BS -import Data.CountryCodes (CountryCode)+import qualified Data.ByteString as BS+import qualified Data.CountryCodes as C -- | create an account createAccount :: (MPUsableMonad m) => BankAccount -> AccessToken -> MangoPayT m BankAccount@@ -29,7 +29,7 @@ -- | fetch an account from its Id fetchAccount :: (MPUsableMonad m) => AnyUserId -> BankAccountId -> AccessToken -> MangoPayT m BankAccount fetchAccount uid = fetchGeneric path- where path = Data.Text.concat ["/users/",uid,"/bankaccounts/"]+ where path = T.concat ["/users/",uid,"/bankaccounts/"] -- | list all accounts for a given user listAccounts :: (MPUsableMonad m) => AnyUserId -> GenericSort -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList BankAccount)@@ -53,7 +53,7 @@ } | Other { atAccountNumber :: Text ,atBIC :: Maybe Text- ,atCountry :: CountryCode+ ,atCountry :: C.CountryCode } deriving (Show,Read,Eq,Ord,Typeable) -- | from json as per MangoPay format@@ -97,6 +97,17 @@ toJSONPairs (US nb aba)=["AccountNumber" .= nb,"ABA" .= aba] toJSONPairs (CA nb bn inb bc)=["AccountNumber" .= nb,"BankName" .= bn,"InstitutionNumber" .= inb, "BranchCode" .= bc] toJSONPairs (Other nb bic c)=["AccountNumber" .= nb,"BIC" .= bic,"Country" .= c]+++-- | Get the country for a BankAccount+accountCountry :: BankAccount -> Maybe C.CountryCode+accountCountry ba = case baDetails ba of+ GB{} -> Just C.GB+ US{} -> Just C.US+ CA{} -> Just C.CA+ Other _ _ c -> Just c+ IBAN ib _ -> C.fromMText $ T.take 2 ib+ -- | Id of a bank account type BankAccountId = Text
src/Web/MangoPay/Monad.hs view
@@ -13,9 +13,10 @@ import Control.Monad.Fix (MonadFix) import Control.Monad.IO.Class (MonadIO) import Control.Monad.Trans.Class (MonadTrans(lift))-import Control.Monad.Trans.Control ( MonadTransControl(..), MonadBaseControl(..)- , ComposeSt, defaultLiftBaseWith- , defaultRestoreM )+import Control.Monad.Trans.Control+ ( MonadTransControl(..), MonadBaseControl(..)+ , ComposeSt, defaultLiftBaseWith, defaultLiftWith+ , defaultRestoreM, defaultRestoreT ) import Control.Monad.Trans.Reader (ReaderT(..), ask, mapReaderT) import Data.Monoid ((<>)) import Data.Typeable (Typeable)@@ -62,14 +63,14 @@ liftBase = lift . liftBase instance MonadTransControl MangoPayT where- newtype StT MangoPayT a = MpStT { unMpStT :: StT (ReaderT MpData) a }- liftWith f = Mp $ liftWith (\run -> f (liftM MpStT . run . unIs))- restoreT = Mp . restoreT . liftM unMpStT+ type StT MangoPayT a = StT (ReaderT MpData) a+ liftWith = defaultLiftWith Mp unIs+ restoreT = defaultRestoreT Mp instance MonadBaseControl b m => MonadBaseControl b (MangoPayT m) where- newtype StM (MangoPayT m) a = StMT {unStMT :: ComposeSt MangoPayT m a}- liftBaseWith = defaultLiftBaseWith StMT- restoreM = defaultRestoreM unStMT+ type StM (MangoPayT m) a = ComposeSt MangoPayT m a+ liftBaseWith = defaultLiftBaseWith+ restoreM = defaultRestoreM instance (MonadLogger m) => MonadLogger (MangoPayT m) where monadLoggerLog loc src lvl msg=lift $ monadLoggerLog loc src lvl msg
test/Web/MangoPay/AccountsTest.hs view
@@ -12,6 +12,8 @@ import Test.Framework import Test.HUnit (Assertion) +import qualified Data.CountryCodes as C+ -- | Test bank account creation using IBAN with BIC. test_BankAccount_IBAN_BIC :: Assertion test_BankAccount_IBAN_BIC = doBankAccountTest True@@ -36,6 +38,7 @@ assertBool $ isJust $ baId acc2 assertBool $ isJust $ baCreationDate acc2 assertEqual iban $ atIBAN $ baDetails acc2+ assertEqual (Just C.FR) $ accountCountry acc2 if useBIC then assertEqual (Just bic) $ atBIC $ baDetails acc2 else assertBool $ isJust $ atBIC $ baDetails acc2 -- MangoPay fills in the BIC.
test/Web/MangoPay/PayinsTest.hs view
@@ -70,7 +70,7 @@ w2<-testMP $ createWallet w assertBool (isJust $ wId w2) let wid=fromJust $ wId w2- testEventTypes [PAYIN_NORMAL_CREATED {- ,PAYIN_NORMAL_FAILED not thrown - MangoPay support notified -}] $ do+ testEventTypes [PAYIN_NORMAL_CREATED, PAYIN_NORMAL_FAILED] $ do let cp=mkCardPayin uid uid wid (Amount "EUR" 33394) (Amount "EUR" 0) "http://dummy" cid cp2<-testMP $ createCardPayin cp assertBool (isJust $ cpId cp2)@@ -80,4 +80,3 @@ w3<-testMP $ fetchWallet wid assertEqual (Just $ Amount "EUR" 0) (wBalance w3) return $ cpId cp2-
test/Web/MangoPay/WalletsTest.hs view
@@ -130,4 +130,6 @@ test_OrderEvents = do evt1 <- testMP $ searchAllEvents def{espSortByDate=Just ASC} evt2 <- testMP $ searchAllEvents def{espSortByDate=Just DESC}- assertEqual evt1 $ reverse evt2+ -- we just check the resource id because the failed transfer may have the same date+ -- as the creation, so we can't compare on the full even (with status)+ assertEqual (map eResourceId evt1) $ reverse (map eResourceId evt2)