paysio 1.0.2 → 1.0.3

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paysio (1.0.1)
4
+ paysio (1.0.2)
5
5
  activesupport
6
6
  oj (> 2)
7
7
  rest-client (~> 1.4)
data/README.rdoc CHANGED
@@ -27,3 +27,8 @@
27
27
  == Actions: refund charge
28
28
  charge = Paysio::Charge.find("ch_1111111")
29
29
  charge.refund
30
+
31
+
32
+ == Actions: redirect to charge after create (e.g. in Ruby on Rails)
33
+ charge = Paysio::Charge.create(amount: 100, payment_system_id: 'test', description: 'test charge')
34
+ redirect_to charge.redirect_url
data/lib/paysio/client.rb CHANGED
@@ -2,6 +2,9 @@ module Paysio
2
2
  class Client
3
3
  class << self
4
4
  def request(method, path, params = {}, headers = {})
5
+ unless Paysio.api_key
6
+ raise Paysio::Errors::NotAuthorized, "Please specify Paysio.api_key"
7
+ end
5
8
  headers = {
6
9
  user_agent: "Pays.io RubyClient/#{Paysio::VERSION}",
7
10
  content_type: 'application/x-www-form-urlencoded'
@@ -27,7 +30,7 @@ module Paysio
27
30
  rescue Oj::ParseError
28
31
  # raise APIError.new("Invalid response object from API: #{body.inspect} (#{code})", code, body)
29
32
  end
30
- Paysio::Resource.build_from(resp)
33
+ Paysio::Resource.build_from(resp, response.headers[:location])
31
34
  end
32
35
 
33
36
  def execute(opts)
@@ -0,0 +1,7 @@
1
+ module Paysio
2
+ module Errors
3
+ class NotAuthorized < Exception
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Paysio
2
+ module Errors
3
+ class ResourceNotValid < Exception
4
+
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,7 @@
1
1
  module Paysio
2
2
  class Resource
3
+ attr_accessor :redirect_url
4
+
3
5
  def initialize(id = nil)
4
6
  @values = {}
5
7
  @id = id
@@ -68,7 +70,8 @@ module Paysio
68
70
 
69
71
  def validate!(attrs)
70
72
  unless valid?(attrs)
71
- raise "#{self.name} should have following attributes: #{@validate_presence_of.inspect}"
73
+ raise Paysio::Errors::ResourceNotValid,
74
+ "#{self.name} should have following attributes: #{@validate_presence_of.inspect}"
72
75
  end
73
76
  end
74
77
 
@@ -76,7 +79,7 @@ module Paysio
76
79
  "/#{self.name.demodulize.tableize}"
77
80
  end
78
81
 
79
- def build_from(resp)
82
+ def build_from(resp, redirect_url = nil)
80
83
  case resp
81
84
  when Array
82
85
  resp.map { |values| build_from(values) }
@@ -88,6 +91,7 @@ module Paysio
88
91
  end
89
92
  resource = klass.new(resp['id'])
90
93
  resource.refresh_from(resp)
94
+ resource.redirect_url = redirect_url
91
95
  resource
92
96
  else
93
97
  resp
@@ -1,3 +1,3 @@
1
1
  module Paysio
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
data/lib/paysio.rb CHANGED
@@ -17,6 +17,10 @@ require 'paysio/actions/update'
17
17
  require 'paysio/actions/destroy'
18
18
  require 'paysio/actions/find'
19
19
 
20
+ # errors
21
+ require 'paysio/errors/not_authorized'
22
+ require 'paysio/errors/resource_not_valid'
23
+
20
24
  # resources
21
25
  require 'paysio/resources/list'
22
26
  require 'paysio/resources/charge'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paysio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -101,6 +101,8 @@ files:
101
101
  - lib/paysio/actions/list.rb
102
102
  - lib/paysio/actions/update.rb
103
103
  - lib/paysio/client.rb
104
+ - lib/paysio/errors/not_authorized.rb
105
+ - lib/paysio/errors/resource_not_valid.rb
104
106
  - lib/paysio/json.rb
105
107
  - lib/paysio/resource.rb
106
108
  - lib/paysio/resources/charge.rb