puntopagos 0.1.8 → 0.1.9

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.
@@ -11,8 +11,12 @@ module PuntoPagos
11
11
  def call_api data, path, method, signature, timestamp
12
12
  #hack fix: JSON.unparse doesn't work in Rails 2.3.5; only {}.to_json does..
13
13
  headers = set_headers(signature, timestamp)
14
- api_request_data = JSON.unparse(data) rescue data.to_json
15
- resp = RestClient.method(method).call(@@puntopagos_base_url+path, data.to_json, headers)
14
+ #api_request_data = JSON.unparse(data) rescue data.to_json
15
+ if method == :post
16
+ resp = RestClient.method(method).call(@@puntopagos_base_url+path, data.to_json, headers)
17
+ elsif method == :get
18
+ resp = RestClient.method(method).call(@@puntopagos_base_url+path, headers)
19
+ end
16
20
  JSON.parse(resp)
17
21
  end
18
22
 
@@ -20,7 +20,8 @@ module PuntoPagos
20
20
  message = create_message params["token"], params["trx_id"], params["monto"].to_s, timestamp
21
21
  authorization = Authorization.new(@env)
22
22
  signature = authorization.sign(message)
23
- signature == pp_signature(headers)
23
+ verification = PuntoPagos::Verification.new(@env)
24
+ (signature == pp_signature(headers)) and (verification.verify(params["token"], params["trx_id"], params["monto"].to_s))
24
25
 
25
26
  end
26
27
 
@@ -0,0 +1,43 @@
1
+ module PuntoPagos
2
+
3
+ # Public: This class manage the signing of a message using
4
+ # the secret and api-key defined in puntopagos.yml
5
+ class Verification
6
+ def initialize env = nil
7
+ @env = env
8
+ @@config ||= PuntoPagos::Config.new(env)
9
+ @@function = "transaccion/traer"
10
+ @@path = "transaccion"
11
+ end
12
+
13
+ # Public: Signs a string using the secret and api-key defined in puntopagos.yml
14
+ #
15
+ # string - The String to be signed
16
+ # Returns the signed String.
17
+ def verify token, trx_id, amount
18
+ executioner = PuntoPagos::Executioner.new(@env)
19
+ message = create_message token, trx_id, amount, timestamp
20
+ authorization = PuntoPagos::Authorization.new(@env)
21
+ signature = authorization.sign(message)
22
+
23
+ response = executioner.call_api(nil, @@path, :get, signature, timestamp)
24
+
25
+ valid?(response)
26
+ end
27
+
28
+ def valid? response
29
+ response["respuesta"] == "00"
30
+ end
31
+
32
+ private
33
+
34
+ def get_timestamp
35
+ Time.now.strftime("%a, %d %b %Y %H:%M:%S GMT")
36
+ end
37
+
38
+ def create_message token, trx_id, amount, timestamp
39
+ @@function + "\n" + token + "\n" + trx_id + "\n" + amount + "\n" + timestamp
40
+ end
41
+
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module PuntoPagos
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/puntopagos.rb CHANGED
@@ -4,4 +4,5 @@ require File.join(File.dirname(__FILE__),"puntopagos/executioner")
4
4
  require File.join(File.dirname(__FILE__),"puntopagos/request")
5
5
  require File.join(File.dirname(__FILE__),"puntopagos/response")
6
6
  require File.join(File.dirname(__FILE__),"puntopagos/notification")
7
+ require File.join(File.dirname(__FILE__),"puntopagos/verification")
7
8
  require File.join(File.dirname(__FILE__),"puntopagos/version")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puntopagos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-10 00:00:00.000000000Z
13
+ date: 2012-10-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
- requirement: &2157701700 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,12 @@ dependencies:
22
22
  version: 1.6.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2157701700
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.6.7
26
31
  description: Ruby wrapper for PuntoPagos Payment API
27
32
  email:
28
33
  - imella@acid.cl
@@ -43,6 +48,7 @@ files:
43
48
  - lib/puntopagos/notification.rb
44
49
  - lib/puntopagos/request.rb
45
50
  - lib/puntopagos/response.rb
51
+ - lib/puntopagos/verification.rb
46
52
  - lib/puntopagos/version.rb
47
53
  - puntopagos.gemspec
48
54
  - test/data/webpay_payload.yml
@@ -68,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
74
  version: '0'
69
75
  requirements: []
70
76
  rubyforge_project:
71
- rubygems_version: 1.8.6
77
+ rubygems_version: 1.8.24
72
78
  signing_key:
73
79
  specification_version: 3
74
80
  summary: Ruby wrapper for PuntoPagos Payment API