poundpay 0.3.2 → 0.4.0

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/Rakefile CHANGED
@@ -4,4 +4,6 @@ require "rspec/core/rake_task"
4
4
 
5
5
  Bundler::GemHelper.install_tasks
6
6
 
7
- Rspec::Core::RakeTask.new(:spec)
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
@@ -71,7 +71,7 @@ class Payment < SimpleController
71
71
 
72
72
  def authorize request
73
73
  if request.POST['sid'].kind_of?(Array)
74
- payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :status => 'authorized')
74
+ payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :state => 'authorized')
75
75
  payments = payments.collect! {|p| p.schema }
76
76
  return PP.pp(payments, ''), "text/html"
77
77
  else
@@ -85,26 +85,23 @@ class Payment < SimpleController
85
85
  def release request
86
86
  payment = Poundpay::Payment.find(request.POST['sid'])
87
87
  payment.release
88
- payment.save
89
88
  return PP.pp(payment.schema, ''), "text/html"
90
89
  end
91
90
 
92
91
  def cancel request
93
92
  payment = Poundpay::Payment.find(request.POST['sid'])
94
93
  payment.cancel
95
- payment.save
96
94
  return PP.pp(payment.schema, ''), "text/html"
97
95
  end
98
96
 
99
97
  def escrow request
100
98
  if request.POST['sid'].kind_of?(Array)
101
- payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :status => 'escrowed')
99
+ payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :state => 'escrowed')
102
100
  payments = payments.collect! {|p| p.schema }
103
101
  return PP.pp(payments, ''), "text/html"
104
102
  else
105
103
  payment = Poundpay::Payment.find(request.POST['sid'])
106
104
  payment.escrow
107
- payment.save
108
105
  return PP.pp(payment.schema, ''), "text/html"
109
106
  end
110
107
  end
@@ -181,4 +178,4 @@ class ChargePermission < SimpleController
181
178
  return PP.pp(charge_permission.schema, ''), 'text/plain'
182
179
  end
183
180
 
184
- end
181
+ end
@@ -78,40 +78,40 @@ module Poundpay
78
78
  end
79
79
 
80
80
  def authorize
81
- unless status == 'STAGED'
82
- raise PaymentAuthorizeException.new "Payment status is #{status}. Only STAGED payments may be AUTHORIZED."
81
+ unless state == 'CREATED'
82
+ raise PaymentAuthorizeException.new "Payment state is #{state}. Only CREATED payments may be AUTHORIZED."
83
83
  end
84
- attributes['status'] = 'AUTHORIZED'
84
+ attributes['state'] = 'AUTHORIZED'
85
85
  save
86
86
  end
87
87
 
88
88
  def escrow
89
- unless status == 'AUTHORIZED'
90
- raise PaymentEscrowException.new "Payment status is #{status}. Only AUTHORIZED payments may be ESCROWED."
89
+ unless state == 'AUTHORIZED'
90
+ raise PaymentEscrowException.new "Payment state is #{state}. Only AUTHORIZED payments may be ESCROWED."
91
91
  end
92
- attributes['status'] = 'ESCROWED'
92
+ attributes['state'] = 'ESCROWED'
93
93
  save
94
94
  end
95
95
 
96
96
  def release
97
- statuses = ['ESCROWED']
98
- unless statuses.include?(status)
99
- raise PaymentReleaseException.new "Payment status is #{status}. Only ESCROWED payments may be RELEASED."
97
+ states = ['ESCROWED']
98
+ unless states.include?(state)
99
+ raise PaymentReleaseException.new "Payment state is #{state}. Only ESCROWED payments may be RELEASED."
100
100
  end
101
- # Tried setting status with status=, but save still had status == 'ESCROWED'.
102
- # Setting the status through the attributes, however, does work.
103
- attributes['status'] = 'RELEASED'
101
+ # Tried setting state with state=, but save still had state == 'ESCROWED'.
102
+ # Setting the state through the attributes, however, does work.
103
+ attributes['state'] = 'RELEASED'
104
104
  save
105
105
  end
106
106
 
107
107
  def cancel
