Permalink
Browse files

Initial release

  • Loading branch information...
0 parents commit 1316578de78787c93fc6231044f1879185ce9a67 @fnando committed Jun 27, 2011
Showing with 5,760 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +1 −0 .rspec
  3. +2 −0 Gemfile
  4. +45 −0 Gemfile.lock
  5. +128 −0 README.rdoc
  6. +5 −0 Rakefile
  7. BIN docs/PP_NVPAPI_DeveloperGuide.pdf
  8. BIN docs/PP_WPP_IntegrationGuide.pdf
  9. +1 −0 lib/paypal-recurring.rb
  10. +106 −0 lib/paypal/recurring.rb
  11. +149 −0 lib/paypal/recurring/base.rb
  12. +3,987 −0 lib/paypal/recurring/cacert.pem
  13. +143 −0 lib/paypal/recurring/request.rb
  14. +26 −0 lib/paypal/recurring/response.rb
  15. +74 −0 lib/paypal/recurring/response/base.rb
  16. +11 −0 lib/paypal/recurring/response/checkout.rb
  17. +26 −0 lib/paypal/recurring/response/details.rb
  18. +12 −0 lib/paypal/recurring/response/manage_profile.rb
  19. +22 −0 lib/paypal/recurring/response/payment.rb
  20. +69 −0 lib/paypal/recurring/response/profile.rb
  21. +10 −0 lib/paypal/recurring/version.rb
  22. +25 −0 paypal-recurring.gemspec
  23. +26 −0 spec/fixtures/checkout/failure.yml
  24. +26 −0 spec/fixtures/checkout/success.yml
  25. +26 −0 spec/fixtures/create_profile/failure.yml
  26. +26 −0 spec/fixtures/create_profile/success.yml
  27. +26 −0 spec/fixtures/details/cancelled.yml
  28. +26 −0 spec/fixtures/details/failure.yml
  29. +26 −0 spec/fixtures/details/success.yml
  30. +26 −0 spec/fixtures/payment/failure.yml
  31. +26 −0 spec/fixtures/payment/success.yml
  32. +26 −0 spec/fixtures/profile/cancel/failure.yml
  33. +26 −0 spec/fixtures/profile/cancel/success.yml
  34. +26 −0 spec/fixtures/profile/failure.yml
  35. +26 −0 spec/fixtures/profile/reactivate/failure.yml
  36. +26 −0 spec/fixtures/profile/reactivate/success.yml
  37. +26 −0 spec/fixtures/profile/success.yml
  38. +26 −0 spec/fixtures/profile/suspend/failure.yml
  39. +26 −0 spec/fixtures/profile/suspend/success.yml
  40. +87 −0 spec/paypal/recurring_spec.rb
  41. +102 −0 spec/paypal/request_spec.rb
  42. +51 −0 spec/paypal/response/checkout_details_spec.rb
  43. +32 −0 spec/paypal/response/checkout_spec.rb
  44. +39 −0 spec/paypal/response/create_recurring_profile_spec.rb
  45. +62 −0 spec/paypal/response/manage_profile_spec.rb
  46. +41 −0 spec/paypal/response/profile_spec.rb
  47. +35 −0 spec/paypal/response/request_payment_spec.rb
  48. +24 −0 spec/spec_helper.rb
@@ -0,0 +1,3 @@
+.DS_Store
+pkg
+tmp
1 .rspec
@@ -0,0 +1 @@
+--color --format documentation
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
@@ -0,0 +1,45 @@
+PATH
+ remote: .
+ specs:
+ paypal-recurring (0.1.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ archive-tar-minitar (0.5.2)
+ columnize (0.3.3)
+ diff-lcs (1.1.2)
+ fakeweb (1.3.0)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
+ rake (0.8.7)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
+ vcr (1.10.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ fakeweb (~> 1.3.0)
+ paypal-recurring!
+ rake (~> 0.8.7)
+ rspec (~> 2.6)
+ ruby-debug19
+ vcr (~> 1.10)
@@ -0,0 +1,128 @@
+= 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 <tt>response.checkout_url</tt>.
+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: <tt>PAYERID</tt> and <tt>TOKEN</tt>. You can use the <tt>TOKEN</tt>
+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
+<tt>checkout_details()</tt> 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: <tt>TOKEN</tt> and <tt>PROFILEID</tt>.
+<tt>TOKEN</tt> 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 <tt>PROFILEID</tt> allows you to manage the recurring profile, like canceling billing when an user don't
+want to use your service anymore.
+
+<b>NOTE:</b> TOKEN will expire after approximately 3 hours.
+
+== TO-DO
+
+* handle Instant Payment Notifications (IPN)
+
+== Maintainer
+
+* Nando Vieira (http://nandovieira.com.br)
+
+== 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.
@@ -0,0 +1,5 @@
+require "bundler"
+Bundler::GemHelper.install_tasks
+
+require "rspec/core/rake_task"
+RSpec::Core::RakeTask.new
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+require "paypal/recurring"
@@ -0,0 +1,106 @@
+require "net/https"
+require "cgi"
+require "uri"
+require "logger"
+require "ostruct"
+require "time"
+
+module PayPal
+ module Recurring
+ autoload :Base, "paypal/recurring/base"
+ autoload :Request, "paypal/recurring/request"
+ autoload :Response, "paypal/recurring/response"
+ autoload :Version, "paypal/recurring/version"
+
+ ENDPOINTS = {
+ :sandbox => {
+ :api => "https://api-3t.sandbox.paypal.com/nvp",
+ :site => "https://www.sandbox.paypal.com/cgi-bin/webscr"
+ },
+ :production => {
+ :api => "https://api-3t.paypal.com/nvp",
+ :site => "https://www.paypal.com/cgi-bin/webscr"
+ }
+ }
+
+ class << self
+ # Define if requests should be made to PayPal's
+ # sandbox environment. This is specially useful when running
+ # on development or test mode.
+ #
+ # PayPal::Recurring.sandbox = true
+ #
+ attr_accessor :sandbox
+
+ # Set PayPal's API username.
+ #
+ attr_accessor :username
+
+ # Set PayPal's API password.
+ #
+ attr_accessor :password
+
+ # Set PayPal's API signature.
+ #
+ attr_accessor :signature
+
+ # Set application logger. By default, will send output to +STDOUT+.
+ #
+ attr_accessor :logger
+ end
+
+ self.logger = Logger.new(STDOUT)
+
+ # Just a shortcut for <tt>PayPal::Recurring::Base.new</tt>.
+ #
+ def self.new(options = {})
+ Base.new(options)
+ end
+
+ # Configure PayPal::Recurring options.
+ #
+ # PayPal::Recurring.configure do |config|
+ # config.sandbox = true
+ # end
+ #
+ def self.configure(&block)
+ yield PayPal::Recurring
+ end
+
+ # Detect if sandbox mode is enabled.
+ #
+ def self.sandbox?
+ sandbox == true
+ end
+
+ # Return a name for current environment mode (sandbox or production).
+ #
+ def self.environment
+ sandbox? ? :sandbox : :production
+ end
+
+ # Return URL endpoints for current environment.
+ #
+ def self.endpoints
+ ENDPOINTS[environment]
+ end
+
+ # Return API endpoint based on current environment.
+ #
+ def self.api_endpoint
+ endpoints[:api]
+ end
+
+ # Return PayPal's API version.
+ #
+ def self.api_version
+ "72.0"
+ end
+
+ # Return site endpoint based on current environment.
+ #
+ def self.site_endpoint
+ endpoints[:site]
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 1316578

Please sign in to comment.