{-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (getLine, lookup, putStr, putStrLn) import Data.Default import Data.Text (Text) import Data.Text.IO import qualified Web.PayPal.Adaptive as PP -- 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." PP.toPayPal client withdrawal >>= print putStrLn "" putStrLn "-- Creating a payment from another account to us." r <- PP.toPayPal client deposit print r putStrLn "" case r of Left _ -> putStrLn "Stopping on create payment failure." Right payResp -> do let payKey = PP._prPayKey payResp putStrLn "-- Go here and use the other account's password to approve the payment:" putStrLn $ PP.approvalUrl client payKey putStrLn "" putStrLn "-- Once that's done press enter ..." _ <- getLine putStrLn "-- Now looking up the payment on PayPal to make sure that succeeded." putStrLn "-- If it did _prPayExecStatus will have changed from PeCreated to PeCompleted." PP.toPayPal client (PP.LookupPayKey payKey) >>= print 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 :: PP.Withdrawal withdrawal = def { PP._wdAmount = PP.USD 100 , PP._wdReceiverEmail = sandboxTestUser } deposit :: PP.Deposit deposit = def { PP._dpAmount = PP.USD 100 , PP._dpSenderEmail = sandboxTestUser }