{-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (getLine, lookup, putStr, putStrLn) import Control.Applicative import Data.Text (Text) import Data.Text.IO import qualified PayPal.Adaptive as PP import qualified PayPal.Adaptive.Deposit as DP import qualified PayPal.Adaptive.Lookup as LP import qualified PayPal.Adaptive.Withdrawal as WD -- You need to create a sandbox app on PayPal and enter its credentials -- below for this app to run. -- -- Also, the email associated with the sandbox app will need at least -- a dollar in its sandbox account. userId, password, sig, accountEmail :: Text userId = "foo_api1.example.com" password = "bar" sig = "baz" accountEmail = "foo@example.com" -- You must also create a sandbox user on PayPal. Enter its email here. -- This is the account we'll be sending money to and from. sandboxTestUser :: Text sandboxTestUser = "user@mail.com" main :: IO () main = do putStrLn "-- Sending money to another PayPal account." resp <- WD.req client withdrawal case resp of Left e -> print e Right withdrawalResp -> do print withdrawalResp putStrLn "" putStrLn "-- Creating a payment from another account to us." resp2 <- DP.req client deposit putStrLn "" case resp2 of Left e2 -> print e2 Right payKey -> do putStrLn "-- Go here and use the other account's password to approve the payment:" putStrLn (DP.approvalUrl client payKey) putStrLn "" putStrLn "-- Once that's done press enter ..." _ <- getLine putStrLn "-- Now looking up the payment on PayPal to make sure it succeeded." resp3 <- (PP.checkComplete =<<) <$> LP.req client (LP.LookupPayKey payKey) case resp3 of Left e3 -> print e3 Right completePayment -> print completePayment client :: PP.Client client = PP.Client { PP._clAppId = "APP-80W284485P519543T" -- Currently the ID for all sandbox apps. , PP._clUserId = userId , PP._clEnv = PP.Sandbox , PP._clPassword = password , PP._clSig = sig , PP._clAccountEmail = accountEmail } withdrawal :: WD.Withdrawal withdrawal = WD.Withdrawal { WD._amount = PP.USD 100 , WD._receiverEmail = sandboxTestUser } deposit :: DP.Deposit deposit = DP.Deposit { DP._amount = PP.USD 100 , DP._senderEmail = sandboxTestUser , DP._returnUrl = "https://example.com/" , DP._cancelUrl = "https://example.com/" }