yesod-paypal-rest (empty) → 0.1.0
raw patch · 4 files changed
+120/−0 lines, 4 filesdep +basedep +paypal-rest-clientdep +timesetup-changed
Dependencies added: base, paypal-rest-client, time, yesod-core
Files
- LICENSE +20/−0
- Setup.hs +2/−0
- src/Yesod/Payments/PayPal.hs +62/−0
- yesod-paypal-rest.cabal +36/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2016 Braden Walters++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Yesod/Payments/PayPal.hs view
@@ -0,0 +1,62 @@+-- |+-- Module: Yesod.Payments.PayPal+-- Copyright: (C) 2016 Braden Walters+-- License: MIT (see LICENSE file)+-- Maintainer: Braden Walters <vc@braden-walters.info>+-- Stability: experimental+-- Portability: ghc++module Yesod.Payments.PayPal+( PayPalCredentials+, YesodPayPalState+, mkYesodPayPalState+, YesodPayPal(..)+, yesodExecPayPal+) where++import Data.IORef+import Data.Time.Clock+import Network.Payments.PayPal+import Network.Payments.PayPal.Auth+import Network.Payments.PayPal.Environment+import Yesod.Core++-- |All credentials needed to log into PayPal's API.+type PayPalCredentials = (EnvironmentUrl, ClientID, Secret)++-- |State needed over multiple PayPal requests.+data YesodPayPalState =+ YesodPayPalState { yPpStToken :: IORef (AccessToken, UTCTime) }++-- |Create a PayPal state for a site.+mkYesodPayPalState :: PayPalCredentials -> IO (Maybe YesodPayPalState)+mkYesodPayPalState (envUrl, clientId, secret) = do+ accessTokenOrErr <- fetchAccessTokenWithExpiration envUrl clientId secret+ case accessTokenOrErr of+ Left err -> return Nothing+ Right accessToken -> do+ ref <- newIORef accessToken+ return $ Just $ YesodPayPalState ref++-- |Typeclass for Yesod sites which use PayPal.+class Yesod site => YesodPayPal site where+ -- |The PayPal API credentials for a site.+ yesodPayPalCredentials :: site -> PayPalCredentials+ -- |State needed over multiple PayPal requests for a site.+ yesodPayPalState :: site -> YesodPayPalState++-- |Execute PayPal operations in the context of Yesod.+yesodExecPayPal :: (YesodPayPal site, FromJSON a) =>+ PayPalOperations a -> HandlerT site IO (Either PayPalError a)+yesodExecPayPal operations = do+ site <- getYesod+ let (envUrl, clientId, secret) = yesodPayPalCredentials site+ accessTokenRef = yPpStToken $ yesodPayPalState site+ liftIO $ do+ accessToken <- readIORef accessTokenRef+ resultOrErr <- execPayPalOpers envUrl clientId secret accessToken operations+ case resultOrErr of+ Left err -> return $ Left err+ Right (result, accessToken') -> do+ writeIORef accessTokenRef accessToken'+ return $ Right result
+ yesod-paypal-rest.cabal view
@@ -0,0 +1,36 @@+name: yesod-paypal-rest+version: 0.1.0+synopsis: Yesod plugin to use PayPal with the paypal-rest-client library.+license: MIT+license-file: LICENSE+author: Braden Walters+maintainer: vc@braden-walters.info+category: Yesod+stability: experimental+build-type: Simple+cabal-version: >= 1.10+Tested-With: GHC == 7.8.4, GHC == 7.10.2, GHC == 8.0.1++description:+ Library to connect Yesod applications with PayPal's+ <https://developer.paypal.com/docs/api/ REST API v1> by using the+ <http://hackage.haskell.org/package/paypal-rest-client paypal-reset-client>+ package. For documentation, see the+ <https://github.com/meoblast001/yesod-paypal-rest/blob/master/README.md README>.+ Due to the experimental nature of the paypal-rest-client, it is recommended to+ explicitly give an exact version of that package even when you are already+ including this package.++library+ exposed-modules: Yesod.Payments.PayPal+ build-depends:+ base >= 4 && < 5+ , yesod-core >= 1.2 && < 1.5+ , paypal-rest-client < 1.0.0+ , time >= 1.5 && < 1.7+ hs-source-dirs: src+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/meoblast001/yesod-paypal-rest.git