108
- statuses = ['AUTHORIZED', 'ESCROWED']
109
- unless statuses.include?(status)
110
- raise PaymentCancelException.new "Payment status is #{status}. Only payments with statuses " \
111
- "#{statuses.join(', ')} may be canceled"
108
+ states = ['CREATED', 'AUTHORIZED', 'ESCROWED']
109
+ unless states.include?(state)
110
+ raise PaymentCancelException.new "Payment state is #{state}. Only payments with states " \
111
+ "#{states.join(', ')} may be canceled"
112
112
  end
113
113
 
114
- attributes['status'] = 'CANCELED'
114
+ attributes['state'] = 'CANCELED'
115
115
  save
116
116
  end
117
117
  end
@@ -1,10 +1,16 @@
1
1
  if defined? Rails
2
+ require 'erb'
3
+
2
4
  module Poundpay
3
5
  def self.configure_from_yaml(path)
4
- pathname = Pathname.new Rails.root.join(path)
5
- raise ArgumentError.new "File does not exist: #{pathname.to_s}" unless pathname.exist?
6
- config = YAML::load_file(pathname)[Rails.env]
6
+ pathname = Rails.root.join(path)
7
+ raise ArgumentError, "File does not exist: #{pathname}" unless pathname.exist?
8
+
9
+ config = pathname.read
10
+ config = ERB.new(config).result if pathname.extname == '.erb'
11
+ config = YAML.load(config)[Rails.env]
12
+
7
13
  Poundpay.configure_from_hash(config)
8
14
  end
9
15
  end
10
- end
16
+ end
@@ -7,7 +7,11 @@ module Poundpay
7
7
  self.format = Formats::UrlencodedJsonFormat
8
8
 
9
9
  class << self
10
- attr_accessor_with_default(:primary_key, 'sid')
10
+ attr_writer :primary_key
11
+
12
+ def primary_key
13
+ @primary_key ||= 'sid'
14
+ end
11
15
 
12
16
  # Modified default to not use an extension
13
17
  def element_path(id, prefix_options = {}, query_options = nil)
@@ -41,9 +45,9 @@ module Poundpay
41
45
  end
42
46
 
43
47
  protected
