simplepay 0.1.0 → 0.1.1
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.
- data.tar.gz.sig +0 -0
- data/History.txt +6 -1
- data/Manifest.txt +4 -0
- data/README.rdoc +34 -17
- data/Rakefile +1 -0
- data/lib/simplepay.rb +1 -1
- data/lib/simplepay/constants.rb +16 -0
- data/lib/simplepay/helpers/notification_helper.rb +49 -0
- data/lib/simplepay/helpers/rails_helper.rb +16 -4
- data/lib/simplepay/rails.rb +9 -0
- data/simplepay.gemspec +4 -4
- data/test/simplepay/helpers/test_notifier.rb +32 -0
- data/test/simplepay/services/test_standard.rb +80 -0
- metadata +8 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
== 0.
|
1
|
+
== 0.1.1 2008-12-11
|
2
|
+
|
3
|
+
* Added a NotificationHelper to aid with Amazon IPN validation.
|
4
|
+
* Updated the Rails helper and added more detailed documentation.
|
5
|
+
|
6
|
+
== 0.1.0 2008-12-05
|
2
7
|
|
3
8
|
* Initial release
|
4
9
|
* Supports Amazon Simple Pay Standard and the-soon-to-be-released Subscriptions
|
data/Manifest.txt
CHANGED
@@ -7,7 +7,9 @@ lib/simplepay/authentication.rb
|
|
7
7
|
lib/simplepay/constants.rb
|
8
8
|
lib/simplepay/errors.rb
|
9
9
|
lib/simplepay/helpers/form_helper.rb
|
10
|
+
lib/simplepay/helpers/notification_helper.rb
|
10
11
|
lib/simplepay/helpers/rails_helper.rb
|
12
|
+
lib/simplepay/rails.rb
|
11
13
|
lib/simplepay/service.rb
|
12
14
|
lib/simplepay/services/standard.rb
|
13
15
|
lib/simplepay/services/subscription.rb
|
@@ -24,6 +26,8 @@ script/console
|
|
24
26
|
script/destroy
|
25
27
|
script/generate
|
26
28
|
simplepay.gemspec
|
29
|
+
test/simplepay/helpers/test_notifier.rb
|
30
|
+
test/simplepay/services/test_standard.rb
|
27
31
|
test/simplepay/services/test_subscription.rb
|
28
32
|
test/simplepay/support/test_amount.rb
|
29
33
|
test/simplepay/support/test_billing_frequency.rb
|
data/README.rdoc
CHANGED
@@ -20,27 +20,44 @@ The following services are coming someday (hopefully soon):
|
|
20
20
|
|
21
21
|
== SYNOPSIS:
|
22
22
|
|
23
|
+
Set up the gem requirement in your environment:
|
24
|
+
|
25
|
+
(in config/environment.rb)
|
26
|
+
|
27
|
+
config.gem "simplepay"
|
28
|
+
|
23
29
|
Configure the gem with your Amazon credentials:
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
(in config/initializers/simplepay.rb)
|
32
|
+
|
33
|
+
Simplepay.aws_access_key_id = 'MYAMAZONACCESSKEYID'
|
34
|
+
Simplepay.aws_secret_access_key = 'MYAMAZONSECRETACCESSKEY'
|
35
|
+
Simplepay.account_id = 'ACCOUNTIDFORAMAZONPAYMENTS'
|
36
|
+
|
37
|
+
Then, let Rails know about the Simplepay::Helpers:
|
38
|
+
|
39
|
+
(potentially in app/controllers/application[_controller].rb or really anywhere else)
|
40
|
+
|
41
|
+
require 'simplepay/rails'
|
42
|
+
|
43
|
+
|
44
|
+
=== Generating your Simple Pay forms
|
30
45
|
|
31
46
|
Generally, this library will then be used directly from one (or more) of your
|
32
|
-
views
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
:
|
42
|
-
|
43
|
-
|
47
|
+
views. Depending on the type of Simple Pay service you're using (see
|
48
|
+
Simplepay::Services), some form values will be required, while others may be
|
49
|
+
optional. This is done like so:
|
50
|
+
|
51
|
+
<%= simplepay_form_for(:standard, {
|
52
|
+
:amount => 10.95,
|
53
|
+
:description => "Profit!"
|
54
|
+
}) %>
|
55
|
+
|
56
|
+
<%= simplepay_form_for(:subscription, {
|
57
|
+
:amount => 10.95,
|
58
|
+
:description => "MORE Profit!",
|
59
|
+
:recurring_frequency => "1 month"
|
60
|
+
}) %>
|
44
61
|
|
45
62
|
== REQUIREMENTS:
|
46
63
|
|
data/Rakefile
CHANGED
data/lib/simplepay.rb
CHANGED
data/lib/simplepay/constants.rb
CHANGED
@@ -17,6 +17,22 @@ module Simplepay
|
|
17
17
|
|
18
18
|
Intervals = [Interval::Day, Interval::Week, Interval::Month, Interval::Year]
|
19
19
|
|
20
|
+
module ResponseStatusCode
|
21
|
+
Abandoned = 'A'
|
22
|
+
HtmlError = 'ME'
|
23
|
+
PaymentFailed = 'PF'
|
24
|
+
PaymentInitiated = 'PI'
|
25
|
+
PaymentReserved = 'PR'
|
26
|
+
PaymentSuccessful = 'PS'
|
27
|
+
SystemError = 'SE'
|
28
|
+
SubscriptionFailed = 'SF'
|
29
|
+
SubscriptionSuccessful = 'SS'
|
30
|
+
|
31
|
+
Successful = [PaymentSuccessful, SubscriptionSuccessful]
|
32
|
+
Failure = [Abandoned, HtmlError, PaymentFailed, SystemError, SubscriptionFailed]
|
33
|
+
Pending = [PaymentInitiated, PaymentReserved]
|
34
|
+
end
|
35
|
+
|
20
36
|
module Currency
|
21
37
|
USD = Support::Currency.new('United States Dollar', 'USD', "%0.2f")
|
22
38
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'simplepay/authentication'
|
2
|
+
|
3
|
+
module Simplepay
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
##
|
7
|
+
# Adds a +valid_simplepay_request?+ method to your ActionControllers.
|
8
|
+
#
|
9
|
+
# In order to use this, you should just directly hand your +params+ into
|
10
|
+
# the method:
|
11
|
+
#
|
12
|
+
# class FooController < ApplicationController
|
13
|
+
#
|
14
|
+
# def receive_ipn
|
15
|
+
# if valid_simplepay_request?(params)
|
16
|
+
# ... record something useful ...
|
17
|
+
# else
|
18
|
+
# ... maybe log a bad request? ...
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
module NotificationHelper
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
|
29
|
+
##
|
30
|
+
# Authenticates the incoming request by validating the +signature+
|
31
|
+
# provided.
|
32
|
+
#
|
33
|
+
# (from within your controller)
|
34
|
+
# def receive_ipn
|
35
|
+
# if valid_simplepay_request?(params)
|
36
|
+
# ...
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
def valid_simplepay_request?(request_hash)
|
41
|
+
hash = request_hash.symbolize_keys
|
42
|
+
signature = hash.delete(:signature) || ''
|
43
|
+
Simplepay::Authentication.authentic?(hash, signature)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -3,8 +3,23 @@ require 'action_view/base'
|
|
3
3
|
module Simplepay
|
4
4
|
module Helpers
|
5
5
|
|
6
|
+
##
|
7
|
+
# Adds helpers to your views for generating the correct HTML FORMs and
|
8
|
+
# valid signatures.
|
9
|
+
#
|
6
10
|
module RailsHelper
|
7
11
|
|
12
|
+
##
|
13
|
+
# This is the general interface for generating your Simple Pay service
|
14
|
+
# forms. See Simplepay::Services for available services and information
|
15
|
+
# specific to each.
|
16
|
+
#
|
17
|
+
# === Example
|
18
|
+
#
|
19
|
+
# (in your view)
|
20
|
+
#
|
21
|
+
# <%= simplepay_form_for(:service_name, {:attr => 'foo'}) %>
|
22
|
+
#
|
8
23
|
def simplepay_form_for(service_name, attributes = {})
|
9
24
|
service = get_simplepay_service(service_name)
|
10
25
|
service.form(attributes)
|
@@ -14,7 +29,7 @@ module Simplepay
|
|
14
29
|
private
|
15
30
|
|
16
31
|
|
17
|
-
def get_simplepay_service(name)
|
32
|
+
def get_simplepay_service(name) #:nodoc:
|
18
33
|
service = "Simplepay::Services::#{name.to_s.camelize}".constantize
|
19
34
|
service.new
|
20
35
|
end
|
@@ -23,6 +38,3 @@ module Simplepay
|
|
23
38
|
|
24
39
|
end
|
25
40
|
end
|
26
|
-
|
27
|
-
# Inject helper into Rails ActionView.
|
28
|
-
ActionView::Base.__send__(:include, Simplepay::Helpers::RailsHelper)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'simplepay'
|
2
|
+
require 'simplepay/helpers/rails_helper'
|
3
|
+
require 'simplepay/helpers/notification_helper'
|
4
|
+
|
5
|
+
# Inject helper into Rails ActionView.
|
6
|
+
ActionView::Base.__send__(:include, Simplepay::Helpers::RailsHelper)
|
7
|
+
|
8
|
+
# Inject notification helper into ActionController
|
9
|
+
ActionController::Base.__send__(:include, Simplepay::Helpers::NotificationHelper)
|
data/simplepay.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{simplepay}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nathaniel E. Bibler"]
|
9
9
|
s.cert_chain = ["/Users/nathan/.gem/gem-public_cert.pem"]
|
10
|
-
s.date = %q{2008-12-
|
10
|
+
s.date = %q{2008-12-11}
|
11
11
|
s.description = %q{This gem provides a Rails interface to the Amazon Simple Pay payment service.}
|
12
12
|
s.email = ["gem@nathanielbibler.com"]
|
13
13
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
14
|
-
s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/simplepay.rb", "lib/simplepay/authentication.rb", "lib/simplepay/constants.rb", "lib/simplepay/errors.rb", "lib/simplepay/helpers/form_helper.rb", "lib/simplepay/helpers/rails_helper.rb", "lib/simplepay/service.rb", "lib/simplepay/services/standard.rb", "lib/simplepay/services/subscription.rb", "lib/simplepay/support.rb", "lib/simplepay/support/amount.rb", "lib/simplepay/support/billing_frequency.rb", "lib/simplepay/support/boolean.rb", "lib/simplepay/support/currency.rb", "lib/simplepay/support/epoch.rb", "lib/simplepay/support/field.rb", "lib/simplepay/support/interval.rb", "lib/simplepay/support/subscription_period.rb", "script/console", "script/destroy", "script/generate", "test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
|
14
|
+
s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/simplepay.rb", "lib/simplepay/authentication.rb", "lib/simplepay/constants.rb", "lib/simplepay/errors.rb", "lib/simplepay/helpers/form_helper.rb", "lib/simplepay/helpers/notification_helper.rb", "lib/simplepay/helpers/rails_helper.rb", "lib/simplepay/rails.rb", "lib/simplepay/service.rb", "lib/simplepay/services/standard.rb", "lib/simplepay/services/subscription.rb", "lib/simplepay/support.rb", "lib/simplepay/support/amount.rb", "lib/simplepay/support/billing_frequency.rb", "lib/simplepay/support/boolean.rb", "lib/simplepay/support/currency.rb", "lib/simplepay/support/epoch.rb", "lib/simplepay/support/field.rb", "lib/simplepay/support/interval.rb", "lib/simplepay/support/subscription_period.rb", "script/console", "script/destroy", "script/generate", "simplepay.gemspec", "test/simplepay/helpers/test_notifier.rb", "test/simplepay/services/test_standard.rb", "test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
|
15
15
|
s.has_rdoc = true
|
16
16
|
s.homepage = %q{http://simplepay.rubyforge.org}
|
17
17
|
s.rdoc_options = ["--main", "README.rdoc"]
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.rubygems_version = %q{1.3.1}
|
21
21
|
s.signing_key = %q{/Users/nathan/.gem/gem-private_key.pem}
|
22
22
|
s.summary = %q{This gem provides a Rails interface to the Amazon Simple Pay payment service.}
|
23
|
-
s.test_files = ["test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
|
23
|
+
s.test_files = ["test/simplepay/helpers/test_notifier.rb", "test/simplepay/services/test_standard.rb", "test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
|
24
24
|
|
25
25
|
if s.respond_to? :specification_version then
|
26
26
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require "simplepay/helpers/notification_helper"
|
3
|
+
|
4
|
+
class TestNotificationClass
|
5
|
+
include Simplepay::Helpers::NotificationHelper
|
6
|
+
|
7
|
+
def testing(request_hash = {})
|
8
|
+
valid_simplepay_request?(request_hash)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Simplepay::Helpers::TestNotificationHelper < Test::Unit::TestCase
|
13
|
+
|
14
|
+
context 'Simplepay::Helpers::NotificationHelper' do
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@notifier = TestNotificationClass.new
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'defer to Simplepay::Authentication.authentic?' do
|
21
|
+
Simplepay::Authentication.expects(:authentic?).with({:test => 'testing'}, 'signed').returns(true)
|
22
|
+
assert @notifier.testing({:test => 'testing', :signature => 'signed'})
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'work with string hash keys' do
|
26
|
+
Simplepay::Authentication.expects(:authentic?).with({:test => 'testing'}, 'signed').returns(true)
|
27
|
+
assert @notifier.testing({"test" => 'testing', "signature" => 'signed'})
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require 'simplepay/services/subscription'
|
3
|
+
|
4
|
+
class Simplepay::Services::TestSubscription < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def self.model_class; Simplepay::Services::Standard; end
|
7
|
+
|
8
|
+
context 'Simplepay::Services::Subscription' do
|
9
|
+
|
10
|
+
should_have_service_field :access_key,
|
11
|
+
:as => 'accessKey',
|
12
|
+
:required => true
|
13
|
+
|
14
|
+
should_have_service_field :signature,
|
15
|
+
:as => 'signature',
|
16
|
+
:required => true
|
17
|
+
|
18
|
+
should_have_service_field :account_id,
|
19
|
+
:as => 'amazonPaymentsAccountId',
|
20
|
+
:required => true
|
21
|
+
|
22
|
+
should_have_service_field :description,
|
23
|
+
:as => 'description',
|
24
|
+
:required => true
|
25
|
+
|
26
|
+
should_have_service_field :amount,
|
27
|
+
:as => 'amount',
|
28
|
+
:required => true,
|
29
|
+
:class => Simplepay::Support::Amount
|
30
|
+
|
31
|
+
should_have_service_field :cobranding_style,
|
32
|
+
:as => 'cobrandingStyle',
|
33
|
+
:required => true
|
34
|
+
|
35
|
+
should_have_service_field :reference_id,
|
36
|
+
:as => 'referenceId',
|
37
|
+
:required => false
|
38
|
+
|
39
|
+
should_have_service_field :immediate_return,
|
40
|
+
:as => 'immediateReturn',
|
41
|
+
:required => false,
|
42
|
+
:class => Simplepay::Support::Boolean
|
43
|
+
|
44
|
+
should_have_service_field :collect_shipping_address,
|
45
|
+
:as => 'collectShippingAddress',
|
46
|
+
:required => false,
|
47
|
+
:class => Simplepay::Support::Boolean
|
48
|
+
|
49
|
+
should_have_service_field :process_immediately,
|
50
|
+
:as => 'processImmediate',
|
51
|
+
:required => false,
|
52
|
+
:class => Simplepay::Support::Boolean
|
53
|
+
|
54
|
+
should_have_service_field :return_url,
|
55
|
+
:as => 'returnUrl',
|
56
|
+
:required => false
|
57
|
+
|
58
|
+
should_have_service_field :abandon_url,
|
59
|
+
:as => 'abandonUrl',
|
60
|
+
:required => false
|
61
|
+
|
62
|
+
should_have_service_field :ipn_url,
|
63
|
+
:as => 'ipnUrl',
|
64
|
+
:required => false
|
65
|
+
|
66
|
+
should_have_service_field :variable_marketplace_fee,
|
67
|
+
:as => 'variableMarketplaceFee',
|
68
|
+
:required => false
|
69
|
+
|
70
|
+
should_have_service_field :fixed_marketplace_fee,
|
71
|
+
:as => 'fixedMarketplaceFee',
|
72
|
+
:required => false
|
73
|
+
|
74
|
+
should_have_service_field :donation_widget,
|
75
|
+
:as => 'isDonationWidget',
|
76
|
+
:required => false
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplepay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel E. Bibler
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
DXxToz6dXyCgpN1XYMMB+A==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2008-12-
|
33
|
+
date: 2008-12-11 00:00:00 -05:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -84,7 +84,9 @@ files:
|
|
84
84
|
- lib/simplepay/constants.rb
|
85
85
|
- lib/simplepay/errors.rb
|
86
86
|
- lib/simplepay/helpers/form_helper.rb
|
87
|
+
- lib/simplepay/helpers/notification_helper.rb
|
87
88
|
- lib/simplepay/helpers/rails_helper.rb
|
89
|
+
- lib/simplepay/rails.rb
|
88
90
|
- lib/simplepay/service.rb
|
89
91
|
- lib/simplepay/services/standard.rb
|
90
92
|
- lib/simplepay/services/subscription.rb
|
@@ -101,6 +103,8 @@ files:
|
|
101
103
|
- script/destroy
|
102
104
|
- script/generate
|
103
105
|
- simplepay.gemspec
|
106
|
+
- test/simplepay/helpers/test_notifier.rb
|
107
|
+
- test/simplepay/services/test_standard.rb
|
104
108
|
- test/simplepay/services/test_subscription.rb
|
105
109
|
- test/simplepay/support/test_amount.rb
|
106
110
|
- test/simplepay/support/test_billing_frequency.rb
|
@@ -141,6 +145,8 @@ signing_key:
|
|
141
145
|
specification_version: 2
|
142
146
|
summary: This gem provides a Rails interface to the Amazon Simple Pay payment service.
|
143
147
|
test_files:
|
148
|
+
- test/simplepay/helpers/test_notifier.rb
|
149
|
+
- test/simplepay/services/test_standard.rb
|
144
150
|
- test/simplepay/services/test_subscription.rb
|
145
151
|
- test/simplepay/support/test_amount.rb
|
146
152
|
- test/simplepay/support/test_billing_frequency.rb
|
metadata.gz.sig
CHANGED
Binary file
|