poundpay 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +72 -0
- data/lib/poundpay/callback.rb +36 -0
- data/lib/poundpay/version.rb +1 -1
- data/lib/poundpay.rb +9 -10
- data/poundpay.gemspec +2 -1
- data/spec/fixtures/callback.rb +11 -0
- data/spec/poundpay/callback_spec.rb +37 -0
- metadata +22 -4
- data/README.mkd +0 -61
data/README.rdoc
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
== Poundpay
|
2
|
+
|
3
|
+
Poundpay is payments platform for marketplaces
|
4
|
+
|
5
|
+
|
6
|
+
== Adding Poundpay to Rails
|
7
|
+
|
8
|
+
1. Add the following to your Gemfile
|
9
|
+
|
10
|
+
gem 'poundpay', '~> 0.1.2'
|
11
|
+
|
12
|
+
2. At the command prompt, install the gem with bundler
|
13
|
+
|
14
|
+
bundle install
|
15
|
+
|
16
|
+
3. Add your Poundpay configuration to config/initializers/poundpay.rb
|
17
|
+
|
18
|
+
Poundpay.configure(
|
19
|
+
"DV0383d447360511e0bbac00264a09ff3c", # developer_sid
|
20
|
+
"c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a", # auth_token
|
21
|
+
api_url = "https://api-sandbox.poundpay.com" # Note: Leave out for production
|
22
|
+
)
|
23
|
+
|
24
|
+
4. Protect your callback controller
|
25
|
+
|
26
|
+
before_filter :verify_poundpay_callback
|
27
|
+
|
28
|
+
|
29
|
+
== Creating a payment
|
30
|
+
Adding the payer_sid (from a previous payment), will cause the payer to see
|
31
|
+
the repeat flow when they are not prompted to reenter their credit card information
|
32
|
+
|
33
|
+
@payment = Poundpay::Payment.create(
|
34
|
+
:amount => 20000,
|
35
|
+
:payer_fee_amount => 0,
|
36
|
+
:payer_email_address => "fred@example.com",
|
37
|
+
:payer_sid => "97f51e5c38e211e08625e7af17bae06a", # Optional
|
38
|
+
:recipient_fee_amount => 500,
|
39
|
+
:recipient_email_address => "david@example.com",
|
40
|
+
:description => "Beats by Dr. Dre",
|
41
|
+
)
|
42
|
+
|
43
|
+
|
44
|
+
== Serving IFRAME
|
45
|
+
|
46
|
+
<script src="https://www.poundpay.com/js/poundpay.js"></script>
|
47
|
+
|
48
|
+
<div id="pound-root"></div>
|
49
|
+
|
50
|
+
<script>
|
51
|
+
function handlePaymentSuccess() {
|
52
|
+
// do something
|
53
|
+
}
|
54
|
+
|
55
|
+
function handlePaymentError() {
|
56
|
+
// handle error
|
57
|
+
}
|
58
|
+
|
59
|
+
PoundPay.init({
|
60
|
+
payment_sid: <%= @payment.sid %>,
|
61
|
+
success: handlePaymentSuccess,
|
62
|
+
error: handlePaymentError,
|
63
|
+
cardholder_name: 'Fred Nietzsche', // note: optional
|
64
|
+
phone_number: '4085551234', // note: optional
|
65
|
+
server: 'https://www-sandbox.poundpay.com' // note: exclude this property when in production
|
66
|
+
});
|
67
|
+
</script>
|
68
|
+
|
69
|
+
|
70
|
+
== Releasing a payment
|
71
|
+
|
72
|
+
payment.release
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module Poundpay
|
5
|
+
def self.verified_callback?(signature, params = {})
|
6
|
+
# Make a request to Poundpay for callback_url once
|
7
|
+
@callback_url = Developer.me.callback_url unless @callback_url
|
8
|
+
signature == calculate_signature(@callback_url, params)
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def self.calculate_signature(url, params)
|
13
|
+
data = url
|
14
|
+
@token = Resource.password
|
15
|
+
params.sort.each do |name, value|
|
16
|
+
data += "#{name}#{value}"
|
17
|
+
end
|
18
|
+
digest = OpenSSL::Digest::Digest.new('sha1')
|
19
|
+
Base64.encode64(OpenSSL::HMAC.digest(digest, @token, data)).strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
module ActionController
|
25
|
+
class Base
|
26
|
+
protected
|
27
|
+
def verify_poundpay_callback
|
28
|
+
signature = request.headers['HTTP_X_POUNDPAY_SIGNATURE']
|
29
|
+
Poundpay.verified_callback?(signature, request.POST) || handle_unverified_callback
|
30
|
+
end
|
31
|
+
|
32
|
+
def handle_unverified_callback
|
33
|
+
raise RoutingError.new('Not Found')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/poundpay/version.rb
CHANGED
data/lib/poundpay.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'poundpay/resource'
|
2
2
|
require 'poundpay/elements'
|
3
|
+
require 'poundpay/callback'
|
3
4
|
|
4
5
|
module Poundpay
|
5
6
|
API_URL = "https://api.poundpay.com"
|
6
7
|
API_VERSION = "silver"
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
"you're using the right developer_sid"
|
13
|
-
end
|
14
|
-
api_url.sub! /(\/)$/, "" # Remove trailing backslash
|
15
|
-
Resource.site = "#{api_url}/#{version}/"
|
16
|
-
Resource.user = developer_sid
|
17
|
-
Resource.password = auth_token
|
9
|
+
def self.configure(developer_sid, auth_token, api_url=API_URL, version=API_VERSION)
|
10
|
+
unless developer_sid.start_with? "DV"
|
11
|
+
raise ArgumentError.new "developer_sid should start with 'DV'. Make sure " \
|
12
|
+
"you're using the right developer_sid"
|
18
13
|
end
|
14
|
+
api_url.sub! /(\/)$/, "" # Remove trailing backslash
|
15
|
+
Resource.site = "#{api_url}/#{version}/"
|
16
|
+
Resource.user = developer_sid
|
17
|
+
Resource.password = auth_token
|
19
18
|
end
|
20
19
|
end
|
data/poundpay.gemspec
CHANGED
@@ -17,9 +17,10 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency("activeresource", ">= 3.0")
|
18
18
|
|
19
19
|
s.add_development_dependency("rspec", ">= 2.0")
|
20
|
+
s.add_development_dependency("wirble")
|
20
21
|
|
21
22
|
s.files = `git ls-files`.split("\n")
|
22
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
25
|
s.require_paths = ["lib"]
|
25
|
-
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'poundpay'
|
2
|
+
require 'poundpay/callback'
|
3
|
+
require 'fixtures/callback'
|
4
|
+
|
5
|
+
describe Poundpay do
|
6
|
+
include Poundpay
|
7
|
+
include Poundpay::CallbackFixture
|
8
|
+
|
9
|
+
before (:all) do
|
10
|
+
Poundpay.configure(
|
11
|
+
"DV0383d447360511e0bbac00264a09ff3c",
|
12
|
+
"c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a")
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".calculate_signature" do
|
16
|
+
it "should calculate the correct signature using HMAC-SHA1" do
|
17
|
+
signature = Poundpay.calculate_signature(valid_callback[:url], valid_callback[:params])
|
18
|
+
signature.should == valid_callback[:signature]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".verified_callback?" do
|
23
|
+
before(:all) do
|
24
|
+
@developer = Poundpay::Developer.new :callback_url => valid_callback[:url]
|
25
|
+
Poundpay::Developer.should_receive(:me).and_return(@developer)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should validate a valid callback and only make request for callback_url once" do
|
29
|
+
Poundpay.verified_callback?(valid_callback[:signature], valid_callback[:params]).should == true
|
30
|
+
Poundpay.verified_callback?(valid_callback[:signature], valid_callback[:params]).should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should invalidate an invalid signature" do
|
34
|
+
Poundpay.verified_callback?("invalid signature", valid_callback[:params]).should == false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matin Tamizi
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-15 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -45,6 +45,19 @@ dependencies:
|
|
45
45
|
version: "2.0"
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: wirble
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id003
|
48
61
|
description: Payments platform for marketplaces
|
49
62
|
email: devsupport@poundpay.com
|
50
63
|
executables: []
|
@@ -59,7 +72,7 @@ files:
|
|
59
72
|
- .rspec
|
60
73
|
- .rvmrc
|
61
74
|
- Gemfile
|
62
|
-
- README.
|
75
|
+
- README.rdoc
|
63
76
|
- Rakefile
|
64
77
|
- examples/simple_application/.gems
|
65
78
|
- examples/simple_application/.rvmrc
|
@@ -69,13 +82,16 @@ files:
|
|
69
82
|
- examples/simple_application/config.ru
|
70
83
|
- examples/simple_application/index.html.erb
|
71
84
|
- lib/poundpay.rb
|
85
|
+
- lib/poundpay/callback.rb
|
72
86
|
- lib/poundpay/elements.rb
|
73
87
|
- lib/poundpay/formats.rb
|
74
88
|
- lib/poundpay/resource.rb
|
75
89
|
- lib/poundpay/version.rb
|
76
90
|
- poundpay.gemspec
|
91
|
+
- spec/fixtures/callback.rb
|
77
92
|
- spec/fixtures/developers.rb
|
78
93
|
- spec/fixtures/payments.rb
|
94
|
+
- spec/poundpay/callback_spec.rb
|
79
95
|
- spec/poundpay/elements_spec.rb
|
80
96
|
- spec/poundpay/formats_spec.rb
|
81
97
|
- spec/poundpay/resource_spec.rb
|
@@ -113,8 +129,10 @@ signing_key:
|
|
113
129
|
specification_version: 3
|
114
130
|
summary: Poundpay Ruby library
|
115
131
|
test_files:
|
132
|
+
- spec/fixtures/callback.rb
|
116
133
|
- spec/fixtures/developers.rb
|
117
134
|
- spec/fixtures/payments.rb
|
135
|
+
- spec/poundpay/callback_spec.rb
|
118
136
|
- spec/poundpay/elements_spec.rb
|
119
137
|
- spec/poundpay/formats_spec.rb
|
120
138
|
- spec/poundpay/resource_spec.rb
|
data/README.mkd
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
Poundpay
|
2
|
-
========
|
3
|
-
|
4
|
-
|
5
|
-
Install
|
6
|
-
-------
|
7
|
-
gem install poundpay
|
8
|
-
|
9
|
-
|
10
|
-
Configure
|
11
|
-
---------
|
12
|
-
Poundpay.configure(
|
13
|
-
"developer_sid",
|
14
|
-
"auth_token",
|
15
|
-
api_url = "https://api-sandbox.poundpay.com", # Note: Leave out for production
|
16
|
-
)
|
17
|
-
|
18
|
-
|
19
|
-
Creating a payment
|
20
|
-
------------------
|
21
|
-
require 'poundpay'
|
22
|
-
|
23
|
-
payment = Poundpay::Payment.create(
|
24
|
-
:amount => 20000,
|
25
|
-
:payer_fee_amount => 0,
|
26
|
-
:payer_email_address => "fred@example.com",
|
27
|
-
:recipient_fee_amount => 500,
|
28
|
-
:recipient_email_address => "david@example.com",
|
29
|
-
:description => "Beats by Dr. Dre",
|
30
|
-
)
|
31
|
-
|
32
|
-
Serving iframe
|
33
|
-
---------------
|
34
|
-
<script src="https://www.poundpay.com/js/poundpay.js"></script>
|
35
|
-
|
36
|
-
<div id="pound-root"></div>
|
37
|
-
|
38
|
-
<script>
|
39
|
-
function handlePaymentSuccess() {
|
40
|
-
// do something
|
41
|
-
}
|
42
|
-
|
43
|
-
function handlePaymentError() {
|
44
|
-
// handle error
|
45
|
-
}
|
46
|
-
|
47
|
-
PoundPay.init({
|
48
|
-
payment_sid: <%= payment.sid %>,
|
49
|
-
success: handlePaymentSuccess,
|
50
|
-
error: handlePaymentError,
|
51
|
-
cardholder_name: 'Fred Nietzsche', // note: optional
|
52
|
-
phone_number: '4085551234', // note: optional
|
53
|
-
server: 'https://www-sandbox.poundpay.com' // note: exclude this property when in production
|
54
|
-
});
|
55
|
-
</script>
|
56
|
-
|
57
|
-
|
58
|
-
Releasing a payment
|
59
|
-
------------------
|
60
|
-
payment.release
|
61
|
-
payment.save!
|