poundpay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README +0 -0
- data/Rakefile +2 -0
- data/examples/simple_application/.gems +1 -0
- data/examples/simple_application/.rvmrc +3 -0
- data/examples/simple_application/README +8 -0
- data/examples/simple_application/application.rb +65 -0
- data/examples/simple_application/config.rb +11 -0
- data/examples/simple_application/config.ru +6 -0
- data/examples/simple_application/index.html.erb +18 -0
- data/lib/poundpay/formats.rb +14 -0
- data/lib/poundpay/resource.rb +52 -0
- data/lib/poundpay/version.rb +3 -0
- data/lib/poundpay.rb +33 -0
- data/poundpay.gemspec +23 -0
- data/spec/poundpay_spec.rb +34 -0
- metadata +94 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create --install 1.9.2@poundpay >& /dev/null
|
data/Gemfile
ADDED
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rack
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Simple example of PoundPay's REST API.
|
2
|
+
|
3
|
+
The example creates a Rack application that servers one page. In that one
|
4
|
+
page, the user is presented with secure iframe served by PoundPay to pay
|
5
|
+
david@example.com $200 for a pair of Beat by Dr. Dre on our simple marketplace.
|
6
|
+
|
7
|
+
To run the example, run the command `rackup` and visit http://localhost:9292
|
8
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
require 'config'
|
8
|
+
|
9
|
+
|
10
|
+
class PoundPay
|
11
|
+
attr_reader :api_url, :version, :sid, :token
|
12
|
+
|
13
|
+
def initialize(api_url, version, sid, token)
|
14
|
+
@api_url = api_url
|
15
|
+
@version = version
|
16
|
+
@sid = sid
|
17
|
+
@token = token
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(endpoint, params)
|
21
|
+
request_url = "#{@api_url}/#{@version}/#{endpoint}"
|
22
|
+
puts request_url, params
|
23
|
+
uri = URI.parse request_url
|
24
|
+
http = Net::HTTP.new uri.host, uri.port
|
25
|
+
http.use_ssl = true
|
26
|
+
req = Net::HTTP::Post.new uri.request_uri
|
27
|
+
req.set_form_data params
|
28
|
+
req.basic_auth @sid, @token
|
29
|
+
response = http.request req
|
30
|
+
JSON.load response.body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
class SimpleApplication
|
36
|
+
attr_reader :poundpay_client
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
config = SimpleApplication::CONFIG[:poundpay]
|
40
|
+
@poundpay_client = PoundPay.new(config[:api_url], config[:version], config[:sid], config[:token])
|
41
|
+
end
|
42
|
+
|
43
|
+
def call(env)
|
44
|
+
unless env['REQUEST_PATH'] == '/' and env['REQUEST_METHOD'] == 'GET'
|
45
|
+
return [404, {"Content-Type" => "text/plain"}, ["Page Not Found"]]
|
46
|
+
end
|
47
|
+
# Create payment request
|
48
|
+
params = {
|
49
|
+
'amount' => 20000, # In USD cents
|
50
|
+
'payer_fee_amount' => 0,
|
51
|
+
'payer_email_address' => 'goliath@example.com',
|
52
|
+
'recipient_fee_amount' => 500,
|
53
|
+
'recipient_email_address' => 'david@example.com',
|
54
|
+
'description' => 'Beats by Dr. Dre',
|
55
|
+
}
|
56
|
+
payment = @poundpay_client.post 'payments', params
|
57
|
+
puts payment
|
58
|
+
|
59
|
+
# Render and return page
|
60
|
+
www_poundpay_url = SimpleApplication::CONFIG[:poundpay][:www_url]
|
61
|
+
template = ERB.new(open("index.html.erb").read)
|
62
|
+
page = template.result(binding)
|
63
|
+
[200, {"Content-Type" => "text/html"}, [page]]
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class SimpleApplication
|
2
|
+
CONFIG = {
|
3
|
+
poundpay: {
|
4
|
+
api_url: "https://api-sandbox.poundpay.com",
|
5
|
+
www_url: "https://www-sandbox.poundpay.com",
|
6
|
+
version: "silver",
|
7
|
+
sid: "DV8539761e250011e0a81d1231400042c7",
|
8
|
+
token: "5d291d63059f5c2fe8d144820a847982a9fba7004a1009a35ed7a5fdf1f67960",
|
9
|
+
}
|
10
|
+
}
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<html>
|
2
|
+
<title>Simple Marketplace</title>
|
3
|
+
<script src="<%= www_poundpay_url %>/js/poundpay.js"></script>
|
4
|
+
<body>
|
5
|
+
<h1>Simple Marketplace</h1>
|
6
|
+
<h2><%= payment['description'] %></h2>
|
7
|
+
<div id="pound-root"></div>
|
8
|
+
<script type="text/javascript">
|
9
|
+
PoundPay.init({
|
10
|
+
// success: successCallback, // Optional js callback
|
11
|
+
payment_sid: "<%= payment['sid'] %>",
|
12
|
+
server: "<%= www_poundpay_url %>",
|
13
|
+
cardholder_name: "David Stonethrower", // Optional
|
14
|
+
phone_number: "6505551234" // Optional
|
15
|
+
});
|
16
|
+
</script>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_resource/formats/json_format'
|
2
|
+
|
3
|
+
module Poundpay
|
4
|
+
module Formats
|
5
|
+
module UrlencodedJsonFormat
|
6
|
+
extend ActiveResource::Formats::JsonFormat
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def mime_type
|
10
|
+
"application/x-www-form-urlencoded"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'active_resource'
|
3
|
+
require 'poundpay/formats'
|
4
|
+
|
5
|
+
module Poundpay
|
6
|
+
class Resource < ActiveResource::Base
|
7
|
+
self.format = Formats::UrlencodedJsonFormat
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor_with_default(:primary_key, 'sid')
|
11
|
+
|
12
|
+
# Modified default to not use an extension
|
13
|
+
def element_path(id, prefix_options = {}, query_options = nil)
|
14
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
15
|
+
"#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Modified default to not use an extension
|
19
|
+
def new_element_path(prefix_options = {})
|
20
|
+
"#{prefix(prefix_options)}#{collection_name}/new"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Modified default to not use an extension
|
24
|
+
def collection_path(prefix_options = {}, query_options = nil)
|
25
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
26
|
+
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Handle paginated collections
|
30
|
+
def instantiate_collection(collection, prefix_options = {})
|
31
|
+
# TODO: Consume pages
|
32
|
+
collection = collection[collection_name]
|
33
|
+
super(collection, prefix_options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Poundpay accepts urlencoded form parameters
|
38
|
+
# Ideally we should override this functionality in the format, but it's not very straightforward to do so
|
39
|
+
def encode
|
40
|
+
urlencode(@attributes)
|
41
|
+
end
|
42
|
+
|
43
|
+
def collection_name
|
44
|
+
self.class.collection_name
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
def urlencode(params)
|
49
|
+
params.to_a.collect! { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/poundpay.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'poundpay/resource'
|
2
|
+
|
3
|
+
module Poundpay
|
4
|
+
API_URL = "https://api.poundpay.com"
|
5
|
+
VERSION = "silver"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def configure(developer_sid, auth_token, api_url=API_URL, version=VERSION)
|
9
|
+
unless developer_sid.start_with? "DV"
|
10
|
+
raise ArgumentError.new "developer_sid should start with DV. Make sure " \
|
11
|
+
"you're using the right developer_sid"
|
12
|
+
end
|
13
|
+
Resource.site = "#{api_url}/#{version}/"
|
14
|
+
Resource.user = developer_sid
|
15
|
+
Resource.password = auth_token
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Developer < Resource
|
20
|
+
class << self
|
21
|
+
def me
|
22
|
+
find(self.user)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Payment < Resource
|
28
|
+
def release
|
29
|
+
self.status = 'RELEASED'
|
30
|
+
self.save
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/poundpay.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "poundpay/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "poundpay"
|
7
|
+
s.version = Poundpay::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Matin Tamizi"]
|
10
|
+
s.email = "devsupport@poundpay.com"
|
11
|
+
s.homepage = "http://github.com/poundpay/poundpay-ruby"
|
12
|
+
s.summary = %q{Poundpay Ruby library}
|
13
|
+
s.description = %q{Payments platform for marketplaces}
|
14
|
+
|
15
|
+
s.rubyforge_project = "poundpay"
|
16
|
+
|
17
|
+
s.add_dependency("activeresource", ">= 3.0")
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'poundpay'
|
2
|
+
|
3
|
+
describe Poundpay do
|
4
|
+
describe "#configure" do
|
5
|
+
it "should require developer_sid to start with DV" do
|
6
|
+
expect {
|
7
|
+
# Pass developer_sid and auth_token in wrong order
|
8
|
+
Poundpay.configure(
|
9
|
+
"c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
|
10
|
+
"DV0383d447360511e0bbac00264a09ff3c",
|
11
|
+
)
|
12
|
+
}.to raise_error(ArgumentError, /DV/)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be configured with default api_url and version" do
|
16
|
+
developer_sid = "DV0383d447360511e0bbac00264a09ff3c"
|
17
|
+
auth_token = "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a"
|
18
|
+
Poundpay.configure(developer_sid, auth_token)
|
19
|
+
Poundpay::Resource.user.should == developer_sid
|
20
|
+
Poundpay::Resource.password.should == auth_token
|
21
|
+
Poundpay::Resource.site.to_s.should == "https://api.poundpay.com/silver/"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should accept optional api_url and version" do
|
25
|
+
Poundpay.configure(
|
26
|
+
"DV0383d447360511e0bbac00264a09ff3c",
|
27
|
+
"c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
|
28
|
+
api_url="https://api-sandbox.poundpay.com",
|
29
|
+
version="gold",
|
30
|
+
)
|
31
|
+
Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poundpay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Matin Tamizi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-11 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activeresource
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: "3.0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Payments platform for marketplaces
|
35
|
+
email: devsupport@poundpay.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rvmrc
|
45
|
+
- Gemfile
|
46
|
+
- README
|
47
|
+
- Rakefile
|
48
|
+
- examples/simple_application/.gems
|
49
|
+
- examples/simple_application/.rvmrc
|
50
|
+
- examples/simple_application/README
|
51
|
+
- examples/simple_application/application.rb
|
52
|
+
- examples/simple_application/config.rb
|
53
|
+
- examples/simple_application/config.ru
|
54
|
+
- examples/simple_application/index.html.erb
|
55
|
+
- lib/poundpay.rb
|
56
|
+
- lib/poundpay/formats.rb
|
57
|
+
- lib/poundpay/resource.rb
|
58
|
+
- lib/poundpay/version.rb
|
59
|
+
- poundpay.gemspec
|
60
|
+
- spec/poundpay_spec.rb
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/poundpay/poundpay-ruby
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project: poundpay
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Poundpay Ruby library
|
93
|
+
test_files:
|
94
|
+
- spec/poundpay_spec.rb
|