puntopagos 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in puntopagos.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ignacio Mella & Gert Findel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,71 @@
1
+ h1. PuntoPagos
2
+
3
+ This development is in a very early stage, please use it at your own risk and feel free to improve it and send Pull Requests.
4
+
5
+ h2. Installation
6
+
7
+ If your are using a Gemfile add the following line and run the bundle command.
8
+
9
+ <pre>
10
+ gem "puntopagos", :git => 'git://github.com/acidlabs/puntopagos-ruby.git'
11
+ </pre>
12
+
13
+ Create puntopagos.yml to your config folder:
14
+
15
+ <pre>
16
+ development:
17
+ environment: "sandbox"
18
+ puntopagos_key: "YOUR-API-KEY"
19
+ puntopagos_secret: "YOUR-APP-SECRET"
20
+
21
+ test:
22
+ environment: "sandbox"
23
+ puntopagos_key: "YOUR-API-KEY"
24
+ puntopagos_secret: "YOUR-APP-SECRET"
25
+
26
+ production:
27
+ environment: "production"
28
+ puntopagos_key: "YOUR-API-KEY"
29
+ puntopagos_secret: "YOUR-APP-SECRET"
30
+ </pre>
31
+
32
+ h2. Sample Usage
33
+
34
+ <pre>
35
+
36
+ req = PuntoPagos::Request.new
37
+ data = {
38
+ 'trx_id' => 'UNIQUE-TRACKING-ID',
39
+ 'monto' => '1000.00'
40
+ #other gateway-specific parameter
41
+ }
42
+
43
+ resp = req.create(data)
44
+ if (resp.success?)
45
+ redirect_to resp.payment_process_url
46
+ end
47
+
48
+ </pre>
49
+
50
+
51
+ h2. Test Data
52
+
53
+ |Gateway|Payload|Expected Result|
54
+ |Transbank|Visa / 4051885600446623 / CVV: 123 / exp: any|Success|
55
+ |Transbank|Mastercard / 5186059559590568 / CVV: 123 / exp: any|Failure|
56
+
57
+ h2. TODO
58
+
59
+ * Config testing
60
+ * Response testing
61
+ * Functional testing
62
+ * Documentation
63
+
64
+ h2. Credits
65
+
66
+ Ignacio Mella & Gert Findel
67
+
68
+ h2. Special Thanks
69
+
70
+ Thanks to dvinales for not suing us.
71
+
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ task :default => :test
9
+
10
+ task :test => %w(test:units)
11
+ namespace :test do
12
+ desc "run unit tests"
13
+ Rake::TestTask.new(:units) do |test|
14
+ test.libs << 'lib' << 'test'
15
+ test.test_files = FileList["test/unit/*_test.rb", "test/unit/*/*_test.rb"]
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ test:
2
+ environment: "sandbox"
3
+ puntopagos_key: "YOUR_API_KEY"
4
+ puntopagos_secret: "YOUR_API_SECRET"
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'puntopagos'
@@ -0,0 +1,32 @@
1
+ require 'yaml'
2
+
3
+ module PuntoPagos
4
+ class Config
5
+ PUNTOPAGOS_BASE_URL = {
6
+ :production => "https://www.puntopagos.com",
7
+ :sandbox => "https://sandbox.puntopagos.com"
8
+ }
9
+
10
+ attr_accessor :config_filepath, :puntopagos_base_url, :puntopagos_key, :puntopagos_secret
11
+
12
+ def initialize(env = nil, config_override = nil)
13
+ if env
14
+ # For non-rails apps
15
+ @config_filepath = File.join(File.dirname(__FILE__), "..", "..", "config", "puntopagos.yml")
16
+ load(env)
17
+ else
18
+ @config_filepath = File.join(Rails.root, "config", "puntopagos.yml")
19
+ load(Rails.env)
20
+ end
21
+ end
22
+
23
+ def load(rails_env)
24
+ config = YAML.load_file(@config_filepath)[rails_env]
25
+ pp_env = config['environment'].to_sym
26
+ @puntopagos_base_url = PUNTOPAGOS_BASE_URL[pp_env]
27
+ @puntopagos_key = config['puntopagos_key']
28
+ @puntopagos_secret = config['puntopagos_secret']
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,63 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+ require 'json'
4
+ require 'rest_client'
5
+
6
+
7
+ module PuntoPagos
8
+
9
+ class NoDataError < Exception
10
+ end
11
+
12
+ class Request
13
+
14
+ def initialize(env = nil)
15
+ @env = env
16
+ @@config ||= PuntoPagos::Config.new(@env)
17
+ @@puntopagos_base_url ||= @@config.puntopagos_base_url
18
+ end
19
+
20
+ def validate
21
+ #TODO validate JSON must have monto and trx_id
22
+ end
23
+
24
+ def create(data)
25
+ raise NoDataError unless data
26
+ get_headers("transaccion/crear",data)
27
+ response_data = call_api(data, "/TransactionService/crear", :post)
28
+ PuntoPagos::Response.new(response_data, @env)
29
+ end
30
+
31
+
32
+
33
+ private
34
+
35
+ def get_headers(function, data)
36
+ raise NoDataError unless data
37
+
38
+ timestamp = Time.now.strftime("%a, %d %b %Y %H:%M:%S GMT")
39
+ message = function+"\n"+data['trx_id'].to_s+"\n"+data['monto'].to_s+"\n"+timestamp
40
+ signature = "PP "+@@config.puntopagos_key+":"+sign(message).chomp!
41
+ @@headers = {
42
+ 'User-Agent' => "puntopagos-ruby-#{PuntoPagos::VERSION}",
43
+ 'Accept' => 'application/json',
44
+ 'Accept-Charset' => 'utf-8',
45
+ 'Content-Type' => 'application/json; charset=utf-8',
46
+ 'Fecha' => timestamp,
47
+ 'Autorizacion' => signature
48
+ }
49
+ end
50
+
51
+ def call_api(data, path, method)
52
+ #hack fix: JSON.unparse doesn't work in Rails 2.3.5; only {}.to_json does..
53
+ api_request_data = JSON.unparse(data) rescue data.to_json
54
+ resp = RestClient.method(method).call(@@puntopagos_base_url+path, data.to_json, @@headers)
55
+
56
+ JSON.parse(resp)
57
+ end
58
+
59
+ def sign(string)
60
+ Base64.encode64(OpenSSL::HMAC.digest('sha1',@@config.puntopagos_secret, string))
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,28 @@
1
+ module PuntoPagos
2
+ class Response
3
+ def initialize(response, env = nil)
4
+ @@config ||= PuntoPagos::Config.new(env)
5
+ @@puntopagos_base_url ||= @@config.puntopagos_base_url
6
+ @@response = response
7
+
8
+ end
9
+
10
+ # TODO validate JSON
11
+ def success?
12
+ @@response["respuesta"] == "00"
13
+ end
14
+
15
+ def get_token
16
+ @@response["token"]
17
+ end
18
+
19
+ def get_error
20
+ @@response["error"]
21
+ end
22
+
23
+ def payment_process_url
24
+ @@puntopagos_base_url + "/transaccion/procesar/"+get_token
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module PuntoPagos
2
+ VERSION = "0.0.1"
3
+ end
data/lib/puntopagos.rb ADDED
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__),"puntopagos/config")
2
+ require File.join(File.dirname(__FILE__),"puntopagos/request")
3
+ require File.join(File.dirname(__FILE__),"puntopagos/response")
4
+ require File.join(File.dirname(__FILE__),"puntopagos/version")
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "puntopagos/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'puntopagos'
7
+ s.version = PuntoPagos::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ignacio Mella", "Gert Findel"]
10
+ s.email = ["imella@acid.cl"]
11
+ s.homepage = %q{https://github.com/acidcl/puntopagos-ruby}
12
+ s.summary = %q{Ruby wrapper for PuntoPagos Payment API}
13
+ s.description = %q{Ruby wrapper for PuntoPagos Payment API}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "rest-client"
21
+
22
+
23
+ end
@@ -0,0 +1,14 @@
1
+ webpay:
2
+ success:
3
+ type: VISA
4
+ cc: 4051885600446623
5
+ cvv: 123
6
+ exp_month: 6
7
+ exp_year: 2015
8
+
9
+ failure:
10
+ type: mastercard
11
+ cc: 5186059559590568
12
+ cvv: 123
13
+ exp_month: 6
14
+ exp_year: 2015
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'JSON'
3
+ require 'test/unit'
4
+ require 'puntopagos'
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class CreateRequestTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @req = PuntoPagos::Request.new('test')
8
+ end
9
+
10
+ def test_valid_create
11
+ puts "-------"
12
+ puts "webpay valid"
13
+
14
+ data = {
15
+ "trx_id" => "#{Time.now.to_i}",
16
+ "monto" => "100.00"
17
+ }
18
+ resp = @req.create(data)
19
+
20
+ assert resp.success? == true
21
+
22
+ # payload = YAML.load_file(File.join(File.dirname(__FILE__),"..", "data","webpay_paylaod.yml"))
23
+ end
24
+
25
+ def test_invalid_webpay_pay
26
+ puts "webpay invalid"
27
+
28
+ data = {
29
+ 'trx_id' => "#{Time.now.to_i}"
30
+ }
31
+ resp = @req.create(data)
32
+
33
+ assert resp.success? == false, "Pass"
34
+
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puntopagos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ignacio Mella
9
+ - Gert Findel
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-06-15 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ requirement: &2156982160 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2156982160
26
+ description: Ruby wrapper for PuntoPagos Payment API
27
+ email:
28
+ - imella@acid.cl
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.textile
37
+ - Rakefile
38
+ - config/puntopagos.yml
39
+ - init.rb
40
+ - lib/puntopagos.rb
41
+ - lib/puntopagos/config.rb
42
+ - lib/puntopagos/request.rb
43
+ - lib/puntopagos/response.rb
44
+ - lib/puntopagos/version.rb
45
+ - puntopagos.gemspec
46
+ - test/data/webpay_payload.yml
47
+ - test/test_helper.rb
48
+ - test/unit/create_request_test.rb
49
+ homepage: https://github.com/acidcl/puntopagos-ruby
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.6
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Ruby wrapper for PuntoPagos Payment API
73
+ test_files:
74
+ - test/data/webpay_payload.yml
75
+ - test/test_helper.rb
76
+ - test/unit/create_request_test.rb