puntopagos 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -17,12 +17,10 @@ development:
17
17
  environment: "sandbox"
18
18
  puntopagos_key: "YOUR-API-KEY"
19
19
  puntopagos_secret: "YOUR-APP-SECRET"
20
-
21
20
  test:
22
21
  environment: "sandbox"
23
22
  puntopagos_key: "YOUR-API-KEY"
24
23
  puntopagos_secret: "YOUR-APP-SECRET"
25
-
26
24
  production:
27
25
  environment: "production"
28
26
  puntopagos_key: "YOUR-API-KEY"
@@ -31,18 +29,28 @@ production:
31
29
 
32
30
  h2. Sample Usage
33
31
 
34
- <pre>
35
-
36
- trx_id = 'UNIQUE-TRACKING-ID' # Number as a string
37
- amount = '1000.00' # Number as a string with two decimals
38
- payment_method = 'some number' # Optional parameter (see PuntoPagos documentation)
32
+ h3. Create a Transaction and Redirect to process url
39
33
 
34
+ <pre>
35
+ trx_id = 'UNIQUE-TRACKING-ID' # Number as a string
36
+ amount = '1000.00' # Number as a string with two decimals
37
+ payment_method = 'some number' # Optional parameter (see PuntoPagos documentation)
40
38
  req = PuntoPagos::Request.new()
41
-
42
- resp = req.create(trx_id, amount, payment_method)
39
+ resp = req.create(trx_id, amount, payment_method)
43
40
  if (resp.success?)
44
41
  redirect_to resp.payment_process_url
45
42
  end
43
+ </pre>
44
+
45
+ h3. Verify notification sent by PuntoPagos
46
+
47
+ <pre>
48
+ # Action where PuntoPagos it's gonna post
49
+ def action
50
+ notification = PuntoPagos::Notification.new
51
+ # This methods requires the headers as a hash and the params object as a hash
52
+ notification.valid? headers, params
53
+ end
46
54
 
47
55
  </pre>
48
56
 
@@ -2,11 +2,18 @@ require 'base64'
2
2
  require 'openssl'
3
3
 
4
4
  module PuntoPagos
5
+
6
+ # Public: This class manage the signing of a message using
7
+ # the secret and api-key defined in puntopagos.yml
5
8
  class Authorization
6
9
  def initialize env = nil
7
10
  @@config ||= PuntoPagos::Config.new(env)
8
11
  end
9
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.
10
17
  def sign(string)
11
18
  encoded_string = Base64.encode64(OpenSSL::HMAC.digest('sha1',@@config.puntopagos_secret, string)).chomp
12
19
  "PP "+@@config.puntopagos_key+":"+ encoded_string
@@ -1,6 +1,8 @@
1
1
  require 'yaml'
2
2
 
3
3
  module PuntoPagos
4
+ # Public: Manage configurations variables
5
+ # like production and sandbox URLs and puntopagos.yml config file
4
6
  class Config
5
7
  PUNTOPAGOS_BASE_URL = {
6
8
  :production => "https://www.puntopagos.com/",
@@ -9,6 +11,12 @@ module PuntoPagos
9
11
 
10
12
  attr_accessor :config_filepath, :puntopagos_base_url, :puntopagos_key, :puntopagos_secret
11
13
 
14
+ # Public: Loads the configuration file puntopagos.yml
15
+ # If it's a rails application it will take the file from the config/ directory
16
+ #
17
+ # env - Environment.
18
+ #
19
+ # Returns a Config object.
12
20
  def initialize env = nil, config_override = nil
13
21
  if env
14
22
  # For non-rails apps
@@ -20,6 +28,13 @@ module PuntoPagos
20
28
  end
21
29
  end
22
30
 
31
+ private
32
+
33
+ # Public: Initialize variables based on puntopagos.yml
34
+ #
35
+ # rails_env - Environment.
36
+ #
37
+ # Returns nothing.
23
38
  def load(rails_env)
24
39
  config = YAML.load_file(@config_filepath)[rails_env]
25
40
  pp_env = config['environment'].to_sym
@@ -10,9 +10,9 @@ module PuntoPagos
10
10
 
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
- headers = set_headers(signature, timestamp)
13
+ headers = set_headers(signature, timestamp)
14
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)
15
+ resp = RestClient.method(method).call(@@puntopagos_base_url+path, data.to_json, headers)
16
16
  JSON.parse(resp)
17
17
  end
18
18
 
@@ -20,12 +20,12 @@ module PuntoPagos
20
20
 
21
21
  def set_headers signature, timestamp
22
22
  headers = {
23
- 'User-Agent' => "puntopagos-ruby-#{PuntoPagos::VERSION}",
24
- 'Accept' => 'application/json',
23
+ 'User-Agent' => "puntopagos-ruby-#{PuntoPagos::VERSION}",
24
+ 'Accept' => 'application/json',
25
25
  'Accept-Charset' => 'utf-8',
26
- 'Content-Type' => 'application/json; charset=utf-8',
27
- 'Fecha' => timestamp,
28
- 'Autorizacion' => signature
26
+ 'Content-Type' => 'application/json; charset=utf-8',
27
+ 'Fecha' => timestamp,
28
+ 'Autorizacion' => signature
29
29
  }
30
30
  end
31
31
  end
