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 Control.Applicative
createPayout :: (MPUsableMonad m) => Payout -> AccessToken -> MangoPayT m Payout
createPayout = createGeneric "/payouts/bankwire"
fetchPayout :: (MPUsableMonad m) => PayoutId -> AccessToken -> MangoPayT m Payout
fetchPayout = fetchGeneric "/payouts/"
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 Nothing
type PayoutId = Text
data Payout=Payout {
ptId :: Maybe PayoutId
,ptCreationDate :: Maybe MpTime
,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 MpTime
,ptType :: Maybe TransactionType
,ptNature :: Maybe TransactionNature
,ptPaymentType :: Maybe PaymentType
,ptMeanOfPaymentType :: Maybe PaymentType
,ptBankWireRef :: Maybe Text
} deriving (Show,Eq,Ord,Typeable)
instance ToJSON Payout where
toJSON pt=objectSN ["Tag" .= ptTag pt,"AuthorId" .= ptAuthorId pt
,"DebitedWalletId" .= ptDebitedWalletId pt
,"DebitedFunds" .= ptDebitedFunds pt,"Fees" .= ptFees pt,"BankAccountId" .= ptBankAccountId pt
,"BankWireRef" .= ptBankWireRef 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" <*>
v .:? "BankWireRef"
parseJSON _=fail "Payout"