packages feed

paypal-adaptive-hoops 0.5.2.0 → 0.5.3.0

raw patch · 4 files changed

+83/−22 lines, 4 filesdep ~textPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: text

API changes (from Hackage documentation)

+ Web.PayPal.Adaptive: approvalUrl :: PpClient -> PayKey -> Text

Files

Example.hs view
@@ -2,28 +2,77 @@  module Main where -import Data.Default (def)-import Web.PayPal.Adaptive+import           Prelude             hiding (getLine, lookup, putStr, putStrLn)+import           Data.Default+import           Data.Text           (Text)+import           Data.Text.IO+import           Web.PayPal.Adaptive --- NOTE: This won't actually run without a real sandbox password, sig, and userId.+-- 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.+accountEmail, userId, password, sig :: Text+accountEmail = "foo@example.com"+userId       = "foo_api1.example.com"+password     = "bar"+sig          = "baz"++-- 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 = toPayPal client send >>= print+main = do+  putStrLn "-- Sending money to another PayPal account."+  toPayPal client send >>= print+  putStrLn "" -  where-    client :: PpClient-    client = PpClient-      { _clAppId    = "APP-80W284485P519543T" -- Currently the ID for all sandbox apps.-      , _clEnv      = PpSandbox-      , _clPassword = "some-gibberish"-      , _clSig      = "long-string-of-gibberish"-      , _clUserId   = "foo_api1.mail.com"-      }+  putStrLn "-- Creating a payment from another account to us."+  r <- toPayPal client create+  print r+  putStrLn ""+  case r of+    Left _        -> putStrLn "Stopping on create payment failure."+    Right payResp -> do -    send :: SendPayment-    send = def-      { _spReceiverList = ReceiverList-        { _rlAmount = USD 100-        , _rlEmail = "user@mail.com"-        }-      , _spSenderEmail = "foo@mail.com"-      }+      let payKey = _prPayKey payResp+      putStrLn "-- Go here and use the other account's password to approve the payment:"+      putStrLn $ 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."+      toPayPal client (LookupPayKey payKey) >>= print++client :: PpClient+client = PpClient+  { _clAppId    = "APP-80W284485P519543T" -- Currently the ID for all sandbox apps.+  , _clEnv      = PpSandbox+  , _clPassword = password+  , _clSig      = sig+  , _clUserId   = userId+  }++send :: SendPayment+send = def+  { _spReceiverList = ReceiverList+    { _rlAmount = USD 100+    , _rlEmail = sandboxTestUser+    }+  , _spSenderEmail = accountEmail+  }++create :: CreatePayment+create = def+  { _cpReceiverList = ReceiverList+    { _rlAmount = USD 100+    , _rlEmail = accountEmail+    }+  , _cpSenderEmail = sandboxTestUser+  }
paypal-adaptive-hoops.cabal view
@@ -1,5 +1,5 @@ name:                 paypal-adaptive-hoops-version:              0.5.2.0+version:              0.5.3.0 author:               Ian Grant Jeffries maintainer:           ian@housejeffries.com category:             Web@@ -69,6 +69,7 @@   build-depends:      base                     , data-default                     , paypal-adaptive-hoops+                    , text  source-repository head   type:               git
src/Web/PayPal/Adaptive.hs view
@@ -15,6 +15,7 @@   , TransactionId    (..)   , TransactionStatus(..)   , Money            (..)+  , approvalUrl   , m2Currency   , m2PayPal   ) where
src/Web/PayPal/Adaptive/Core.hs view
@@ -265,6 +265,16 @@           PeError      -> Left $ AeRefused a           _            -> Left $ AeShouldNotHappen a "got unsupported PayExecStatus" +approvalUrl :: PpClient -> PayKey -> Text+approvalUrl c k =+  case _clEnv c of+    PpSandbox ->+      "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey="+      <> _unPayKey k+    PpProduction ->+      "https://www.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey="+      <> _unPayKey k+ -------------------------------------------------- -- Lookup Payment --------------------------------------------------