@@ -1,4 +1,5 @@
1
1
  module PuntoPagos
2
+ # Public: Manages the notification process.
2
3
  class Notification
3
4
  def initialize env = nil
4
5
  @env = env
@@ -6,10 +7,17 @@ module PuntoPagos
6
7
  @@function = "transaccion/notificar"
7
8
  end
8
9
 
10
+ # Public: Validates the message sent by PuntoPagos in the
11
+ # notification process.
12
+ #
13
+ # headers - The headers of the request as a Hash.
14
+ # params - The params Hash.
15
+ #
16
+ # Returns true or false.
9
17
  def valid? headers, params
10
18
  timestamp = get_timestamp headers
11
19
 
12
- message = create_message params["token"], params["trx_id"], params["monto"], timestamp
20
+ message = create_message params["token"], params["trx_id"], params["monto"].to_s, timestamp
13
21
  authorization = Authorization.new(@env)
14
22
  signature = authorization.sign(message)
15
23
  signature == pp_signature(headers)
@@ -18,14 +26,33 @@ module PuntoPagos
18
26
 
19
27
  private
20
28
 
29
+ # Internal: Creates the message to be signed which will be
30
+ # compared against the one that PuntoPagos sends.
31
+ #
32
+ # token - PuntoPagos transaction unique token.
33
+ # trx_id - Your transaction unique id.
34
+ # amount - The transaction amount.
35
+ # timestamp - timestamp
36
+ #
37
+ # Returns a message as a String.
21
38
  def create_message token, trx_id, amount, timestamp
22
39
  @@function + "\n" + token + "\n" + trx_id + "\n" + amount + "\n" + timestamp
23
40
  end
24
41
 
42
+ # Internal: Gets the signature out of the Autorizacion HTTP Header.
43
+ #
44
+ # headers - request headers as a Hash.
45
+ #
46
+ # Returns the Autorizacion HTTP Header value.
25
47
  def pp_signature headers
26
48
  headers['Autorizacion']
27
49
  end
28
50
 
51
+ # Internal: Gets the timestamp out of the Fecha HTTP Header.
52
+ #
53
+ # headers - request headers as a Hash.
54
+ #
55
+ # Returns the Fecha HTTP Header value.
29
56
  def get_timestamp headers
30
57
  headers['Fecha']
31
58
  end
@@ -1,3 +1,3 @@
1
1
  module PuntoPagos
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -4,20 +4,15 @@ require 'test_helper'
4
4
  class CreateRequestTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @req = PuntoPagos::Request.new('production')
7
+ @req = PuntoPagos::Request.new('test')
8
8
  end
9
9
 
10
10
  def test_valid_create
11
11
  puts "-------"
12
12
  puts "webpay valid"
13
13
 
14
- data = {
15
- "trx_id" => "#{Time.now.to_i}",
16
- "monto" => "100.00",
17
- "medio_pago" => "3"
18
- }
19
- resp = @req.create("#{Time.now.to_i}", "100.00")
20
- puts "RESP: #{resp.success?}"
14
+ resp = @req.create("#{Time.now.to_i}", "100.00")
15
+
21
16
  assert resp.success? == true, "Pass"
22
17
 
23
18
  # payload = YAML.load_file(File.join(File.dirname(__FILE__),"..", "data","webpay_paylaod.yml"))
@@ -26,9 +21,6 @@ class CreateRequestTest < Test::Unit::TestCase
26
21
  def test_invalid_webpay_pay
27
22
  puts "webpay invalid"
28
23
 
29
- data = {
30
- 'trx_id' => "#{Time.now.to_i}"
31
- }
32
24
  resp = @req.create("#{Time.now.to_i}","10")
33
25
 
34
26
  assert resp.success? == false
@@ -37,9 +29,9 @@ class CreateRequestTest < Test::Unit::TestCase
37
29
 
38
30
  def test_notification
39
31
  puts "testing notification"
40
- notification = PuntoPagos::Notification.new('production')
41
- headers = {'Fecha' => 'Thu, 14 Jun 2012 22:52:47 GMT', 'Autorizacion' => 'PP rkdXmAGWLHCKdPyyk6ig:qOSavthLY3ElqsRCtxFEl02lL1s='}
42
- params = {'token' => 'M5N1DAE6PALVAF8K', 'monto' => '1000000.00', 'trx_id' => '9787415132'}
32
+ notification = PuntoPagos::Notification.new('test')
33
+ headers = {'Fecha' => 'Thu, 14 Jun 2012 22:52:47 GMT', 'Autorizacion' => 'PP rkdXmAGWLHCKdPyyk6ig:qOSavthLY3ElqsRCtxFEl02lL1s='}
34
+ params = {'token' => 'M5N1DAE6PALVAF8K', 'monto' => '1000000.00', 'trx_id' => '9787415132'}
43
35
  assert notification.valid?(headers, params) == true
44
36
  end
45
37
 
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.4
4
+ version: 0.1.5
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-06-15 00:00:00.000000000Z
13
+ date: 2012-07-10 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
- requirement: &2161561760 !ruby/object:Gem::Requirement
17
+ requirement: &2157206220 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 1.6.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2161561760
25
+ version_requirements: *2157206220
26
26
  description: Ruby wrapper for PuntoPagos Payment API
27
27
  email:
28
28
  - imella@acid.cl