44
- def remove_extension(path)
45
- path.sub /(\.#{format.extension})/, ""
46
- end
48
+ def remove_extension(path)
49
+ path.sub /(\.#{format.extension})/, ""
50
+ end
47
51
  end
48
52
 
49
53
  # Poundpay accepts urlencoded form parameters
@@ -57,14 +61,14 @@ module Poundpay
57
61
  end
58
62
 
59
63
  protected
60
- def self.urlencode(params)
61
- params.to_a.collect! { |k, v|
62
- if v.kind_of?(Array)
63
- v.collect! { |x| "#{k}=#{CGI.escape(x.to_s)}"}.join("&")
64
- else
65
- "#{k}=#{CGI.escape(v.to_s)}"
66
- end
67
- }.join("&")
64
+ def self.urlencode(params)
65
+ params.to_a.collect! { |k, v|
66
+ if v.kind_of?(Array)
67
+ v.collect! { |x| "#{k}=#{CGI.escape(x.to_s)}" }.join("&")
68
+ else
69
+ "#{k}=#{CGI.escape(v.to_s)}"
68
70
  end
71
+ }.join("&")
72
+ end
69
73
  end
70
- end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module Poundpay
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -14,9 +14,9 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "poundpay"
16
16
 
17
- s.add_dependency("activeresource", "~> 3.0.0")
17
+ s.add_dependency("activeresource", "~> 3.1")
18
18
 
19
- s.add_development_dependency("rspec", ">= 2.0")
19
+ s.add_development_dependency("rspec", "~> 2.0")
20
20
  s.add_development_dependency("wirble")
21
21
 
22
22
  s.files = `git ls-files`.split("\n")
@@ -1,6 +1,6 @@
1
1
  module Poundpay
2
2
  module PaymentFixture
3
- def staged_payment_attributes
3
+ def created_payment_attributes
4
4
  {
5
5
  "amount" => 20000,
6
6
  "payer_fee_amount" => 0,
@@ -9,7 +9,7 @@ module Poundpay
9
9
  "recipient_email_address" => "david@example.com",
10
10
  "description" => "Beats by Dr. Dre",
11
11
  "sid" => "PY1d82752a361211e0bce31231400042c7",
12
- "status" => "STAGED",
12
+ "state" => "CREATED",
13
13
  "amount_to_credit_developer" => 550,
14
14
  "updated_at" => "2011-02-11T19:07:05.332356Z",
15
15
  "recipient_sid" => nil,
@@ -23,26 +23,26 @@ module Poundpay
23
23
  end
24
24
 
25
25
  def authorized_payment_attributes
26
- @attributes = staged_payment_attributes
27
- @attributes["status"] = "AUTHORIZED"
26
+ @attributes = created_payment_attributes
27
+ @attributes["state"] = "AUTHORIZED"
28
28
  @attributes
29
29
  end
30
30
 
31
31
  def escrowed_payment_attributes
32
- @attributes = staged_payment_attributes
33
- @attributes["status"] = "ESCROWED"
32
+ @attributes = created_payment_attributes
33
+ @attributes["state"] = "ESCROWED"
34
34
  @attributes
35
35
  end
36
36
 
37
37
  def released_payment_attributes
38
- @attributes = staged_payment_attributes
39
- @attributes["status"] = "RELEASED"
38
+ @attributes = created_payment_attributes
39
+ @attributes["state"] = "RELEASED"
40
40
  @attributes
41
41
  end
42
42
 
43
43
  def canceled_payment_attributes
44
- @attributes = staged_payment_attributes
45
- @attributes["status"] = "CANCELED"
44
+ @attributes = created_payment_attributes
45
+ @attributes["state"] = "CANCELED"
46
46
  @attributes
47
47
  end
48
48
  end
@@ -16,5 +16,5 @@ future:
16
16
  api_version: gold
17
17
 
18
18
  invalid:
19
- developer_sid:
20
- auth_token:
19
+ developer_sid:
20
+ auth_token:
@@ -0,0 +1,5 @@
1
+ development:
2
+ developer_sid: DV0383d447360511e0bbac00264a09ff3c
3
+ auth_token: <%= 'erb_development_auth_token' %>
4
+ www_url: https://www-sandbox.poundpay.com
5
+ api_url: https://api-sandbox.poundpay.com
@@ -68,24 +68,24 @@ describe Payment do
68
68
  end
69
69
 
70
70
  describe "#authorize" do
71
- it "should not be able to authorize a non STAGED payment" do
72
- @non_staged_payment = Payment.new authorized_payment_attributes
73
- expect {@non_staged_payment.authorize}.to raise_error(PaymentAuthorizeException)
71
+ it "should not be able to authorize a non CREATED payment" do
72
+ @non_created_payment = Payment.new authorized_payment_attributes
73
+ expect {@non_created_payment.authorize}.to raise_error(PaymentAuthorizeException)
74
74
  end
75
75
 
76
- it "should authorize a STAGED payment" do
77
- @staged_payment = Payment.new staged_payment_attributes
78
- @staged_payment.should_receive(:save).and_return(Payment.new authorized_payment_attributes)
76
+ it "should authorize a CREATED payment" do
77
+ @created_payment = Payment.new created_payment_attributes
78
+ @created_payment.should_receive(:save).and_return(Payment.new authorized_payment_attributes)
79
79
 
80
- @staged_payment.authorize
81
- @staged_payment.status.should == 'AUTHORIZED'
80
+ @created_payment.authorize
81
+ @created_payment.state.should == 'AUTHORIZED'
82
82
  end
83
83
  end
84
84
 
85
85
  describe "#escrow" do
86
- it "should not be able to escrow a STAGED payment" do
87
- @staged_payment = Payment.new staged_payment_attributes
88
- expect {@staged_payment.escrow}.to raise_error(PaymentEscrowException)
86
+ it "should not be able to escrow a CREATED payment" do
87
+ @created_payment = Payment.new created_payment_attributes
88
+ expect {@created_payment.escrow}.to raise_error(PaymentEscrowException)
89
89
  end
90
90
 
91
91
  it "should escrow an AUTHORIZED payment" do
@@ -93,14 +93,14 @@ describe Payment do
93
93
  @authorized_payment.should_receive(:save).and_return(Payment.new escrowed_payment_attributes)
94
94
 
95
95
  @authorized_payment.escrow
96
- @authorized_payment.status.should == 'ESCROWED'
96
+ @authorized_payment.state.should == 'ESCROWED'
97
97
  end
98
98
  end
99
99
 
100
100
  describe "#release" do
101
- it "should not be able to release a STAGED payment" do
102
- @staged_payment = Payment.new staged_payment_attributes
103
- expect {@staged_payment.release}.to raise_error(PaymentReleaseException)
101
+ it "should not be able to release a CREATED payment" do
102
+ @created_payment = Payment.new created_payment_attributes
103
+ expect {@created_payment.release}.to raise_error(PaymentReleaseException)
104
104
  end
105
105
 
106
106
  it "should release an ESCROWED payment" do
@@ -108,14 +108,14 @@ describe Payment do
108
108
  @escrowed_payment.should_receive(:save).and_return(Payment.new released_payment_attributes)
109
109
 
110
110
  @escrowed_payment.release
111
- @escrowed_payment.status.should == 'RELEASED'
111
+ @escrowed_payment.state.should == 'RELEASED'
112
112
  end
113
113
  end
114
114
 
115
115
  describe "#cancel" do
116
- it "should not be able to cancel a STAGED payment" do
117
- @staged_payment = Payment.new staged_payment_attributes
118
- expect {@staged_payment.cancel}.to raise_error(PaymentCancelException)
116
+ it "should not be able to cancel a RELEASED payment" do
117
+ @released_payment = Payment.new released_payment_attributes
118
+ expect {@released_payment.cancel}.to raise_error(PaymentCancelException)
119
119
  end
120
120
 
121
121
  it "should cancel an ESCROWED payment" do
@@ -123,7 +123,15 @@ describe Payment do
123
123
  @escrowed_payment.should_receive(:save).and_return(Payment.new canceled_payment_attributes)
124
124
 
125
125
  @escrowed_payment.cancel
126
- @escrowed_payment.status.should == 'CANCELED'
126
+ @escrowed_payment.state.should == 'CANCELED'
127
+ end
128
+
129
+ it "should cancel a CREATED payment" do
130
+ @created_payment = Payment.new created_payment_attributes
131
+ @created_payment.should_receive(:save).and_return(Payment.new canceled_payment_attributes)
132
+
133
+ @created_payment.cancel
134
+ @created_payment.state.should == 'CANCELED'
127
135
  end
128
136
  end
129
137
  end
@@ -2,48 +2,45 @@ require 'poundpay'
2
2
 
3
3
  describe Poundpay do
4
4
  module Rails
5
+ def self.root
6
+ Pathname(File.expand_path("../../fixtures", __FILE__))
7
+ end
8
+
9
+ def self.env
10
+ "development"
11
+ end
12
+ end
13
+
14
+ load File.expand_path("../../../lib/poundpay/rails.rb", __FILE__)
15
+
16
+ before do
17
+ Poundpay.should_not be_configured
5
18
  end
6
19
 
7
- after (:each) do
20
+ after do
8
21
  Poundpay.clear_config!
9
22
  end
10
23
 
11
24
  it "should automatically load config if exists" do
12
- load File.expand_path("../../../lib/poundpay/rails.rb", __FILE__)
25
+ Poundpay.configure_from_yaml "poundpay.yml"
13
26
 
14
- module Rails
15
- def self.root
16
- Pathname(File.expand_path("../../fixtures", __FILE__))
17
- end
18
-
19
- def self.env
20
- "development"
21
- end
22
- end
23
-
24
- Poundpay.configured?.should be_false
25
- Poundpay.configure_from_yaml "config/poundpay.yml"
26
- Poundpay.configured?.should be_true
27
+ Poundpay.should be_configured
27
28
  Poundpay::Resource.password.should == "development_auth_token"
28
29
  end
29
30
 
30
- it "should not do anything if config does not exist" do
31
- load File.expand_path("../../../lib/poundpay/rails.rb", __FILE__)
31
+ it "configures using ERB files to allow ENV variables" do
32
+ Poundpay.configure_from_yaml "poundpay.yml.erb"
32
33
 
33
- module Rails
34
- def self.root
35
- Pathname(File.expand_path("../../fixtures", __FILE__))
36
- end
34
+ Poundpay.should be_configured
35
+ Poundpay::Resource.password.should == "erb_development_auth_token"
36
+ end
37
37
 
38
- def self.env
39
- "development"
40
- end
41
- end
38
+ it "should raise argument error and configure nothing if config does not exist" do
39
+ expect {
40
+ Poundpay.configure_from_yaml "wrong_path"
41
+ }.to raise_error(ArgumentError, /wrong_path/)
42
42
 
43
- Poundpay.configured?.should be_false
44
- expect { Poundpay.configure_from_yaml "wrong_path" }.to raise_error(ArgumentError, /wrong_path/)
45
- Poundpay.configured?.should be_false
46
- Poundpay::Resource.password.should == nil
43
+ Poundpay.should_not be_configured
44
+ Poundpay::Resource.password.should_not be
47
45
  end
48
-
49
- end
46
+ end
metadata CHANGED
@@ -1,55 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: poundpay
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Matin Tamizi
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-03-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: activeresource
16
- requirement: &24260120 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
25
+ requirements:
19
26
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 3.0.0
27
+ - !ruby/object:Gem::Version
28
+ hash: 5
29
+ segments:
30
+ - 3
31
+ - 1
32
+ version: "3.1"
22
33
  type: :runtime
23
- prerelease: false
24
- version_requirements: *24260120
25
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
26
36
  name: rspec
27
- requirement: &24259460 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
28
39
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '2.0'
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 2
46
+ - 0
47
+ version: "2.0"
33
48
  type: :development
34
- prerelease: false
35
- version_requirements: *24259460
36
- - !ruby/object:Gem::Dependency
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
37
51
  name: wirble
38
- requirement: &24259020 !ruby/object:Gem::Requirement
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
39
54
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
44
62
  type: :development
45
- prerelease: false
46
- version_requirements: *24259020
63
+ version_requirements: *id003
47
64
  description: Payments platform for marketplaces
48
65
  email: devsupport@poundpay.com
49
66
  executables: []
67
+
50
68
  extensions: []
69
+
51
70
  extra_rdoc_files: []
52
- files:
71
+
72
+ files:
53
73
  - .autotest
54
74
  - .gitignore
55
75
  - .gitmodules
@@ -79,6 +99,7 @@ files:
79
99
  - spec/fixtures/developers.rb
80
100
  - spec/fixtures/payments.rb
81
101
  - spec/fixtures/poundpay.yml
102
+ - spec/fixtures/poundpay.yml.erb
82
103
  - spec/poundpay/callback_spec.rb
83
104
  - spec/poundpay/elements_spec.rb
84
105
  - spec/poundpay/exceptions_spec.rb
@@ -88,26 +109,36 @@ files:
88
109
  - spec/poundpay_spec.rb
89
110
  homepage: http://github.com/poundpay/poundpay-ruby
90
111
  licenses: []
112
+
91
113
  post_install_message:
92
114
  rdoc_options: []
93
- require_paths:
115
+
116
+ require_paths:
94
117
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
118
+ required_ruby_version: !ruby/object:Gem::Requirement
96
119
  none: false
97
- requirements:
98
- - - ! '>='
99
- - !ruby/object:Gem::Version
100
- version: '0'
101
- required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
128
  none: false
103
- requirements:
104
- - - ! '>='
105
- - !ruby/object:Gem::Version
106
- version: '0'
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
107
136
  requirements: []
137
+
108
138
  rubyforge_project: poundpay
109
139
  rubygems_version: 1.8.10
110
140
  signing_key:
111
141
  specification_version: 3
112
142
  summary: Poundpay Ruby library
113
143
  test_files: []
144
+