mangopay 1.8.2 → 1.9
raw patch · 16 files changed
+157/−186 lines, 16 files
Files
- mangopay.cabal +1/−1
- src/Web/MangoPay.hs +16/−16
- src/Web/MangoPay/Accounts.hs +7/−7
- src/Web/MangoPay/Cards.hs +13/−31
- src/Web/MangoPay/Documents.hs +8/−8
- src/Web/MangoPay/Events.hs +4/−4
- src/Web/MangoPay/Monad.hs +2/−2
- src/Web/MangoPay/Payins.hs +21/−22
- src/Web/MangoPay/Payouts.hs +9/−11
- src/Web/MangoPay/Refunds.hs +14/−14
- src/Web/MangoPay/Types.hs +8/−12
- src/Web/MangoPay/Users.hs +19/−20
- src/Web/MangoPay/Wallets.hs +29/−29
- test/Web/MangoPay/AccessTest.hs +3/−3
- test/Web/MangoPay/TestUtils.hs +1/−3
- test/Web/MangoPay/UsersTest.hs +2/−3
mangopay.cabal view
@@ -1,5 +1,5 @@ name: mangopay-version: 1.8.2+version: 1.9 cabal-version: >= 1.8 build-type: Simple author: JP Moresmau <jpmoresmau@gmail.com>
src/Web/MangoPay.hs view
@@ -31,13 +31,13 @@ ,IncomeRange(..) ,incomeBounds ,incomeRange- ,NaturalUserID+ ,NaturalUserId ,LegalUser(..) ,LegalUserType(..)- ,LegalUserID+ ,LegalUserId ,UserRef(..) ,PersonType(..)- ,AnyUserID+ ,AnyUserId ,createNaturalUser ,modifyNaturalUser ,fetchNaturalUser@@ -46,22 +46,22 @@ ,fetchLegalUser ,getUser ,listUsers- ,getExistingUserID+ ,getExistingUserId -- Wallets ,Wallet(..) ,Amount(..)- ,WalletID+ ,WalletId ,Currency ,createWallet ,modifyWallet ,fetchWallet ,listWallets ,Transfer(..)- ,TransferID+ ,TransferId ,TransferStatus(..) ,Transaction(..)- ,TransactionID+ ,TransactionId ,TransactionType(..) ,TransactionNature(..) ,createTransfer@@ -78,7 +78,7 @@ ,checkEvent ,HookStatus(..) ,HookValidity(..)- ,HookID+ ,HookId ,Hook(..) ,createHook ,modifyHook@@ -89,7 +89,7 @@ -- Documents and pages ,Document(..)- ,DocumentID+ ,DocumentId ,DocumentType(..) ,DocumentStatus(..) ,createDocument@@ -101,7 +101,7 @@ -- Accounts ,BankAccount(..)- ,BankAccountID+ ,BankAccountId ,BankAccountDetails(..) ,PaymentType(..) ,createAccount@@ -110,19 +110,19 @@ -- Payins ,PaymentExecution(..)- ,BankWireID+ ,BankWireId ,BankWire(..) ,createBankWirePayIn ,fetchBankWirePayIn ,mkBankWire- ,CardPayinID+ ,CardPayinId ,CardPayin(..) ,createCardPayin ,fetchCardPayin ,mkCardPayin -- Payouts- ,PayoutID+ ,PayoutId ,Payout(..) ,mkPayout ,createPayout@@ -130,8 +130,8 @@ -- Cards ,CardRegistration(..)- ,CardRegistrationID- ,CardID+ ,CardRegistrationId+ ,CardId ,CardInfo(..) ,Card(..) ,CardValidity(..)@@ -142,7 +142,7 @@ ,listCards -- Refunds- ,RefundID+ ,RefundId ,Refund(..) ,RefundRequest(..) ,refundTransfer
src/Web/MangoPay/Accounts.hs view
@@ -24,13 +24,13 @@ where path = BS.concat ["/users/",encodeUtf8 uid,"/bankaccounts/",encodeUtf8 $ typeName $ baDetails ba] uid = fromMaybe (error "no user provided for account") $ baUserId ba --- | fetch an account from its ID-fetchAccount :: (MPUsableMonad m) => AnyUserID -> BankAccountID -> AccessToken -> MangoPayT m BankAccount+-- | 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/"] -- | list all accounts for a given user-listAccounts :: (MPUsableMonad m) => AnyUserID -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList BankAccount)+listAccounts :: (MPUsableMonad m) => AnyUserId -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList BankAccount) listAccounts uid = genericList ["/users/",uid,"/bankaccounts/"] -- | account details, depending on the type@@ -96,14 +96,14 @@ 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] --- | ID of a bank account-type BankAccountID = Text+-- | Id of a bank account+type BankAccountId = Text -- | bank account details data BankAccount = BankAccount {- baId :: Maybe BankAccountID+ baId :: Maybe BankAccountId ,baCreationDate :: Maybe POSIXTime- ,baUserId :: Maybe AnyUserID+ ,baUserId :: Maybe AnyUserId ,baTag :: Maybe Text ,baDetails :: BankAccountDetails ,baOwnerName :: Text
src/Web/MangoPay/Cards.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables, OverloadedStrings, FlexibleContexts, FlexibleInstances, ConstraintKinds, RecordWildCards #-}+{-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables,OverloadedStrings, FlexibleContexts, FlexibleInstances,ConstraintKinds #-} -- | handle cards module Web.MangoPay.Cards where @@ -15,8 +15,8 @@ import qualified Data.HashMap.Lazy as HM --- | card registration ID-type CardRegistrationID=Text+-- | card registration Id+type CardRegistrationId=Text -- | create a card registration@@ -38,22 +38,22 @@ -- | helper function to create a new card registration-mkCardRegistration :: AnyUserID -> Currency -> CardRegistration+mkCardRegistration :: AnyUserId -> Currency -> CardRegistration mkCardRegistration uid currency=CardRegistration Nothing Nothing Nothing uid currency Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing -- | a card registration data CardRegistration = CardRegistration {- crId :: Maybe CardRegistrationID -- ^ The Id of the object+ crId :: Maybe CardRegistrationId -- ^ The Id of the object ,crCreationDate :: Maybe POSIXTime -- ^ The creation date of the object ,crTag :: Maybe Text -- ^ Custom data- ,crUserId :: AnyUserID -- ^ The ID of the author+ ,crUserId :: AnyUserId -- ^ The Id of the author ,crCurrency :: Currency -- ^ The currency of the card registrated ,crAccessKey :: Maybe Text -- ^ This key has to be sent with the card details and the PreregistrationData ,crPreregistrationData :: Maybe Text -- ^ This passphrase has to be sent with the card details and the AccessKey ,crCardRegistrationURL :: Maybe Text -- ^ The URL where to POST the card details, the AccessKey and PreregistrationData ,crRegistrationData :: Maybe Text -- ^ You get the CardRegistrationData once you posted the card details, the AccessKey and PreregistrationData ,crCardType :: Maybe Text -- ^ « CB_VISA_MASTERCARD » is the only value available yet- ,crCardId :: Maybe CardID -- ^ You get the CardId (to process payments) once you edited the CardRegistration Object with the RegistrationData+ ,crCardId :: Maybe CardId -- ^ You get the CardId (to process payments) once you edited the CardRegistration Object with the RegistrationData ,crResultCode :: Maybe Text -- ^ The result code of the object ,crResultMessage :: Maybe Text -- ^ The message explaining the result code ,crStatus :: Maybe DocumentStatus -- ^ The status of the object.@@ -62,7 +62,7 @@ -- | to json as per MangoPay format instance ToJSON CardRegistration where- toJSON cr=object ["Id".= crId cr -- we store the ID, because in the registration workflow we may need to hang on to the registration object for a while, so let's use JSON serialization to keep it!+ toJSON cr=object ["Id".= crId cr -- we store the Id, because in the registration workflow we may need to hang on to the registration object for a while, so let's use JSON serialization to keep it! , "Tag" .= crTag cr,"UserId" .= crUserId cr ,"Currency" .= crCurrency cr,"RegistrationData" .= crRegistrationData cr ,"CardRegistrationURL" .= crCardRegistrationURL cr]@@ -86,12 +86,12 @@ v .:? "Status" parseJSON _=fail "CardRegistration" --- | fetch a card from its ID-fetchCard :: (MPUsableMonad m) => CardID -> AccessToken -> MangoPayT m Card+-- | fetch a card from its Id+fetchCard :: (MPUsableMonad m) => CardId -> AccessToken -> MangoPayT m Card fetchCard = fetchGeneric "/cards/" -- | list all cards for a given user-listCards :: (MPUsableMonad m) => AnyUserID -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Card)+listCards :: (MPUsableMonad m) => AnyUserId -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Card) listCards uid = genericList ["/users/",uid,"/cards"] -- | validity of a card@@ -111,7 +111,7 @@ -- | a registered card data Card=Card {- cId :: CardID+ cId :: CardId ,cCreationDate :: POSIXTime ,cTag :: Maybe Text ,cExpirationDate :: CardExpiration -- ^ MMYY@@ -124,7 +124,7 @@ ,cCurrency :: Currency ,cValidity :: CardValidity -- ^ Once we proceed (or attempted to process) a payment with the card we are able to indicate if it is « valid » or « invalid ». If we didn’t process a payment yet the « Validity » stay at « unknown ». ,cCountry :: Text- ,cUserId :: AnyUserID+ ,cUserId :: AnyUserId } deriving (Show,Eq,Ord,Typeable) -- | from json as per MangoPay format@@ -145,21 +145,3 @@ v .: "Country" <*> v .: "UserId" parseJSON _=fail "Card"---- | to json as per MangoPay format-instance ToJSON Card where- toJSON Card {..} = object- [ "Id" .= cId- , "CreationDate" .= cCreationDate- , "Tag" .= cTag- , "ExpirationDate" .= cExpirationDate- , "Alias" .= cAlias- , "CardProvider" .= cCardProvider- , "CardType" .= cCardType- , "Product" .= cProduct- , "BankCode" .= cBankCode- , "Active" .= cActive- , "Currency" .= cCurrency- , "Validity" .= cValidity- , "Country" .= cCountry- , "UserId" .= cUserId ]
src/Web/MangoPay/Documents.hs view
@@ -21,32 +21,32 @@ import qualified Data.Text.Encoding as TE -- | create a document-createDocument :: (MPUsableMonad m) => AnyUserID -> Document -> AccessToken -> MangoPayT m Document+createDocument :: (MPUsableMonad m) => AnyUserId -> Document -> AccessToken -> MangoPayT m Document createDocument uid d = createGeneric path d where path = BS.concat ["/users/",TE.encodeUtf8 uid,"/KYC/documents/"] -modifyDocument :: (MPUsableMonad m) => AnyUserID -> Document -> AccessToken -> MangoPayT m Document+modifyDocument :: (MPUsableMonad m) => AnyUserId -> Document -> AccessToken -> MangoPayT m Document modifyDocument uid d = modifyGeneric path d dId where path = T.concat ["/users/", uid, "/KYC/documents/"] --- | fetch a document from its ID-fetchDocument :: (MPUsableMonad m) => AnyUserID -> DocumentID -> AccessToken -> MangoPayT m Document+-- | fetch a document from its Id+fetchDocument :: (MPUsableMonad m) => AnyUserId -> DocumentId -> AccessToken -> MangoPayT m Document fetchDocument uid = fetchGeneric path where path = T.concat ["/users/",uid,"/KYC/documents/"] -- | create a page -- note that per the MangoPay API the document HAS to be in CREATED status -- should we check it here? Since MangoPay returns a 500 Internal Server Error if the document is in another status...-createPage :: (MPUsableMonad m) => AnyUserID -> DocumentID -> BS.ByteString -> AccessToken -> MangoPayT m ()+createPage :: (MPUsableMonad m) => AnyUserId -> DocumentId -> BS.ByteString -> AccessToken -> MangoPayT m () createPage uid did contents at=do let val=object ["File" .= TE.decodeUtf8 (B64.encode contents)] url<-getClientURLMultiple ["/users/",uid,"/KYC/documents/",did,"/pages"] postNoReply url (Just at) val --- | ID of a document-type DocumentID = Text+-- | Id of a document+type DocumentId = Text -- | type of the document data DocumentType= IDENTITY_PROOF -- ^ For legal and natural users@@ -83,7 +83,7 @@ -- | a document data Document = Document {- dId :: Maybe DocumentID+ dId :: Maybe DocumentId ,dCreationDate :: Maybe POSIXTime ,dTag :: Maybe Text -- ^ custom data for client ,dType :: DocumentType
src/Web/MangoPay/Events.hs view
@@ -54,8 +54,8 @@ modifyHook :: (MPUsableMonad m) => Hook -> AccessToken -> MangoPayT m Hook modifyHook h = modifyGGeneric (Just $ HM.delete "EventType") "/hooks/" h hId --- | fetch a wallet from its ID-fetchHook :: (MPUsableMonad m) => HookID -> AccessToken -> MangoPayT m Hook+-- | fetch a wallet from its Id+fetchHook :: (MPUsableMonad m) => HookId -> AccessToken -> MangoPayT m Hook fetchHook = fetchGeneric "/hooks/" -- | list all wallets for a given user@@ -196,11 +196,11 @@ parseJSON _= fail "HookValidity" -- | id for hook-type HookID=Text+type HookId=Text -- | a notification hook data Hook=Hook {- hId :: Maybe HookID -- ^ The Id of the hook details+ hId :: Maybe HookId -- ^ The Id of the hook details ,hCreationDate :: Maybe POSIXTime ,hTag :: Maybe Text -- ^ Custom data ,hUrl :: Text -- ^This is the URL where you receive notification for each EventType
src/Web/MangoPay/Monad.hs view
@@ -175,14 +175,14 @@ getClientURL :: (Monad m)=> ByteString -- ^ the url path -> MangoPayT m ByteString -- ^ the URL getClientURL path=do- cid<- liftM clientIDBS getCreds+ cid<- liftM clientIdBS getCreds return $ BS.concat ["/v2/",cid,path] -- | get the url to use for our clientId getClientURLMultiple :: (Monad m)=> [T.Text] -- ^ the url components -> MangoPayT m ByteString -- ^ the URL getClientURLMultiple path=do- cid<- liftM clientIDBS getCreds+ cid<- liftM clientIdBS getCreds return $ BS.concat $ ["/v2/",cid] ++ map TE.encodeUtf8 path -- | build a URL for a get operation with a single query
src/Web/MangoPay/Payins.hs view
@@ -18,16 +18,16 @@ createBankWirePayIn :: (MPUsableMonad m) => BankWire -> AccessToken -> MangoPayT m BankWire createBankWirePayIn = createGeneric "/payins/bankwire/direct" --- | fetch a bank wire pay-in from its ID-fetchBankWirePayIn :: (MPUsableMonad m) => BankWireID -> AccessToken -> MangoPayT m BankWire+-- | fetch a bank wire pay-in from its Id+fetchBankWirePayIn :: (MPUsableMonad m) => BankWireId -> AccessToken -> MangoPayT m BankWire fetchBankWirePayIn = fetchGeneric "/payins/" -- | create a direct card pay in createCardPayin :: (MPUsableMonad m) => CardPayin -> AccessToken -> MangoPayT m CardPayin createCardPayin = createGeneric "/payins/card/direct" --- | fetch a direct card pay in from its ID-fetchCardPayin :: (MPUsableMonad m) => CardPayinID -> AccessToken -> MangoPayT m CardPayin+-- | fetch a direct card pay in from its Id+fetchCardPayin :: (MPUsableMonad m) => CardPayinId -> AccessToken -> MangoPayT m CardPayin fetchCardPayin = fetchGeneric "/payins/" data PaymentExecution = WEB -- ^ through a web interface@@ -44,28 +44,28 @@ parseJSON _ =fail "PaymentExecution" -- | helper function to create a new bank wire with the needed information-mkBankWire :: AnyUserID -> AnyUserID -> WalletID -> Amount -> Amount -> BankWire+mkBankWire :: AnyUserId -> AnyUserId -> WalletId -> Amount -> Amount -> BankWire mkBankWire aid uid wid amount fees= BankWire Nothing Nothing Nothing aid uid Nothing wid Nothing Nothing Nothing amount fees Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing -- | bankwire or card pay in-type AnyPayinID=Text+type AnyPayinId=Text -- | id of a bankwire-type BankWireID=Text+type BankWireId=Text -- | a bank wire -- there are a lot of common fields between all kinds of payments -- so this could probably become a "Payment" type data BankWire=BankWire {- bwId :: Maybe BankWireID+ bwId :: Maybe BankWireId ,bwCreationDate :: Maybe POSIXTime ,bwTag :: Maybe Text -- ^ custom data- ,bwAuthorId :: AnyUserID -- ^ The user ID of the author- ,bwCreditedUserId :: AnyUserID -- ^ It represents the amount credited on the targeted e-wallet.+ ,bwAuthorId :: AnyUserId -- ^ The user Id of the author+ ,bwCreditedUserId :: AnyUserId -- ^ It represents the amount credited on the targeted e-wallet. ,bwFees :: Maybe Amount -- ^ It represents your fees taken on the DebitedFundsDebitedFunds – Fees = CreditedFunds (amount received on wallet)- ,bwCreditedWalletId :: WalletID -- ^ The ID of the credited wallet- ,bwDebitedWalletId :: Maybe WalletID -- ^ The ID of the debited wallet+ ,bwCreditedWalletId :: WalletId -- ^ The Id of the credited wallet+ ,bwDebitedWalletId :: Maybe WalletId -- ^ The Id of the debited wallet ,bwDebitedFunds :: Maybe Amount -- ^ It represents the amount debited from the bank account. ,bwCreditedFunds :: Maybe Amount -- ^ It represents the amount credited on the targeted e-wallet. ,bwDeclaredDebitedFunds :: Amount -- ^ It represents the expected amount by the platform before that the user makes the payment.@@ -115,32 +115,32 @@ v .:? "ExecutionType" parseJSON _=fail "BankWire" --- | ID of a direct pay in-type CardPayinID=Text+-- | Id of a direct pay in+type CardPayinId=Text -- | helper function to create a new direct payin with the needed information -- | the url is only used in secure mode but is REQUIRED by MangoPay-mkCardPayin :: AnyUserID -> AnyUserID -> WalletID -> Amount -> Amount -> Text -> CardID -> CardPayin+mkCardPayin :: AnyUserId -> AnyUserId -> WalletId -> Amount -> Amount -> Text -> CardId -> CardPayin mkCardPayin aid uid wid amount fees url cid= CardPayin Nothing Nothing Nothing aid uid fees wid Nothing amount Nothing (Just url) Nothing Nothing cid Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing -- | direct pay in via registered card data CardPayin=CardPayin {- cpId :: Maybe CardPayinID+ cpId :: Maybe CardPayinId ,cpCreationDate :: Maybe POSIXTime ,cpTag :: Maybe Text -- ^ custom data- ,cpAuthorId :: AnyUserID -- ^ The user ID of the author- ,cpCreditedUserId :: AnyUserID -- ^ The user ID of the owner of the credited wallet+ ,cpAuthorId :: AnyUserId -- ^ The user Id of the author+ ,cpCreditedUserId :: AnyUserId -- ^ The user Id of the owner of the credited wallet ,cpFees :: Amount -- ^ It represents your fees taken on the DebitedFundsDebitedFunds – Fees = CreditedFunds (amount received on wallet)- ,cpCreditedWalletId :: WalletID -- ^ The ID of the credited wallet- ,cpDebitedWalletId :: Maybe WalletID -- ^ The ID of the debited wallet+ ,cpCreditedWalletId :: WalletId -- ^ The Id of the credited wallet+ ,cpDebitedWalletId :: Maybe WalletId -- ^ The Id of the debited wallet ,cpDebitedFunds :: Amount -- ^ It represents the amount debited from the bank account. ,cpCreditedFunds :: Maybe Amount -- ^ It represents the amount credited on the targeted e-wallet. ,cpSecureModeReturnURL :: Maybe Text -- ^ This URL will be used in case the SecureMode is activated. ,cpSecureMode :: Maybe Text -- ^ The SecureMode correspond to « 3D secure » for CB Visa and MasterCard or « Amex Safe Key » for American Express. This field lets you activate it manually. ,cpSecureModeRedirectURL :: Maybe Text -- ^ This URL will be used in case the SecureMode is activated.- ,cpCardId :: CardID -- ^ The ID of the registered card (Got through CardRegistration object)+ ,cpCardId :: CardId -- ^ The Id of the registered card (Got through CardRegistration object) ,cpStatus :: Maybe TransferStatus -- ^ The status of the payment ,cpResultCode :: Maybe Text -- ^ The transaction result code ,cpResultMessage :: Maybe Text -- ^ The transaction result Message@@ -185,4 +185,3 @@ v .:? "PaymentType" <*> v .:? "ExecutionType" parseJSON _=fail "CardPayin"-
src/Web/MangoPay/Payouts.hs view
@@ -18,29 +18,29 @@ createPayout :: (MPUsableMonad m) => Payout -> AccessToken -> MangoPayT m Payout createPayout = createGeneric "/payouts/bankwire" --- | fetch an payout from its ID-fetchPayout :: (MPUsableMonad m) => PayoutID -> AccessToken -> MangoPayT m Payout+-- | fetch an payout from its Id+fetchPayout :: (MPUsableMonad m) => PayoutId -> AccessToken -> MangoPayT m Payout fetchPayout = fetchGeneric "/payouts/" -- | make a simplep payout for creation-mkPayout :: AnyUserID -> WalletID -> Amount -> Amount -> BankAccountID -> Payout+mkPayout :: AnyUserId -> WalletId -> Amount -> Amount -> BankAccountId -> Payout mkPayout aid wid fds fees bid=Payout Nothing Nothing Nothing aid wid fds fees bid Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing -- | id of payout-type PayoutID = Text+type PayoutId = Text -- | payout data Payout=Payout {- ptId :: Maybe PayoutID+ ptId :: Maybe PayoutId ,ptCreationDate :: Maybe POSIXTime ,ptTag :: Maybe Text -- ^ custom data for client- ,ptAuthorId :: AnyUserID -- ^ The user ID of the author- ,ptDebitedWalletId :: WalletID+ ,ptAuthorId :: AnyUserId -- ^ The user Id of the author+ ,ptDebitedWalletId :: WalletId ,ptDebitedFunds :: Amount ,ptFees :: Amount- ,ptBankAccountId :: BankAccountID- ,ptCreditedUserId :: Maybe AnyUserID+ ,ptBankAccountId :: BankAccountId+ ,ptCreditedUserId :: Maybe AnyUserId ,ptCreditedFunds :: Maybe Amount ,ptStatus :: Maybe TransferStatus ,ptResultCode :: Maybe Text -- ^ The transaction result code@@ -81,5 +81,3 @@ v .:? "PaymentType" <*> v .:? "MeanOfPaymentType" parseJSON _=fail "Payout"--
src/Web/MangoPay/Refunds.hs view
@@ -15,24 +15,24 @@ import Control.Applicative -- | refund a transfer-refundTransfer :: (MPUsableMonad m) => TransferID -> AnyUserID -> AccessToken -> MangoPayT m Refund-refundTransfer tid authID at= do+refundTransfer :: (MPUsableMonad m) => TransferId -> AnyUserId -> AccessToken -> MangoPayT m Refund+refundTransfer tid authId at= do url<-getClientURLMultiple ["/transfers/",tid,"/refunds"]- postExchange url (Just at) (RefundRequest authID Nothing Nothing)+ postExchange url (Just at) (RefundRequest authId Nothing Nothing) -- | refund a pay-in-refundPayin :: (MPUsableMonad m) => AnyPayinID -> RefundRequest -> AccessToken -> MangoPayT m Refund+refundPayin :: (MPUsableMonad m) => AnyPayinId -> RefundRequest -> AccessToken -> MangoPayT m Refund refundPayin pid rr at= do url<-getClientURLMultiple ["/payins/",pid,"/refunds"] postExchange url (Just at) rr --- | fetch a refund from its ID-fetchRefund :: (MPUsableMonad m) => RefundID -> AccessToken -> MangoPayT m Refund+-- | fetch a refund from its Id+fetchRefund :: (MPUsableMonad m) => RefundId -> AccessToken -> MangoPayT m Refund fetchRefund = fetchGeneric "/refunds/" -- | refund request data RefundRequest=RefundRequest{- rrAuthorId :: AnyUserID -- ^ The user ID of the author+ rrAuthorId :: AnyUserId -- ^ The user Id of the author ,rrDebitedFunds :: Maybe Amount -- ^ Strictly positive amount. In cents. ,rrFees :: Maybe Amount -- ^ In cents }deriving (Show,Eq,Ord,Typeable)@@ -44,14 +44,14 @@ -- | id of a refund-type RefundID = Text+type RefundId = Text -- | refund of a transfer data Refund=Refund{- rId :: RefundID -- ^ Id of the refund+ rId :: RefundId -- ^ Id of the refund ,rCreationDate :: POSIXTime ,rTag :: Maybe Text -- ^ Custom data- ,rAuthorId :: AnyUserID -- ^ The user ID of the author+ ,rAuthorId :: AnyUserId -- ^ The user Id of the author ,rDebitedFunds :: Amount -- ^ Strictly positive amount. In cents. ,rFees :: Amount -- ^ In cents ,rCreditedFunds :: Amount -- ^ In cents@@ -61,11 +61,11 @@ ,rExecutionDate :: POSIXTime ,rType :: TransactionType ,rNature :: TransactionNature- ,rCreditedUserId :: Maybe AnyUserID -- ^ Id of the user owner of the credited wallet- ,rInitialTransactionId :: TransactionID -- ^ Id of the transaction being refunded+ ,rCreditedUserId :: Maybe AnyUserId -- ^ Id of the user owner of the credited wallet+ ,rInitialTransactionId :: TransactionId -- ^ Id of the transaction being refunded ,rInitialTransactionType :: TransactionType -- ^ The type of the transaction before being refunded (PayIn, Refund)- ,rDebitedWalletId :: WalletID -- ^ The Id of the debited Wallet- ,rCreditedWalletID :: Maybe WalletID -- ^ The Id of the credited Wallet+ ,rDebitedWalletId :: WalletId -- ^ The Id of the debited Wallet+ ,rCreditedWalletId :: Maybe WalletId -- ^ The Id of the credited Wallet } deriving (Show,Eq,Ord,Typeable) -- | from json as per MangoPay format
src/Web/MangoPay/Types.hs view
@@ -44,7 +44,7 @@ -- | the app credentials data Credentials = Credentials {- cClientID :: Text -- ^ client id+ cClientId :: Text -- ^ client id ,cName :: Text -- ^ the name ,cEmail :: Text -- ^ the email ,cClientSecret :: Maybe Text -- ^ client secret, maybe be Nothing if we haven't generated it@@ -53,7 +53,7 @@ -- | to json as per MangoPay format instance ToJSON Credentials where- toJSON c=object ["ClientId" .= cClientID c, "Name" .= cName c , "Email" .= cEmail c,"Passphrase" .= cClientSecret c]+ toJSON c=object ["ClientId" .= cClientId c, "Name" .= cName c , "Email" .= cEmail c,"Passphrase" .= cClientSecret c] -- | from json as per MangoPay format instance FromJSON Credentials where@@ -65,8 +65,8 @@ parseJSON _= fail "Credentials" -- | get client id in ByteString form-clientIDBS :: Credentials -> ByteString-clientIDBS=TE.encodeUtf8 . cClientID+clientIdBS :: Credentials -> ByteString+clientIdBS=TE.encodeUtf8 . cClientId -- | the access token is simply a Text@@ -130,7 +130,7 @@ -- | an error returned to us by MangoPay data MpError = MpError {- igeID :: Text+ igeId :: Text ,igeType :: Text ,igeMessage :: Text ,igeDate :: Maybe POSIXTime@@ -140,7 +140,7 @@ -- | to json as per MangoPay format instance ToJSON MpError where- toJSON mpe=object ["Id" .= igeID mpe, "Type" .= igeType mpe, "Message" .= igeMessage mpe, "Date" .= igeDate mpe]+ toJSON mpe=object ["Id" .= igeId mpe, "Type" .= igeType mpe, "Message" .= igeMessage mpe, "Date" .= igeDate mpe] -- | from json as per MangoPay format@@ -186,8 +186,8 @@ } deriving (Show,Read,Eq,Ord,Typeable) --- | ID of a card-type CardID=Text+-- | Id of a card+type CardId=Text -- | alias for Currency type Currency=Text@@ -306,10 +306,6 @@ parseJSON (String s) | Right (ce,"")<- readCardExpiration s=pure ce parseJSON _=fail "CardExpiration"---- | show Card Expiration to JSON string (MMYY)-instance ToJSON CardExpiration where- toJSON = toJSON . writeCardExpiration instance IsString CardExpiration where fromString s
src/Web/MangoPay/Users.hs view
@@ -26,8 +26,8 @@ where u' = u{uProofOfIdentity = Nothing, uProofOfAddress = Nothing} --- | fetch a natural user from her ID-fetchNaturalUser :: (MPUsableMonad m) => NaturalUserID -> AccessToken -> MangoPayT m NaturalUser+-- | fetch a natural user from her Id+fetchNaturalUser :: (MPUsableMonad m) => NaturalUserId -> AccessToken -> MangoPayT m NaturalUser fetchNaturalUser = fetchGeneric "/users/natural/" @@ -41,13 +41,13 @@ modifyLegalUser u = modifyGeneric "/users/legal/" u lId --- | fetch a natural user from her ID-fetchLegalUser :: (MPUsableMonad m) => LegalUserID -> AccessToken -> MangoPayT m LegalUser+-- | fetch a natural user from her Id+fetchLegalUser :: (MPUsableMonad m) => LegalUserId -> AccessToken -> MangoPayT m LegalUser fetchLegalUser = fetchGeneric "/users/legal/" -- | get a user, natural or legal-getUser :: (MPUsableMonad m) => AnyUserID -> AccessToken -> MangoPayT m (Either NaturalUser LegalUser)+getUser :: (MPUsableMonad m) => AnyUserId -> AccessToken -> MangoPayT m (Either NaturalUser LegalUser) getUser = fetchGeneric "/users/" @@ -56,12 +56,12 @@ listUsers = genericList ["/users/"] --- | Convenience function to extract the user ID of an EXISTING user (one with an id).-getExistingUserID+-- | Convenience function to extract the user Id of an EXISTING user (one with an id).+getExistingUserId :: Either NaturalUser LegalUser- -> AnyUserID-getExistingUserID u | Just uid <- either uId lId u = uid-getExistingUserID _ = error "Web.MangoPay.Users.getExistingUserID: Nothing"+ -> AnyUserId+getExistingUserId u | Just uid <- either uId lId u = uid+getExistingUserId _ = error "Web.MangoPay.Users.getExistingUserId: Nothing" instance FromJSON (Either NaturalUser LegalUser) where@@ -73,24 +73,24 @@ parseJSON _=fail "EitherUsers" -- not supported---deleteNaturalUser :: (MonadBaseControl IO m, MonadResource m) => UserID -> AccessToken -> MangoPayT m ()+--deleteNaturalUser :: (MonadBaseControl IO m, MonadResource m) => UserId -> AccessToken -> MangoPayT m () --deleteNaturalUser uid at=do -- url<-getClientURL (TE.encodeUtf8 $ Data.Text.concat ["/users/natural/",uid]) -- req<-getDeleteRequest url (Just at) ([]::HT.Query) -- _::Object<- getJSONResponse req -- return () --- | ID for any kind of user-type AnyUserID = Text+-- | Id for any kind of user+type AnyUserId = Text --- | User ID-type NaturalUserID = Text+-- | User Id+type NaturalUserId = Text -- | a natural user -- <http://docs.mangopay.com/api-references/users/natural-users/> data NaturalUser=NaturalUser {- uId :: Maybe NaturalUserID -- ^ The Id of the object+ uId :: Maybe NaturalUserId -- ^ The Id of the object ,uCreationDate :: Maybe POSIXTime -- ^ The creation date of the user object ,uEmail :: Text -- ^ User’s e-mail ,uFirstName :: Text -- ^ User’s firstname@@ -132,8 +132,8 @@ v .:? "ProofOfAddress" parseJSON _= fail "NaturalUser" --- | User ID-type LegalUserID = Text+-- | User Id+type LegalUserId = Text -- | the type of legal user data LegalUserType = Business | Organization@@ -218,7 +218,7 @@ -- | a short user reference data UserRef=UserRef {- urId :: AnyUserID+ urId :: AnyUserId , urCreationDate :: POSIXTime , urPersonType :: PersonType , urEmail :: Text@@ -241,4 +241,3 @@ v .: "Email" <*> v .:? "Tag" parseJSON _=fail "UserRef"-
src/Web/MangoPay/Wallets.hs view
@@ -24,37 +24,37 @@ modifyWallet w = modifyGGeneric (Just $ HM.delete "Currency") "/wallets/" w wId --- | fetch a wallet from its ID-fetchWallet :: (MPUsableMonad m) => WalletID -> AccessToken -> MangoPayT m Wallet+-- | fetch a wallet from its Id+fetchWallet :: (MPUsableMonad m) => WalletId -> AccessToken -> MangoPayT m Wallet fetchWallet = fetchGeneric "/wallets/" -- | list all wallets for a given user-listWallets :: (MPUsableMonad m) => AnyUserID -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Wallet)+listWallets :: (MPUsableMonad m) => AnyUserId -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Wallet) listWallets uid = genericList ["/users/",uid,"/wallets"] -- | create a new fund transfer createTransfer :: (MPUsableMonad m) => Transfer -> AccessToken -> MangoPayT m Transfer createTransfer = createGeneric "/transfers" --- | fetch a transfer from its ID-fetchTransfer :: (MPUsableMonad m) => TransferID -> AccessToken -> MangoPayT m Transfer+-- | fetch a transfer from its Id+fetchTransfer :: (MPUsableMonad m) => TransferId -> AccessToken -> MangoPayT m Transfer fetchTransfer = fetchGeneric "/transfers/" -- | list transfers for a given wallet-listTransactions :: (MPUsableMonad m) => WalletID -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Transaction)+listTransactions :: (MPUsableMonad m) => WalletId -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Transaction) listTransactions wid = genericList ["/wallets/",wid,"/transactions"] -- | list transfer for a given user-listTransactionsForUser :: (MPUsableMonad m) => AnyUserID -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Transaction)+listTransactionsForUser :: (MPUsableMonad m) => AnyUserId -> Maybe Pagination -> AccessToken -> MangoPayT m (PagedList Transaction) listTransactionsForUser uid = genericList ["/users/",uid,"/transactions"] --- | ID of a wallet-type WalletID=Text+-- | Id of a wallet+type WalletId=Text -- | a wallet data Wallet = Wallet {- wId:: Maybe WalletID -- ^ The Id of the wallet+ wId:: Maybe WalletId -- ^ The Id of the wallet ,wCreationDate :: Maybe POSIXTime -- ^ The creation date of the object ,wTag :: Maybe Text -- ^ Custom data ,wOwners :: [Text] -- ^ The owner of the wallet@@ -81,8 +81,8 @@ parseJSON _=fail "Wallet" --- | ID of a transfer-type TransferID=Text+-- | Id of a transfer+type TransferId=Text -- | status of a transfer data TransferStatus= Created | Succeeded | Failed@@ -103,15 +103,15 @@ -- | transfer between wallets data Transfer = Transfer{- tId :: Maybe TransferID -- ^ Id of the transfer+ tId :: Maybe TransferId -- ^ Id of the transfer ,tCreationDate :: Maybe POSIXTime -- ^ The creation date of the object ,tTag :: Maybe Text -- ^ Custom data- ,tAuthorId :: AnyUserID -- ^ The Id of the author- ,tCreditedUserId :: Maybe AnyUserID -- ^ The Id of the user owner of the credited wallet+ ,tAuthorId :: AnyUserId -- ^ The Id of the author+ ,tCreditedUserId :: Maybe AnyUserId -- ^ The Id of the user owner of the credited wallet ,tDebitedFunds :: Amount -- ^ The funds debited from the « debited wallet »DebitedFunds – Fees = CreditedFunds (amount received on wallet) ,tFees :: Amount -- ^ The fees taken on the transfer.DebitedFunds – Fees = CreditedFunds (amount received on wallet)- ,tDebitedWalletID :: WalletID -- ^ The debited wallet (where the funds are held before the transfer)- ,tCreditedWalletID:: WalletID -- ^ The credited wallet (where the funds will be held after the transfer)+ ,tDebitedWalletId :: WalletId -- ^ The debited wallet (where the funds are held before the transfer)+ ,tCreditedWalletId:: WalletId -- ^ The credited wallet (where the funds will be held after the transfer) ,tCreditedFunds :: Maybe Amount -- ^ The funds credited on the « credited wallet »DebitedFunds – Fees = CreditedFunds (amount received on wallet) ,tStatus :: Maybe TransferStatus -- ^ The status of the transfer: ,tResultCode :: Maybe Text -- ^ The transaction result code@@ -123,7 +123,7 @@ -- | to json as per MangoPay format instance ToJSON Transfer where toJSON t=object ["AuthorId" .= tAuthorId t,"CreditedUserId" .= tCreditedUserId t,"DebitedFunds" .= tDebitedFunds t,- "Fees" .= tFees t,"DebitedWalletID" .= tDebitedWalletID t,"CreditedWalletID" .= tCreditedWalletID t,+ "Fees" .= tFees t,"DebitedWalletId" .= tDebitedWalletId t,"CreditedWalletId" .= tCreditedWalletId t, "Tag" .= tTag t] -- | from json as per MangoPay format@@ -136,8 +136,8 @@ v .: "CreditedUserId" <*> v .: "DebitedFunds" <*> v .: "Fees" <*>- v .: "DebitedWalletId" <*> -- yes, it's ID one way, Id the other- v .: "CreditedWalletId" <*> -- yes, it's ID one way, Id the other+ v .: "DebitedWalletId" <*> -- yes, it's Id one way, Id the other+ v .: "CreditedWalletId" <*> -- yes, it's Id one way, Id the other v .:? "CreditedFunds" <*> v .:? "Status" <*> v .:? "ResultCode" <*>@@ -177,19 +177,19 @@ parseJSON _ =fail "TransactionNature" -type TransactionID = Text+type TransactionId = Text -- | any transaction data Transaction = Transaction{- txId :: Maybe TransactionID -- ^ Id of the transfer+ txId :: Maybe TransactionId -- ^ Id of the transfer ,txCreationDate :: Maybe POSIXTime -- ^ The creation date of the object ,txTag :: Maybe Text -- ^ Custom data- ,txAuthorId :: AnyUserID -- ^ The Id of the author- ,txCreditedUserId :: Maybe AnyUserID -- ^ The Id of the user owner of the credited wallet+ ,txAuthorId :: AnyUserId -- ^ The Id of the author+ ,txCreditedUserId :: Maybe AnyUserId -- ^ The Id of the user owner of the credited wallet ,txDebitedFunds :: Amount -- ^ The funds debited from the « debited wallet »DebitedFunds – Fees = CreditedFunds (amount received on wallet) ,txFees :: Amount -- ^ The fees taken on the transfer.DebitedFunds – Fees = CreditedFunds (amount received on wallet)- ,txDebitedWalletID :: Maybe WalletID -- ^ The debited wallet (where the funds are held before the transfer)- ,txCreditedWalletID:: Maybe WalletID -- ^ The credited wallet (where the funds will be held after the transfer)+ ,txDebitedWalletId :: Maybe WalletId -- ^ The debited wallet (where the funds are held before the transfer)+ ,txCreditedWalletId:: Maybe WalletId -- ^ The credited wallet (where the funds will be held after the transfer) ,txCreditedFunds :: Maybe Amount -- ^ The funds credited on the « credited wallet »DebitedFunds – Fees = CreditedFunds (amount received on wallet) ,txStatus :: Maybe TransferStatus -- ^ The status of the transfer: ,txResultCode :: Maybe Text -- ^ The transaction result code@@ -203,7 +203,7 @@ -- | to json as per MangoPay format instance ToJSON Transaction where toJSON t=object ["AuthorId" .= txAuthorId t,"CreditedUserId" .= txCreditedUserId t,"DebitedFunds" .= txDebitedFunds t,- "Fees" .= txFees t,"DebitedWalletID" .= txDebitedWalletID t,"CreditedWalletID" .= txCreditedWalletID t,+ "Fees" .= txFees t,"DebitedWalletID" .= txDebitedWalletId t,"CreditedWalletID" .= txCreditedWalletId t, "Tag" .= txTag t,"Type" .= txType t,"Nature" .= txNature t] -- | from json as per MangoPay format@@ -216,8 +216,8 @@ v .: "CreditedUserId" <*> v .: "DebitedFunds" <*> v .: "Fees" <*>- v .:? "DebitedWalletId" <*> -- yes, it's ID one way, Id the other- v .:? "CreditedWalletId" <*> -- yes, it's ID one way, Id the other+ v .:? "DebitedWalletId" <*> -- yes, it's Id one way, Id the other+ v .:? "CreditedWalletId" <*> -- yes, it's Id one way, Id the other v .:? "CreditedFunds" <*> v .:? "Status" <*> v .:? "ResultCode" <*>
test/Web/MangoPay/AccessTest.hs view
@@ -29,11 +29,11 @@ let mcred=decode js assertBool (isJust mcred) ct<-getPOSIXTime- -- max 20 characters in ClientID+ -- max 20 characters in ClientId let suff=T.take 20 $ T.pack $ show $ round ct let creds=(fromJust mcred) let newCreds=creds{cClientSecret=Nothing,- cClientID=T.append (cClientID creds) suff,+ cClientId=T.append (cClientId creds) suff, cName=T.append (cName creds) suff} mgr<-liftM tsManager $ readIORef testState creds2<-runResourceT $ runStdoutLoggingT $ runMangoPayT newCreds mgr Sandbox createCredentialsSecret@@ -41,7 +41,7 @@ let s=fromJust $ cClientSecret creds2 -- login once with our new credentials oat<-runResourceT $ runStdoutLoggingT $ runMangoPayT creds2 mgr Sandbox $- oauthLogin (cClientID creds2) s+ oauthLogin (cClientId creds2) s -- store access token and credentials modifyIORef testState (\ts->ts{tsAccessToken=toAccessToken oat,tsCredentials=creds2}) -- create hooks for all event types
test/Web/MangoPay/TestUtils.hs view
@@ -249,7 +249,7 @@ -- | perform the full registration of a card -- this function is UNSAFE, because if you use this, YOU manage the user's credit card details -- so you need to be PCI compliant!-unsafeFullRegistration :: (MPUsableMonad m) => AnyUserID -> Currency -> CardInfo -> AccessToken -> MangoPayT m CardRegistration+unsafeFullRegistration :: (MPUsableMonad m) => AnyUserId -> Currency -> CardInfo -> AccessToken -> MangoPayT m CardRegistration unsafeFullRegistration uid currency cardInfo at=do -- create registration let cr1=mkCardRegistration uid currency@@ -286,5 +286,3 @@ assertBool $ "data=" `T.isPrefixOf` t return cr{crRegistrationData=Just t} unsafeRegisterCard _ _=assertFailure "CardRegistration not ready"--
test/Web/MangoPay/UsersTest.hs view
@@ -30,7 +30,7 @@ assertEqual (Left ue) eu usL<-testMP $ listUsers (Just $ Pagination 1 100) assertEqual 1 (length $ filter (((fromJust $ uId u)==) . urId) $ plData usL)- assertEqual (fromJust $ uId u) (getExistingUserID $ Left u)+ assertEqual (fromJust $ uId u) (getExistingUserId $ Left u) testLegalUser :: LegalUser testLegalUser = LegalUser Nothing Nothing "jpmoresmau@gmail.com" "JP Moresmau" Business Nothing@@ -54,7 +54,7 @@ assertEqual (Right le) el usL<-testMP $ listUsers (Just $ Pagination 1 100) assertEqual 1 (length $ filter (((fromJust $ lId l)==) . urId) $ plData usL)- assertEqual (fromJust $ lId l) (getExistingUserID $ Right l)+ assertEqual (fromJust $ lId l) (getExistingUserId $ Right l) test_PaginationUsers :: Assertion test_PaginationUsers = do@@ -69,4 +69,3 @@ assertEqual 1 (plPageCount usL2) us<-testMP $ getAll listUsers assertEqual 2 (length us)-