Coder Social home page Coder Social logo

lift-paypalrest's Introduction

Lift PayPal REST

Lift PayPal REST is a Lift module that makes it easy to create Comet applications using PayPal's REST API. Here is an example website built with it.

##Good stuff:

  • More control of your checkout process with Authorizations, Payments, PayerInfos, etc.
  • All monetary values are in CurrencyZone#Currency
  • More control of the API call using futures. Use with Actors or directly with Await
  • All PayPal messages are case classes

Example Usage

  1. Create an Actor object that extends LiftPayPalServer. This Actor makes the actual API calls and deals with handling tokens, etc.

  2. Create a Comet for dealing with the purchasing logic. This Comet will send messages to the actor from the previous step and receives messages back by e.g. sending a reference to itself in the messages sent to the API server. E.g.

    "#buy [onclick]" #> { YourPayPalServer ! CreateAuthorization(callBackUrl, callBackCancelUrl, itemsInfoEtc, price, this) ... } ... override def lowPriority: PartialFunction[Any, Unit] = { case AuthorizationCreated(id, approvalUrl) => ... }

  3. Create an object that extends PayPalRestHelper and add your own serve. The user is redirected back from PayPal to the URL that this object listens on, e.g. /paypal and the call will contain the payer id (or it is a cancellation) E.g.

    object YourPayPalRestServer extends PayPalRestHelper { serve { case List("paypal") Get req => withPayerId(req, (payerId: PayerId) => { msgComet(payerId) RedirectResponse("/your/url/here", req) })

     case List("paypal", "cancel") Get req =>
       msgComet(CancelPayment)
       RedirectResponse("/your/cancel/url/here", req)
    

    }

    def msgComet(msg: Any) = S.session.foreach( _.sendCometActorMessage("YourComet", Empty, msg) ) }

  4. Add to boot from the previous step:

    LiftRules.dispatch.append(YourPayPalRestServer)

Installing

Download lift-paypalrest_2.10-0.0.1.jar into your project folder or build it yourself (proper hosted builds coming soon)

In build.sbt:

unmanagedJars in Compile += file("lift-paypalrest_2.10-0.0.1.jar")
  libraryDependencies ++= {
    val liftVersion = "2.6-SNAPSHOT"
    val specsVersion = "2.4-SNAPSHOT"
    Seq(
      "net.liftweb" %% "lift-webkit" % liftVersion % "compile",
      "org.specs2" %% "specs2-core" % specsVersion % "test",
      "org.specs2" %% "specs2-junit" % specsVersion % "test",
      "net.databinder.dispatch" %% "dispatch-core" % "0.11.0",
      "net.databinder.dispatch" %% "dispatch-lift-json" % "0.11.0"
    )
  }

Add your Test credential client id and secret from https://developer.paypal.com/webapps/developer/applications/myapps to /src/main/resources/props/default.props /src/test/resources/props/test.default.props:

paypal.endpoint=api.sandbox.paypal.com
paypal.client.id=TEST_CLIENT_ID
paypal.client.secret=TEST_SECRET
paypal.callbackurl=http://localhost:8080/paypal

Then add your Live credentials from the same page to /src/main/resources/props/production.default.props:

paypal.endpoint=api.paypal.com
paypal.client.id=LIVE_CLIENT_ID
paypal.client.secret=LIVE_SECRET
paypal.callbackurl=https://INSERT_YOUR_DOMAIN_HERE_DONT_USE_THIS_HAHA.com/paypal

If you want something else than /paypal as the suffix of your callbackurl, remember to match for it in your PayPalRestHelper's serve

Building

Requires sbt >= 0.13.5 and JRE >= 7

git clone https://github.com/i-k/lift-paypal.git
cd lift-paypal
sbt package

Adding and running tests

Add your Test credentials (see Installing) to /src/test/resources/props/test.default.props to make calls to PayPal

Coming soon

  • Premade case classes for the logic between Comets and the API-actor
  • More default values to PayPalRestHelper
  • Hosted builds

In other words adding a few steps in between this:

How to draw an owl

License

Open source software released under the Apache 2.0 license.

lift-paypalrest's People

Contributors

i-k avatar

Stargazers

ian parkins avatar

Watchers

 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.