module Web.MangoPay.Payins 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
storeBankWire :: (MPUsableMonad m) => BankWire -> AccessToken -> MangoPayT m BankWire
storeBankWire bw at= do
url<-getClientURL "/payins/bankwire/direct"
postExchange url (Just at) bw
fetchBankWire :: (MPUsableMonad m) => BankWireID -> AccessToken -> MangoPayT m BankWire
fetchBankWire bwid at=do
url<-getClientURLMultiple ["/payins/",bwid]
req<-getGetRequest url (Just at) ([]::HT.Query)
getJSONResponse req
storeCardPayin :: (MPUsableMonad m) => CardPayin -> AccessToken -> MangoPayT m CardPayin
storeCardPayin cp at= do
url<-getClientURL "/payins/card/direct"
postExchange url (Just at) cp
fetchCardPayin :: (MPUsableMonad m) => CardPayinID -> AccessToken -> MangoPayT m CardPayin
fetchCardPayin cpid at=do
url<-getClientURLMultiple ["/payins/",cpid]
req<-getGetRequest url (Just at) ([]::HT.Query)
getJSONResponse req
data PaymentExecution = WEB
| DIRECT
deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)
instance ToJSON PaymentExecution where
toJSON =toJSON . show
instance FromJSON PaymentExecution where
parseJSON (String s)=pure $ read $ unpack s
parseJSON _ =fail "PaymentExecution"
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
type AnyPayinID=Text
type BankWireID=Text
data BankWire=BankWire {
bwId :: Maybe BankWireID
,bwCreationDate :: Maybe POSIXTime
,bwTag :: Maybe Text
,bwAuthorId :: AnyUserID
,bwCreditedUserId :: AnyUserID
,bwFees :: Maybe Amount
,bwCreditedWalletId :: WalletID
,bwDebitedWalletId :: Maybe WalletID
,bwDebitedFunds :: Maybe Amount
,bwCreditedFunds :: Maybe Amount
,bwDeclaredDebitedFunds :: Amount
,bwDeclaredFees :: Amount
,bwWireReference :: Maybe Text
,bwBankAccount :: Maybe BankAccount
,bwStatus :: Maybe TransferStatus
,bwResultCode :: Maybe Text
,bwResultMessage :: Maybe Text
,bwExecutionDate :: Maybe POSIXTime
,bwType :: Maybe TransactionType
,bwNature :: Maybe TransactionNature
,bwPaymentType :: Maybe PaymentType
,bwExecutionType :: Maybe PaymentExecution
} deriving (Show,Eq,Ord,Typeable)
instance ToJSON BankWire where
toJSON bw=object ["Tag" .= bwTag bw,"AuthorId" .= bwAuthorId bw
,"CreditedUserId" .= bwCreditedUserId bw,"CreditedWalletId" .= bwCreditedWalletId bw
,"DeclaredDebitedFunds" .= bwDeclaredDebitedFunds bw,"DeclaredFees" .= bwDeclaredFees bw]
instance FromJSON BankWire where
parseJSON (Object v) =BankWire <$>
v .: "Id" <*>
v .: "CreationDate" <*>
v .:? "Tag" <*>
v .: "AuthorId" <*>
v .: "CreditedUserId" <*>
v .:? "Fees" <*>
v .: "CreditedWalletId" <*>
v .:? "DebitedWalletId" <*>
v .:? "DebitedFunds" <*>
v .:? "CreditedFunds" <*>
v .: "DeclaredDebitedFunds" <*>
v .: "DeclaredFees" <*>
v .:? "WireReference" <*>
v .:? "BankAccount" <*>
v .:? "Status" <*>
v .:? "ResultCode" <*>
v .:? "ResultMessage" <*>
v .:? "ExecutionDate" <*>
v .:? "Type" <*>
v .:? "Nature" <*>
v .:? "PaymentType" <*>
v .:? "ExecutionType"
parseJSON _=fail "BankWire"
type CardPayinID=Text
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
data CardPayin=CardPayin {
cpId :: Maybe CardPayinID
,cpCreationDate :: Maybe POSIXTime
,cpTag :: Maybe Text
,cpAuthorId :: AnyUserID
,cpCreditedUserId :: AnyUserID
,cpFees :: Amount
,cpCreditedWalletId :: WalletID
,cpDebitedWalletId :: Maybe WalletID
,cpDebitedFunds :: Amount
,cpCreditedFunds :: Maybe Amount
,cpSecureModeReturnURL :: Maybe Text
,cpSecureMode :: Maybe Text
,cpSecureModeRedirectURL :: Maybe Text
,cpCardId :: CardID
,cpStatus :: Maybe TransferStatus
,cpResultCode :: Maybe Text
,cpResultMessage :: Maybe Text
,cpExecutionDate :: Maybe POSIXTime
,cpType :: Maybe TransactionType
,cpNature :: Maybe TransactionNature
,cpPaymentType :: Maybe Text
,cpExecutionType :: Maybe PaymentExecution
} deriving (Show,Eq,Ord,Typeable)
instance ToJSON CardPayin where
toJSON cp=object ["Tag" .= cpTag cp,"AuthorId" .= cpAuthorId cp
,"CreditedUserId" .= cpCreditedUserId cp,"CreditedWalletId" .= cpCreditedWalletId cp
,"DebitedFunds" .= cpDebitedFunds cp,"Fees" .= cpFees cp,"CardID" .= cpCardId cp
,"SecureModeReturnURL" .= cpSecureModeReturnURL cp
,"SecureMode" .= cpSecureMode cp]
instance FromJSON CardPayin where
parseJSON (Object v) =CardPayin <$>
v .: "Id" <*>
v .: "CreationDate" <*>
v .:? "Tag" <*>
v .: "AuthorId" <*>
v .: "CreditedUserId" <*>
v .: "Fees" <*>
v .: "CreditedWalletId" <*>
v .:? "DebitedWalletId" <*>
v .: "DebitedFunds" <*>
v .:? "CreditedFunds" <*>
v .:? "SecureModeReturnURL" <*>
v .:? "SecureModeRedirectURL" <*>
v .:? "SecureMode" <*>
v .: "CardId" <*>
v .:? "Status" <*>
v .:? "ResultCode" <*>
v .:? "ResultMessage" <*>
v .:? "ExecutionDate" <*>
v .:? "Type" <*>
v .:? "Nature" <*>
v .:? "PaymentType" <*>
v .:? "ExecutionType"
parseJSON _=fail "CardPayin"