Giter Club home page Giter Club logo

paypal-rest-client's Introduction

PayPal Client (for Haskell)

This library allows you to connect with PayPal's REST API V1 through Haskell.

Build Status

Master: Build Status Develop: Build Status

Warning Regarding Stability

During releases under 1.0.0, please use exact version numbers as bug fixes may require breaking changes while this library is unstable.

What Can It Do?

Currently implemented API resources include:

  • Auth
    • OAuth 2
  • Payments
    • Create a payment
    • Execute approved PayPal payment
    • Show payment details
    • List payments

Documentation and Usage Examples

Documentation can be found at the page for paypal-rest-client in Hackage.

The PayPal Monad and Session

PayPal's API uses OAuth 2 and therefore provides access tokens which expire. When this happens, the access token must be renewed. This problem is solved by the PayPalOperations monad. This monad can chain PayPal actions together which will be executed consecutively by execPayPal. If the token expires before an action is executed, the token is first renewed.

Suppose you need to create a new payment, then get that payment ID back as well as a list of all payment IDs. You could write this:

import Network.Payments.PayPal
import Network.Payments.PayPal.Payments

myOperations :: PayPalOperations (PaymentID, [PaymentID])
myOperations = do
  cRes <- createPayment $ CreateRequest ...
  lRes <- listPayments Nothing
  return (createResPayId cRes, map createResPayId $ listResPayments lRes)

Then, given you have a Config module with the credentials, you can execute the monad and get your results like so

import Config
import Network.Payments.PayPal

main :: IO ()
main = do
  payPalResult <- execPayPal sandboxUrl Config.clientId Config.secret
                             myOperations
  case payPalResult of
    Left err -> show err
    Right (newId, allIds) -> do
      putStrLn ("The new ID is: " ++ show newId)
      putStrLn ("All IDs are: " ++ show allIds)

The monad does not need to take error handling into account. If an error occurs, the monad receives a short circuit and the rest of the code is not executed. The error is simply returned to be handled. In the example, this means if createPayment fails, listPayments will never run.

paypal-rest-client's People

Contributors

meoblast001 avatar simonmichael avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.