paypal-subscribe 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ gem "activesupport"
10
+
11
+ group :development do
12
+ gem "rspec", "~> 2.8.0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.8.4"
16
+ gem "simplecov", ">= 0"
17
+ gem "fuubar"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.7)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ diff-lcs (1.1.3)
8
+ fuubar (1.0.0)
9
+ rspec (~> 2.0)
10
+ rspec-instafail (~> 0.2.0)
11
+ ruby-progressbar (~> 0.0.10)
12
+ git (1.2.5)
13
+ i18n (0.6.0)
14
+ jeweler (1.8.4)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ rdoc
19
+ json (1.7.4)
20
+ multi_json (1.3.6)
21
+ rake (0.9.2.2)
22
+ rdoc (3.12)
23
+ json (~> 1.4)
24
+ rspec (2.8.0)
25
+ rspec-core (~> 2.8.0)
26
+ rspec-expectations (~> 2.8.0)
27
+ rspec-mocks (~> 2.8.0)
28
+ rspec-core (2.8.0)
29
+ rspec-expectations (2.8.0)
30
+ diff-lcs (~> 1.1.2)
31
+ rspec-instafail (0.2.4)
32
+ rspec-mocks (2.8.0)
33
+ ruby-progressbar (0.0.10)
34
+ simplecov (0.6.4)
35
+ multi_json (~> 1.0)
36
+ simplecov-html (~> 0.5.3)
37
+ simplecov-html (0.5.3)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ activesupport
44
+ bundler (~> 1.0.0)
45
+ fuubar
46
+ jeweler (~> 1.8.4)
47
+ rdoc (~> 3.12)
48
+ rspec (~> 2.8.0)
49
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Daniel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,159 @@
1
+ ## paypal-subscribe
2
+
3
+ Dealing with PayPal is hell. It's nice to use it as customer. But implementing its API isn't very nice.
4
+ Unfortunately in Germany there is no support for PayPal's recurring payment API on the part of PayPal.
5
+
6
+ Before smashing my head against the wall, I decided to use their offer of creating a **subscription** button.
7
+
8
+ But that's hell too. Doing it once, and when I need another one, generating a new one - and it's not sure if this is working well at this time?
9
+
10
+ That is why this gem comes along. Drop it in your Rails app. Add some lines of configuration. Add the helper to the view. Done.
11
+
12
+ ### Installation
13
+
14
+ ```ruby
15
+ gem 'paypal-subscribe', :git => "git@github.com:dsci/paypal-subscribe.git"
16
+ ```
17
+
18
+ to your Gemfile. (It's not released via RubyGems)
19
+
20
+ ### Configuration
21
+
22
+ Add a <code>paypal.rb</code> file in your <code>#{Rails.root}/config/initializers</code>
23
+
24
+ Copy and paste this:
25
+
26
+ ```ruby
27
+ PaypalSubscribe.setup do |config|
28
+
29
+ # Your PayPal ID or an email address associated with your PayPal account.
30
+ # Email addresses must be confirmed.
31
+ config.business = "selle__1343901688_biz@gmail.com"
32
+
33
+ # Do not prompt buyers to include a note with their payments
34
+ config.no_note = true
35
+
36
+ # Description of item being sold. If you are collecting aggregate payments,
37
+ # the value can be a summary of all items purchased, a tracking number, or
38
+ # a generic term such as “subscription.” If this variable is omitted, buyers
39
+ # see a field in which they can enter the item name.
40
+ config.item_name = "Grreeeat Magazine"
41
+
42
+ # Regular subscription price.
43
+ config.a3 = 5.99
44
+
45
+ # Subscription duration. Specify an integer value in
46
+ # the allowable range for the units of duration that you specify with t3.
47
+ config.p3 = 1
48
+
49
+ # Regular subscription units of duration.
50
+ #
51
+ # Allowable values are:
52
+ #
53
+ # D – for days; allowable range for p3 is 1 to 90
54
+ # W – for weeks; allowable range for p3 is 1 to 52
55
+ # M – for months; allowable range for p3 is 1 to 24
56
+ # Y – for years; allowable range for p3 is 1 to 5
57
+ config.t3 = "M"
58
+
59
+ # Recurring payments. Subscription payments recur unless subscribers cancel
60
+ # their subscriptions before the end of the current billing cycle or you
61
+ # limit the number of times that payments recur with the value that you
62
+ # specify for srt.
63
+ #
64
+ # true or false
65
+ config.src = true
66
+
67
+ # Reattempt on failure. If a recurring payment fails, PayPal attempts to
68
+ # collect the payment two more times before canceling the subscription.
69
+ #
70
+ # true or false
71
+ config.sra = true
72
+
73
+ # Recurring times. Number of times that subscription payments recur.
74
+ # Specify an integer with a minimum value of 1 and a maximum value
75
+ # of 52. Valid only if you specify src="1".
76
+ config.srt = 12
77
+
78
+ # Extend config options which ever you want.
79
+ # See
80
+ # https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
81
+ #
82
+ # This has to be a lambda:
83
+ #
84
+ # config.additional_values = ->(config) do
85
+ # config[:modify] = value_for_modify
86
+ #
87
+ # return config
88
+ # end
89
+ # And it has to return the config object!
90
+ #
91
+ # config.additional_values= lambda { |config| }
92
+ end
93
+ ```
94
+
95
+ I added just a few configs which I need and which are required. You can extend the form options by adding a lambda to <code>config.additional_values</code>.
96
+
97
+ Currency defaults to <code>EUR</code>. But is changeable via <code>config.currency_code</code>.
98
+
99
+ See more at [PayPal](https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables)
100
+
101
+ For more informations which options are already included see [here](https://github.com/dsci/paypal-subscribe/blob/master/lib/paypal-subscribe.rb)
102
+
103
+ Open your view and put a helper in it:
104
+
105
+ ```ruby
106
+ <%=paypal_subscribe_button :image => "logo.png", :alt => "Button description"%>
107
+ ```
108
+
109
+ **Note** that image is just a file (name) which should be accessible through the asset pipeline.
110
+
111
+ ## Callbacks
112
+
113
+ The gem provides three default callbacks:
114
+
115
+ * success
116
+ * failure
117
+ * notify
118
+
119
+ To get use of this callbacks you have to define named routes like this.
120
+
121
+ ```ruby
122
+ scope :module => "transactions" do
123
+ match "/paypal/success" => "paypal#paypal_success", :as => :paypal_success
124
+ match "/paypal/failure" => "paypal#paypal_failure", :as => :paypal_failure
125
+ match "/paypal/notify" => "paypal#paypal_notify", :as => :paypal_notify
126
+ end
127
+ ```
128
+
129
+ **paypal-subscribe** default to:
130
+
131
+ * <code>paypal_success</code> on *return*
132
+ * <code>paypal_failure</code> on *cancel_return*
133
+ * <code>paypal_notify</code> on *notify*
134
+
135
+ If you are fine with that, all is done.
136
+
137
+ If you are not fine with that, assign your custom routes within the config block:
138
+
139
+ ```ruby
140
+ config.success_callback = :my_own_success_callback_route
141
+ config.failure_callback = :my_own_failure_callback_route
142
+ config.paypal_notify = :my_own_notify_callback_route
143
+ ```
144
+
145
+ ## Contributing to paypal-subscribe
146
+
147
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
148
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
149
+ * Fork the project.
150
+ * Start a feature/bugfix branch.
151
+ * Commit and push until you are happy with your contribution.
152
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
153
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
154
+
155
+ ## Copyright
156
+
157
+ Copyright (c) 2012 Daniel Schmidt. See LICENSE.txt for
158
+ further details.
159
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "paypal-subscribe"
18
+ gem.homepage = "http://github.com/dsci/paypal-subscribe"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Paypal subscribe button form for Rails.}
21
+ gem.description = %Q{A rails helper to display a PayPal subscribe button.}
22
+ gem.email = "dsci@code79.net"
23
+ gem.authors = ["Daniel Schmidt"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "paypal-subscribe #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,226 @@
1
+ require 'bundler/setup'
2
+
3
+ begin
4
+ Bundler.setup
5
+ rescue
6
+ raise RuntimeError, "Bundler couldn't find some gems." +
7
+ "Did you run 'bundle install'?"
8
+ end
9
+
10
+ require 'active_support/core_ext/module/attribute_accessors'
11
+ require 'paypal-subscribe/action_view/form_helper'
12
+
13
+ module PaypalSubscribe
14
+
15
+ extend self
16
+
17
+ @production_uri = "https://www.paypal.com/cgi-bin/webscr"
18
+ @sandbox_uri = "https://www.sandbox.paypal.com/cgi-bin/webscr"
19
+
20
+ @@paypal_config_hash = {}
21
+
22
+ SHIPPING = {
23
+ :address => 0,
24
+ :none => 1,
25
+ :require_address => 2
26
+ }
27
+
28
+ autoload :Errors, 'paypal-subscribe/errors'
29
+
30
+ # INTERNAL - Form url.
31
+ #
32
+ # For production environment:
33
+ # - https://www.paypal.com/cgi-bin/webscr
34
+ #
35
+ # In any other environment it returns a sandbox link.
36
+ def paypal_url
37
+ if defined?(Rails.env)
38
+ return Rails.env.eql?("production") ? @production_uri : @sandbox_uri
39
+ else
40
+ return @sandbox_uri
41
+ end
42
+ end
43
+
44
+ # Your PayPal ID or an email address associated with your PayPal account.
45
+ # Email addresses must be confirmed.
46
+ mattr_accessor :business
47
+ @@business = "paypal@seller.com"
48
+
49
+ # Description of item being sold. If you are collecting aggregate payments,
50
+ # the value can be a summary of all items purchased, a tracking number, or
51
+ # a generic term such as “subscription.” If this variable is omitted, buyers
52
+ # see a field in which they can enter the item name.
53
+ mattr_accessor :item_name
54
+ @@item_name = "my awesome subscription"
55
+
56
+ # The URL of the 150x50-pixel image displayed as your logo in the upper left
57
+ # corner of the PayPal checkout pages.
58
+
59
+ # Default – Your business name, if you have a PayPal Business account, or your
60
+ # email address, if you have PayPal Premier or Personal account.
61
+ mattr_accessor :image_url
62
+ @@item_name = "my_logo.png"
63
+
64
+ # The paypal return config.
65
+ #
66
+ # The URL to which PayPal redirects buyers’ browser after they complete their payments.
67
+ # For example, specify a URL on your site that displays a “Thank you for your payment” page.
68
+ #
69
+ # Note that you have to define a named route:
70
+ #
71
+ # match '/mypaypal/success' => "transactions/success", :as => :paypal_success
72
+ #
73
+ # :paypal_success is default
74
+ #
75
+ # Paypal returns params like this:
76
+ # {"auth"=>"AwkacusGt-1J7vlbxI88Yi0D-BsC4mxY.lmJw9DtfsqDUnuCWN0O5oYv0gZ7QJO0mVnmAEhdEymQHTAP4skMN0w"}
77
+ mattr_accessor :success_callback
78
+ @@success_callback = :paypal_success
79
+
80
+ # The paypal cancel return config
81
+ #
82
+ # A URL to which PayPal redirects the buyers’ browsers if they cancel checkout before
83
+ # completing their payments. For example, specify a URL on your website that displays
84
+ # a “Payment Canceled” page.
85
+ #
86
+ # Note that you have to define a named route:
87
+ #
88
+ # match '/mypaypal/failure' => "transactions/failure", :as => :paypal_failure
89
+ #
90
+ # :paypal_success is default
91
+ mattr_accessor :failure_callback
92
+ @@failure_callback = :paypal_failure
93
+
94
+ # The Paypal ipn callback config
95
+ #
96
+ # The URL to which PayPal posts information about the payment,
97
+ # in the form of Instant Payment Notification messages.
98
+ #
99
+ # Note that you have define a named route:
100
+ #
101
+ # match '/mypaypal/notification' => 'transaction/notify', :as => :paypal_notify
102
+ #
103
+ # :paypal_notify is default.
104
+ mattr_accessor :notify_callback
105
+ @@notify_callback = :paypal_notify
106
+
107
+ # Regular subscription price.
108
+ mattr_accessor :a3
109
+
110
+ # Regular subscription units of duration.
111
+ #
112
+ # Allowable values are:
113
+ #
114
+ # D – for days; allowable range for p3 is 1 to 90
115
+ # W – for weeks; allowable range for p3 is 1 to 52
116
+ # M – for months; allowable range for p3 is 1 to 24
117
+ # Y – for years; allowable range for p3 is 1 to 5
118
+ mattr_accessor :t3
119
+
120
+ # Subscription duration. Specify an integer value in
121
+ # the allowable range for the units of duration that you specify with t3.
122
+ mattr_accessor :p3
123
+
124
+ # Recurring payments. Subscription payments recur unless subscribers cancel
125
+ # their subscriptions before the end of the current billing cycle or you
126
+ # limit the number of times that payments recur with the value that you
127
+ # specify for srt.
128
+ #
129
+ # true or false
130
+ mattr_reader :src
131
+ def src=(value)
132
+ @@src = no_able(value)
133
+ end
134
+
135
+ # Reattempt on failure. If a recurring payment fails, PayPal attempts to
136
+ # collect the payment two more times before canceling the subscription.
137
+ mattr_reader :sra
138
+ def sra=(value)
139
+ @@sra = no_able(value)
140
+ end
141
+
142
+ # Recurring times. Number of times that subscription payments recur.
143
+ # Specify an integer with a minimum value of 1 and a maximum value
144
+ # of 52. Valid only if you specify src="1".
145
+ mattr_accessor :srt
146
+
147
+ # Do not prompt buyers to include a note with their payments
148
+ mattr_reader :no_note
149
+
150
+ # Do not prompt buyers to include a note with their payments.
151
+ def no_note=(value)
152
+ @@no_note = no_able(value)
153
+ end
154
+
155
+ mattr_reader :no_shipping
156
+
157
+ # Do not prompt buyers for a shipping address.
158
+ #
159
+ # Allowable values are:
160
+ # :address – prompt for an address, but do not require one
161
+ # :none - do not prompt for an address
162
+ # :required_address – prompt for an address, and require one
163
+ def no_shipping=(value)
164
+ @@no_shipping = SHIPPING[value]
165
+ end
166
+
167
+ # Pass-through variable you can use to identify your
168
+ # invoice number for this purchase
169
+ mattr_accessor :invoice
170
+
171
+ # The currency of the payment. Defaults to "EUR"
172
+ mattr_accessor :currency_code
173
+ @@currency_code = "EUR"
174
+
175
+ # Extend config options which ever you want.
176
+ # See
177
+ # https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
178
+ #
179
+ # This has to be a lambda:
180
+ #
181
+ # PaypalSubscribe.additional_values = ->(config) do
182
+ # config[:modify] = value_for_modify
183
+ #
184
+ # return config
185
+ # end
186
+ def additional_values=(method)
187
+ unless method.is_a?(Proc)
188
+ raise Errors::ArgumentError.new("Expected a proc (lambda) as argument.")
189
+ else
190
+ @@paypal_config_hash = method.call(@@paypal_config_hash)
191
+ end
192
+ end
193
+
194
+ # INTERNAL - Builds the form config hash
195
+ #
196
+ # Returns a hash with all config options.
197
+ def paypal_config
198
+ exceptionals = {:success_callback => :return,
199
+ :failure_callback => :cancel_return,
200
+ :notify_callback => :notify_url}
201
+ self.class_variables.each do |c_var|
202
+ key = c_var.to_s.gsub("@@","").to_sym
203
+ unless key.eql?(:paypal_config_hash)
204
+ if exceptionals.keys.include?(key)
205
+ key = exceptionals[key]
206
+ end
207
+ @@paypal_config_hash[key] = self.class_variable_get(c_var)
208
+ end
209
+ end
210
+ return @@paypal_config_hash
211
+ end
212
+
213
+ def setup(&block)
214
+ yield(self)
215
+ end
216
+
217
+ private
218
+
219
+ def no_able(value)
220
+ return case value.class.name
221
+ when "TrueClass" then 1
222
+ when "FalseClass" then 0
223
+ else value
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,72 @@
1
+ require 'active_support/core_ext/array/extract_options'
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module FormTagHelper
6
+ # PUBLIC Rails view helper to generate a PayPal subscription form.
7
+ #
8
+ # Generated output will be something like this:
9
+ #
10
+ # <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
11
+ # <input type="hidden" name="cmd" value="_xclick-subscriptions">
12
+ # <input type="hidden" name="business" value="selle__1343901688_biz@gmail.com">
13
+ # <input type="hidden" name="item_name" value="Baseball Hat Monthly">
14
+ # <input type="hidden" name="image_url" value="https://www.yoursite.com/logo.gif">
15
+ # <input type="hidden" name="no_shipping" value="1">
16
+ # <input type="hidden" name="return" value="http://www.yoursite.com/thankyou.htm">
17
+ # <input type="hidden" name="cancel_return" # value="http://www.yoursite.com/cancel.htm">
18
+ # <input type="hidden" name="a3" value="3.99">
19
+ # <input type="hidden" name="p3" value="1">
20
+ # <input type="hidden" name="t3" value="M">
21
+ # <input type="hidden" name="src" value="1">
22
+ # <input type="hidden" name="sra" value="1">
23
+ # <input type="hidden" name="srt" value="12">
24
+ # <input type="hidden" name="no_note" value="1">
25
+ # <input type="hidden" name="custom" value="customcode">
26
+ # <input type="hidden" name="invoice" value="invoicenumber">
27
+ # <input type="hidden" name="currency_code" value="EUR" >
28
+ # <input type="image" src="http://images.paypal.com/images/x-click-but01.gif" border="0" name="submit" alt="Make payments with PayPal - it’s fast, free and secure!">
29
+ # </form>
30
+ #
31
+ # * args - a list of arguments that includes an options hash:
32
+ # * image - The name of the image which is used within submit button.
33
+ # Note that the image should be just a name which is accesible
34
+ # through the asset pipeline
35
+ # * alt - The alt tag content for the button
36
+ # Other configurations should be made in Rails.root/config/initializers
37
+ #
38
+ # Returns a HTML form.
39
+ def paypal_subscribe_button(*args)
40
+ options = args.extract_options!
41
+ paypal_uri = PaypalSubscribe.paypal_url
42
+ paypal_form = form_tag(paypal_uri, :method => "POST")
43
+
44
+ paypal_form += hidden_field_tag("cmd", "_xclick-subscriptions")
45
+
46
+ config = PaypalSubscribe.paypal_config
47
+ callbacks = []
48
+ callbacks << {:return => config.delete(:return)}
49
+ callbacks << {:cancel_return => config.delete(:cancel_return)}
50
+ callbacks << {:notify_url => config.delete(:notify_url)}
51
+
52
+ config.each_pair do |key,value|
53
+ paypal_form += hidden_field_tag("#{key}", value)
54
+ end
55
+
56
+ callbacks.each do |callback_config|
57
+ callback_config.each_pair do |key,value|
58
+ paypal_form += hidden_field_tag(key,self.send("#{value}_url"))
59
+ end
60
+ end
61
+
62
+ image_source = asset_path(options[:image])
63
+
64
+ paypal_form += image_submit_tag(image_source, :alt => options[:alt], :name => "submit")
65
+
66
+ paypal_form
67
+ end
68
+ alias_method :paypal_subscribe_form,:paypal_subscribe_button
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,8 @@
1
+ module PaypalSubscribe
2
+
3
+ module Errors
4
+
5
+ class ArgumentError < StandardError; end
6
+
7
+ end
8
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "paypal-subscribe"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Daniel Schmidt"]
12
+ s.date = "2012-08-03"
13
+ s.description = "A rails helper to display a PayPal subscribe button."
14
+ s.email = "dsci@code79.net"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/paypal-subscribe.rb",
29
+ "lib/paypal-subscribe/action_view/form_helper.rb",
30
+ "lib/paypal-subscribe/errors.rb",
31
+ "paypal-subscribe.gemspec",
32
+ "spec/paypal-subscribe_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/dsci/paypal-subscribe"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.17"
39
+ s.summary = "Paypal subscribe button form for Rails."
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
46
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
50
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
51
+ s.add_development_dependency(%q<fuubar>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<activesupport>, [">= 0"])
54
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
55
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
58
+ s.add_dependency(%q<simplecov>, [">= 0"])
59
+ s.add_dependency(%q<fuubar>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<activesupport>, [">= 0"])
63
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
67
+ s.add_dependency(%q<simplecov>, [">= 0"])
68
+ s.add_dependency(%q<fuubar>, [">= 0"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,109 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "PaypalSubscribe" do
4
+
5
+ context "configuration section" do
6
+
7
+ subject{PaypalSubscribe}
8
+
9
+ it{should respond_to :paypal_url}
10
+ it{should respond_to :business}
11
+ it{should respond_to :business=}
12
+ it{should respond_to :item_name}
13
+ it{should respond_to :item_name=}
14
+ it{should respond_to :image_url}
15
+ it{should respond_to :image_url=}
16
+ it{should respond_to :success_callback}
17
+ it{should respond_to :success_callback=}
18
+ it{should respond_to :failure_callback}
19
+ it{should respond_to :failure_callback=}
20
+ it{should respond_to :a3}
21
+ it{should respond_to :a3=}
22
+ it{should respond_to :p3}
23
+ it{should respond_to :p3=}
24
+ it{should respond_to :t3}
25
+ it{should respond_to :t3=}
26
+ it{should respond_to :src}
27
+ it{should respond_to :src=}
28
+ it{should respond_to :sra}
29
+ it{should respond_to :sra=}
30
+ it{should respond_to :srt}
31
+ it{should respond_to :srt=}
32
+ it{should respond_to :no_note}
33
+ it{should respond_to :no_note=}
34
+ it{should respond_to :invoice}
35
+ it{should respond_to :invoice=}
36
+ it{should respond_to :currency_code}
37
+ it{should respond_to :currency_code=}
38
+ it{should respond_to :additional_values=}
39
+ it{should respond_to :paypal_config}
40
+ it{should respond_to :no_shipping}
41
+ it{should respond_to :no_shipping=}
42
+
43
+ context "defining additional_values" do
44
+
45
+ it "raises an error if argument is not a Proc" do
46
+ expect do
47
+ PaypalSubscribe.additional_values="sss"
48
+ end.to raise_error(PaypalSubscribe::Errors::ArgumentError,
49
+ "Expected a proc (lambda) as argument.")
50
+ end
51
+
52
+ it "extends the configuration" do
53
+ value_for_modify = 1
54
+ PaypalSubscribe.additional_values = ->(config) do
55
+ config[:modify] = value_for_modify
56
+
57
+ return config
58
+ end
59
+
60
+ configs = PaypalSubscribe.paypal_config
61
+
62
+ configs[:modify].should eq value_for_modify
63
+ end
64
+
65
+ end
66
+
67
+
68
+ end
69
+
70
+ context "configured" do
71
+
72
+ before do
73
+
74
+ PaypalSubscribe.setup do |config|
75
+ config.business = "my@seller.com"
76
+ config.no_note = true
77
+ end
78
+
79
+ end
80
+
81
+ context "getting the config values hash" do
82
+
83
+ subject{PaypalSubscribe.paypal_config}
84
+
85
+ it "business is my@seller.com" do
86
+ subject[:business].should eq "my@seller.com"
87
+ end
88
+
89
+ it "currency_code is 'EUR'" do
90
+ subject[:currency_code].should eq "EUR"
91
+ end
92
+
93
+ it "not note is 1" do
94
+ subject[:no_note].should eq 1
95
+ end
96
+
97
+ it "return is :paypal_success" do
98
+ subject[:return].should eq :paypal_success
99
+ end
100
+
101
+ it "cancel is :paypal_failure" do
102
+ subject[:cancel_return].should eq :paypal_failure
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+
5
+ require 'paypal-subscribe'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paypal-subscribe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Schmidt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70252619067900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70252619067900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70252619067420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70252619067420
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ requirement: &70252619066940 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.12'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70252619066940
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70252619066460 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70252619066460
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70252619065980 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.8.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70252619065980
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &70252619081880 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70252619081880
80
+ - !ruby/object:Gem::Dependency
81
+ name: fuubar
82
+ requirement: &70252619081400 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70252619081400
91
+ description: A rails helper to display a PayPal subscribe button.
92
+ email: dsci@code79.net
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files:
96
+ - LICENSE.txt
97
+ - README.md
98
+ files:
99
+ - .document
100
+ - .rspec
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - VERSION
107
+ - lib/paypal-subscribe.rb
108
+ - lib/paypal-subscribe/action_view/form_helper.rb
109
+ - lib/paypal-subscribe/errors.rb
110
+ - paypal-subscribe.gemspec
111
+ - spec/paypal-subscribe_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: http://github.com/dsci/paypal-subscribe
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: 3296455567913997973
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.17
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Paypal subscribe button form for Rails.
141
+ test_files: []