GithubHelp home page GithubHelp logo

paypal-recurring's Introduction

PayPal Recurring Billing

PayPal Express Checkout API Client for recurring billing.

Installation

gem install paypal-recurring

Usage

First, you need to set up your credentials:

require "paypal/recurring"

PayPal::Recurring.configure do |config|
  config.sandbox = true
  config.username = "seller_1308793919_biz_api1.simplesideias.com.br"
  config.password = "1308793931"
  config.signature = "AFcWxV21C7fd0v3bYYYRCpSSRl31AzaB6TzXx5amObyEghjU13.0av2Y"
end

Then, you can request a new payment authorization:

ppr = PayPal::Recurring.new({
  :return_url   => "http://example.com/paypal/thank_you",
  :cancel_url   => "http://example.com/paypal/canceled",
  :ipn_url      => "http://example.com/paypal/ipn",
  :description  => "Awesome - Monthly Subscription",
  :amount       => "9.00",
  :currency     => "USD"
})

response = ppr.checkout
puts response.checkout_url if response.valid?

You need to redirect your user to the url returned by response.checkout_url. After the user accepts or rejects your payment request, he will be redirected to one of those urls you specified. The return url will receive two parameters: PAYERID and TOKEN. You can use the TOKEN parameter to identify your user on your database.

If you need to retrieve information about your buyer, like address or e-mail, you can use the checkout_details() method.

ppr = PayPal::Recurring.new(:token => "EC-05C46042TU8306821")
response = ppr.checkout_details

Now, you need to request payment. The information you provide here should be exactly the same when you started the checkout process.

ppr = PayPal::Recurring.new({
  :token       => "EC-05C46042TU8306821",
  :payer_id    => "WTTS5KC2T46YU",
  :amount      => "9.00",
  :description => "Awesome - Monthly Subscription"
})
response = ppr.request_payment
response.approved?
response.completed?

Finally, you need to create a new recurring profile.

ppr = PayPal::Recurring.new({
  :amount      => "9.00",
  :currency    => "USD",
  :description => "Awesome - Monthly Subscription",
  :ipn_url     => "http://example.com/paypal/ipn",
  :frequency   => 1,
  :token       => "EC-05C46042TU8306821",
  :period      => :monthly,
  :reference   => "1234",
  :payer_id    => "WTTS5KC2T46YU",
  :start_at    => Time.now,
  :failed      => 1,
  :outstanding => :next_billing
})

response = ppr.create_recurring_profile
puts response.profile_id

You can manage your recurring profile.

ppr = PayPal::Recurring.new(:profile_id => "I-VCEL6TRG35CU")

ppr.suspend
ppr.reactivate
ppr.cancel

What information do I need to keep?

You should save two paramaters to your database: TOKEN and PROFILEID. TOKEN is required when user returns to your website after he authorizes (or not) the billing process. You need to save it so you can find him later. You can remove this info after payment and recurring profile are set.

The PROFILEID allows you to manage the recurring profile, like canceling billing when an user don’t want to use your service anymore.

NOTE: TOKEN will expire after approximately 3 hours.

TO-DO

  • handle Instant Payment Notifications (IPN)

Maintainer

License

(The MIT License)

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.

paypal-recurring's People

Contributors

fnando avatar mikian avatar rlivsey avatar

Stargazers

 avatar

Watchers

 avatar James Cloos 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.