module Web.MangoPay.Payouts where
import Web.MangoPay.Accounts
import Web.MangoPay.Monad
import Web.MangoPay.Types
import Web.MangoPay.Users
import Web.MangoPay.Wallets
import Data.Text
import Data.Typeable (Typeable)
import Data.Aeson
import Data.Time.Clock.POSIX (POSIXTime)
import Control.Applicative
import qualified Network.HTTP.Types as HT
storePayout :: (MPUsableMonad m) => Payout -> AccessToken -> MangoPayT m Payout
storePayout pt at= do
url<-getClientURL "/payouts/bankwire"
postExchange url (Just at) pt
fetchPayout :: (MPUsableMonad m) => PayoutID -> AccessToken -> MangoPayT m Payout
fetchPayout ptid at=do
url<-getClientURLMultiple ["/payouts/",ptid]
req<-getGetRequest url (Just at) ([]::HT.Query)
getJSONResponse req
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
type PayoutID = Text
data Payout=Payout {
ptId :: Maybe PayoutID
,ptCreationDate :: Maybe POSIXTime
,ptTag :: Maybe Text
,ptAuthorId :: AnyUserID
,ptDebitedWalletId :: WalletID
,ptDebitedFunds :: Amount
,ptFees :: Amount
,ptBankAccountId :: BankAccountID
,ptCreditedUserId :: Maybe AnyUserID
,ptCreditedFunds :: Maybe Amount
,ptStatus :: Maybe TransferStatus
,ptResultCode :: Maybe Text
,ptResultMessage :: Maybe Text
,ptExecutionDate :: Maybe POSIXTime
,ptType :: Maybe TransactionType
,ptNature :: Maybe TransactionNature
,ptPaymentType :: Maybe PaymentType
,ptMeanOfPaymentType :: Maybe PaymentType
} deriving (Show,Eq,Ord,Typeable)
instance ToJSON Payout where
toJSON pt=object ["Tag" .= ptTag pt,"AuthorId" .= ptAuthorId pt
,"DebitedWalletId" .= ptDebitedWalletId pt
,"DebitedFunds" .= ptDebitedFunds pt,"Fees" .= ptFees pt,"BankAccountId" .= ptBankAccountId pt]
instance FromJSON Payout where
parseJSON (Object v) =Payout <$>
v .: "Id" <*>
v .: "CreationDate" <*>
v .:? "Tag" <*>
v .: "AuthorId" <*>
v .: "DebitedWalletId" <*>
v .: "DebitedFunds" <*>
v .: "Fees" <*>
v .: "BankAccountId" <*>
v .:? "CreditedUserId" <*>
v .:? "CreditedFunds" <*>
v .:? "Status" <*>
v .:? "ResultCode" <*>
v .:? "ResultMessage" <*>
v .:? "ExecutionDate" <*>
v .:? "Type" <*>
v .:? "Nature" <*>
v .:? "PaymentType" <*>
v .:? "MeanOfPaymentType"
parseJSON _=fail "Payout"