simplepay-rails4 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -1
- data/README.md +26 -0
- data/app/helpers/simplepay/rails/simplepay_helper.rb +3 -0
- data/lib/simplepay/service.rb +13 -11
- data/lib/simplepay/support/field.rb +5 -8
- data/lib/simplepay/version.rb +1 -1
- data/test/simplepay/test_service.rb +3 -1
- data/test/test_helper.rb +1 -0
- metadata +1 -2
- data/lib/simplepay/helpers/form_helper.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6b3573c1791b1f46173f7dd12100eda651f875
|
4
|
+
data.tar.gz: 0071f403b025c2d023089f048a76ebcebc8909e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cc107ddac364869a7382fdbeed87886b2722a3f3b8d87393488f2f8884a6dd6002f996a990c791978c859b32507bdd8616df38bad8243b1cefe391eeeae7390
|
7
|
+
data.tar.gz: 3f132ad19a8b4dd747431fb841d1c7742eb6c835487cc44e0563e59c246dd1aa2727501c23e5856f9682c9a3e13ab0dc9a308c2ab9056c01064a39aa5b01e1ce
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simplepay-rails4 (0.4.
|
4
|
+
simplepay-rails4 (0.4.1)
|
5
5
|
nokogiri (~> 1.6)
|
6
6
|
rails (~> 4)
|
7
7
|
|
@@ -36,6 +36,13 @@ GEM
|
|
36
36
|
tzinfo (~> 1.1)
|
37
37
|
arel (5.0.1.20140414130214)
|
38
38
|
builder (3.2.2)
|
39
|
+
columnize (0.8.9)
|
40
|
+
debugger (1.6.8)
|
41
|
+
columnize (>= 0.3.1)
|
42
|
+
debugger-linecache (~> 1.2.0)
|
43
|
+
debugger-ruby_core_source (~> 1.3.5)
|
44
|
+
debugger-linecache (1.2.0)
|
45
|
+
debugger-ruby_core_source (1.3.5)
|
39
46
|
erubis (2.7.0)
|
40
47
|
hike (1.2.3)
|
41
48
|
i18n (0.6.9)
|
@@ -97,6 +104,7 @@ PLATFORMS
|
|
97
104
|
ruby
|
98
105
|
|
99
106
|
DEPENDENCIES
|
107
|
+
debugger
|
100
108
|
minitest-spec-rails
|
101
109
|
mocha
|
102
110
|
rails (~> 4.1.0)
|
data/README.md
CHANGED
@@ -73,6 +73,32 @@ optional. This is done like so:
|
|
73
73
|
}) %>
|
74
74
|
```
|
75
75
|
|
76
|
+
### Custom Submit
|
77
|
+
|
78
|
+
You can add a custom submit button (and indeed custom form elements) using
|
79
|
+
either an attribute or a block (not both)
|
80
|
+
|
81
|
+
```erb
|
82
|
+
<%= simplepay_form_for(:subscription, {
|
83
|
+
:amount => 10.95,
|
84
|
+
:description => "MORE Profit!",
|
85
|
+
:recurring_frequency => "1 month"
|
86
|
+
}, submit_tag('Custom Submit')) %>
|
87
|
+
|
88
|
+
<%# OR #%>
|
89
|
+
|
90
|
+
<%= simplepay_form_for :marketplace,
|
91
|
+
:amount => invoice.total,
|
92
|
+
:description => "Mutual profit!",
|
93
|
+
:recipient_email => 'seller@gmail.com',
|
94
|
+
:fixed_marketplace_fee => 10.00,
|
95
|
+
:variable_marketplace_fee => 5 do %>
|
96
|
+
<div>
|
97
|
+
<%= submit_tag 'Pay With Amazon', class: 'btn btn-primary' %>
|
98
|
+
</div>
|
99
|
+
<% end %>
|
100
|
+
```
|
101
|
+
|
76
102
|
### Marketplace forms
|
77
103
|
|
78
104
|
Amazon Simple Pay Marketplace makes it easy to facilitate payments between
|
@@ -20,6 +20,9 @@ module Simplepay
|
|
20
20
|
#
|
21
21
|
def simplepay_form_for(service_name, attributes = {}, submit_tag = nil)
|
22
22
|
service = get_simplepay_service(service_name)
|
23
|
+
if block_given?
|
24
|
+
submit_tag = capture(&Proc.new)
|
25
|
+
end
|
23
26
|
service.form(attributes, submit_tag).html_safe
|
24
27
|
end
|
25
28
|
|
data/lib/simplepay/service.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'action_view'
|
2
2
|
|
3
3
|
module Simplepay
|
4
4
|
|
@@ -14,6 +14,9 @@ module Simplepay
|
|
14
14
|
# signature:: The validation string, guaranteeing that you are the one generating the request and that the values were not tampered with enroute (automatically generated by the form generators)
|
15
15
|
#
|
16
16
|
class Service
|
17
|
+
include ActionView::Helpers::CaptureHelper
|
18
|
+
include ActionView::Helpers::TagHelper
|
19
|
+
include ActionView::Helpers::FormTagHelper
|
17
20
|
|
18
21
|
# Fully-qualified URL for the production endpoint for the service.
|
19
22
|
ENDPOINT_URL = 'https://authorize.payments.amazon.com/pba/paypipeline'
|
@@ -68,6 +71,7 @@ module Simplepay
|
|
68
71
|
|
69
72
|
end
|
70
73
|
|
74
|
+
attr_accessor :output_buffer
|
71
75
|
|
72
76
|
##
|
73
77
|
# Returns the fields for the service instance.
|
@@ -85,25 +89,23 @@ module Simplepay
|
|
85
89
|
end
|
86
90
|
|
87
91
|
def form(attributes = {}, submit = nil)
|
92
|
+
self.output_buffer = ActionView::OutputBuffer.new
|
88
93
|
set_accessor_fields
|
89
94
|
set_fields(attributes)
|
90
95
|
set_signature
|
91
|
-
content = generate_input_fields
|
92
|
-
|
93
|
-
|
94
|
-
|
96
|
+
content = generate_input_fields
|
97
|
+
content += submit ? submit.to_s : generate_submit_field()
|
98
|
+
content_tag(:form, content.html_safe, method: 'post', action: url)
|
99
|
+
end
|
95
100
|
|
96
101
|
private
|
97
|
-
|
98
|
-
|
102
|
+
|
99
103
|
def generate_input_fields
|
100
104
|
self.fields.collect { |f| f.to_input }.join
|
101
105
|
end
|
102
106
|
|
103
|
-
def generate_submit_field
|
104
|
-
|
105
|
-
options.merge!(:value => self.class.submit_tag) if self.class.submit_tag
|
106
|
-
submit ? submit.to_s : Simplepay::Helpers::FormHelper.tag(:input, options)
|
107
|
+
def generate_submit_field
|
108
|
+
submit_tag(self.class.submit_tag)
|
107
109
|
end
|
108
110
|
|
109
111
|
def set_accessor_fields
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'action_view'
|
2
3
|
|
3
4
|
module Simplepay
|
4
5
|
module Support
|
@@ -8,6 +9,7 @@ module Simplepay
|
|
8
9
|
# form. These fields are often unique to their service.
|
9
10
|
#
|
10
11
|
class Field
|
12
|
+
include ActionView::Helpers::FormTagHelper
|
11
13
|
include Comparable
|
12
14
|
|
13
15
|
ALLOWED_OPTIONS = [:as, :class, :required, :value]
|
@@ -120,15 +122,10 @@ module Simplepay
|
|
120
122
|
end
|
121
123
|
|
122
124
|
|
123
|
-
private
|
124
|
-
|
125
|
+
private
|
125
126
|
|
126
127
|
def html_input_tag #:nodoc:
|
127
|
-
|
128
|
-
:name => service_name,
|
129
|
-
:value => value,
|
130
|
-
:type => 'hidden'
|
131
|
-
})
|
128
|
+
hidden_field_tag(service_name, value)
|
132
129
|
end
|
133
130
|
|
134
131
|
def normalize_options!(options) #:nodoc:
|
@@ -144,4 +141,4 @@ module Simplepay
|
|
144
141
|
end
|
145
142
|
|
146
143
|
end
|
147
|
-
end
|
144
|
+
end
|
data/lib/simplepay/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
require 'rexml/document'
|
3
3
|
require 'simplepay/service'
|
4
|
+
require 'action_view'
|
4
5
|
|
5
6
|
class TestService < Simplepay::Service
|
6
7
|
ENDPOINT_URL = 'http://test.host.url/api'
|
@@ -15,6 +16,7 @@ class TestService < Simplepay::Service
|
|
15
16
|
end
|
16
17
|
|
17
18
|
class Simplepay::TestService < ActiveSupport::TestCase
|
19
|
+
include ActionView::Helpers::FormTagHelper
|
18
20
|
|
19
21
|
context 'Simplepay::Service' do
|
20
22
|
|
@@ -109,7 +111,7 @@ class Simplepay::TestService < ActiveSupport::TestCase
|
|
109
111
|
end
|
110
112
|
|
111
113
|
should 'allow the HTML SUBMIT button to be overridden' do
|
112
|
-
document = REXML::Document.new(@service.form({:required => 'set'},
|
114
|
+
document = REXML::Document.new(@service.form({:required => 'set'}, submit_tag('Send It')))
|
113
115
|
assert_not_nil document.root.elements["input[@type='submit' and @value='Send It']"]
|
114
116
|
end
|
115
117
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplepay-rails4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel E. Bibler
|
@@ -61,7 +61,6 @@ files:
|
|
61
61
|
- lib/simplepay/constants.rb
|
62
62
|
- lib/simplepay/engine.rb
|
63
63
|
- lib/simplepay/errors.rb
|
64
|
-
- lib/simplepay/helpers/form_helper.rb
|
65
64
|
- lib/simplepay/service.rb
|
66
65
|
- lib/simplepay/services/donation.rb
|
67
66
|
- lib/simplepay/services/marketplace.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Simplepay
|
2
|
-
module Helpers
|
3
|
-
|
4
|
-
module FormHelper
|
5
|
-
|
6
|
-
def self.tag(name, options = nil, open = false)
|
7
|
-
"<#{name}#{tag_options(options) if options}" + (open ? ">" : " />")
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.content_tag(name, content, options = nil)
|
11
|
-
tag = "<#{name}#{tag_options(options)}>#{content}</#{name}>"
|
12
|
-
tag = tag.html_safe if tag.respond_to?(:html_safe)
|
13
|
-
tag
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
|
20
|
-
def self.tag_options(options)
|
21
|
-
unless options.blank?
|
22
|
-
attrs = []
|
23
|
-
attrs = options.map { |key, value| %(#{key}="#{value}") }
|
24
|
-
" #{attrs.sort * ' '}" unless attrs.empty?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|