paybox_system 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +20 -0
- data/README.md +176 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/docs/pubkey.pem +6 -0
- data/lib/paybox_system.rb +49 -0
- data/lib/paybox_system/rails/helpers.rb +35 -0
- data/paybox_system.gemspec +69 -0
- data/spec/paybox_system_spec.rb +51 -0
- data/spec/spec_helper.rb +12 -0
- metadata +131 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "rack"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.8.0"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "bundler", "~> 1.0"
|
14
|
+
gem "jeweler", "~> 1.8.3"
|
15
|
+
gem "simplecov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.3)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.6.5)
|
12
|
+
multi_json (1.0.4)
|
13
|
+
rack (1.4.1)
|
14
|
+
rake (0.9.2.2)
|
15
|
+
rdoc (3.12)
|
16
|
+
json (~> 1.4)
|
17
|
+
rspec (2.8.0)
|
18
|
+
rspec-core (~> 2.8.0)
|
19
|
+
rspec-expectations (~> 2.8.0)
|
20
|
+
rspec-mocks (~> 2.8.0)
|
21
|
+
rspec-core (2.8.0)
|
22
|
+
rspec-expectations (2.8.0)
|
23
|
+
diff-lcs (~> 1.1.2)
|
24
|
+
rspec-mocks (2.8.0)
|
25
|
+
simplecov (0.5.4)
|
26
|
+
multi_json (~> 1.0.3)
|
27
|
+
simplecov-html (~> 0.5.3)
|
28
|
+
simplecov-html (0.5.3)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 1.0)
|
35
|
+
jeweler (~> 1.8.3)
|
36
|
+
rack
|
37
|
+
rdoc (~> 3.12)
|
38
|
+
rspec (~> 2.8.0)
|
39
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Nicolas Blanco & Keley Consulting
|
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.md
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
Paybox System for Ruby
|
2
|
+
======================
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/slainer68/paybox_system.png?branch=master)](http://travis-ci.org/slainer68/paybox_system)
|
5
|
+
|
6
|
+
Introduction
|
7
|
+
------------
|
8
|
+
|
9
|
+
This gem is the Ruby implementation of the e-commerce payment gateway Paybox System from [Paybox](http://www.paybox.com).
|
10
|
+
|
11
|
+
This gem is unofficial and is not approved or endorsed by Paybox.
|
12
|
+
|
13
|
+
Please note that Paybox provides several solutions. Depending of the solution you have chosen, you must use different implementations.
|
14
|
+
|
15
|
+
In my humble opinion :
|
16
|
+
|
17
|
+
* For Paybox Direct, use ActiveMerchant and the built-in Paybox Direct gateway
|
18
|
+
* For Paybox Direct Plus, use ActiveMerchant and use the Paybox Direct Plus gateway provided [here](https://github.com/arambert/Paybox-Direct-Plus)
|
19
|
+
* For Paybox System, use this gem.
|
20
|
+
|
21
|
+
IMPORTANT! The default way of using Paybox System is by sending commands to a CGI module.
|
22
|
+
The problem with the CGI is that you have to use the good CGI depending on your architecture, if you upgrade your architecture it may breaks, and moreover on some cloud architecture like Heroku, you are just not allowed to run CGIs...
|
23
|
+
|
24
|
+
Paybox provides also a way to use Paybox System without CGI. This gem use this method, so you can safely use it on any architecture.
|
25
|
+
|
26
|
+
I highly recommend you to contact Paybox by email and tell them you want to use "Paybox System without CGI by calculating the HMAC yourself".
|
27
|
+
|
28
|
+
Paybox System Basics
|
29
|
+
--------------------
|
30
|
+
|
31
|
+
(Do not read this paragraph if you already know how Paybox System works)
|
32
|
+
|
33
|
+
I recommend you to read the Paybox System manual. Please contact Paybox and ask them the PDF manual for "Paybox System without CGI".
|
34
|
+
|
35
|
+
Basically you have to create a HTML form containing some hidden fields. Those fields contains the parameters you have to send to Paybox like your identification, the amount of the transaction, etc.
|
36
|
+
|
37
|
+
The last field contains a cryptographic signature. This signature has to be generated from all the previous fields using a secret key. You can generate the secret key in the administration interface provided by Paybox.
|
38
|
+
|
39
|
+
The signature is used by Paybox to validate that the form has been generated by you and has not been modified by anybody.
|
40
|
+
|
41
|
+
When the user submits the form, it is redirected to Paybox where the payment is eventually made.
|
42
|
+
|
43
|
+
When the payment is made, Paybox sends a callback to your site (Instant Payment Notification) and the user is redirected back to your site.
|
44
|
+
|
45
|
+
When the callback and redirections are made, Paybox sends you a signature in the parameters. You have to verify the signature using the Paybox public cryptographic key (RSA) to be sure that the request has been made by Paybox.
|
46
|
+
|
47
|
+
How to use this gem
|
48
|
+
-------------------
|
49
|
+
|
50
|
+
This gem only depends on the built-in OpenSSL Ruby libs and Rack. You can use it with any Ruby web framework.
|
51
|
+
|
52
|
+
The gem consists of 2 main methods : one to build the parameters you have to send to Paybox, the other to check the integrity of the Paybox response.
|
53
|
+
|
54
|
+
Configuration
|
55
|
+
-------------
|
56
|
+
|
57
|
+
You must initialize a configuration Hash before using the main Base class methods.
|
58
|
+
This configuration Hash must at least contain the secret key in the key :secret_key.
|
59
|
+
|
60
|
+
For example, the test secret key :
|
61
|
+
|
62
|
+
Paybox::System::Base.config = { :secret_key => "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" }
|
63
|
+
|
64
|
+
Building the Paybox parameters
|
65
|
+
------------------------------
|
66
|
+
|
67
|
+
Check the manual for the complete list of all the different parameters you need to send to Paybox.
|
68
|
+
All these parameters are upper-case and begin by `PBX_`, like : `PBX_SITE`.
|
69
|
+
Use the `Paybox::System::Base.hash_form_fields_from` with a hash that contains all the paybox parameters in symbols without `PBX_`, for example :
|
70
|
+
|
71
|
+
Paybox::System::Base.hash_form_fields_from(:site => "XYZ") # => returns { "PBX_SITE" => "XYZ", etc. }
|
72
|
+
|
73
|
+
The returning Hash also contains 3 additional keys : `PBX_HASH` that is always `SHA512`, `PBX_TIME` with the current timestamp (so you don't have to calculate it yourself) and more important, it contains the signature in `PBX_HMAC` based on all the previous parameters and the secret key.
|
74
|
+
|
75
|
+
Real example with the Paybox test parameters :
|
76
|
+
|
77
|
+
Paybox::System::Base.hash_form_fields_from(:site => "1999888", :rang => "32", :identifiant => "107904482",
|
78
|
+
:paybox => "https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi",
|
79
|
+
:backup1 => "https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi",
|
80
|
+
:backup2 => "https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi",
|
81
|
+
:total => "1500",
|
82
|
+
:devise => 978,
|
83
|
+
:cmd => "id cmd 123456",
|
84
|
+
:porteur => "test@paybox.com",
|
85
|
+
:retour => "amount:M;reference:R;autorization:A;error:E;sign:K",
|
86
|
+
:effectue => "http://monsite.com/payment_success",
|
87
|
+
:refuse => "http://monsite.com/payment_refused",
|
88
|
+
:annule => "http://monsite.com/payment_canceled",
|
89
|
+
:repondre_a => "http://monsite.com/payment_callback")
|
90
|
+
|
91
|
+
Use the returned Hash to build the form.
|
92
|
+
|
93
|
+
Verifying the Paybox Response
|
94
|
+
-----------------------------
|
95
|
+
|
96
|
+
When Paybox redirects the user back to your site or makes the callback, you have to check that the request comes from Paybox.
|
97
|
+
Otherwise anybody can send a manually-made request to your server.
|
98
|
+
To do so, you have to verify the signature provided by Paybox in the request.
|
99
|
+
|
100
|
+
You have to get the full request path and separate the parameters and the signature.
|
101
|
+
Then use the `Paybox::System::Base.check_response?` with the parameters string and the signature.
|
102
|
+
If the method returns true, the message integrity is verified, otherwise there is a problem and you should raise an exception.
|
103
|
+
|
104
|
+
For example :
|
105
|
+
|
106
|
+
http://mysite.com/payment_callback?amount=1500&error=00000&reference=id123456&sign=ABCDEFGH123456
|
107
|
+
|
108
|
+
=> The parameters string is : "amount=1500&error=00000&reference=id123456"
|
109
|
+
=> The signature string is : "ABCDEFGH123456"
|
110
|
+
|
111
|
+
=> Paybox::System::Base.check_response?("amount=1500&error=00000&reference=id123456", "ABCDEFGH123456")
|
112
|
+
|
113
|
+
Rails helpers
|
114
|
+
-------------
|
115
|
+
|
116
|
+
If you use Rails 3, you don't have to directly use the Base methods.
|
117
|
+
This gem provides a helper class that contains a view helper to generate the form and a before\_filter to use in controllers to check the integrity of the Paybox response.
|
118
|
+
|
119
|
+
Create an initializer `config/initializers/paybox_system.rb`:
|
120
|
+
|
121
|
+
require "paybox_system/rails/helpers"
|
122
|
+
Paybox::System::Base.config = { secret_key => "YOUR_SECRET_KEY" } # I recommend you to load the key depending of the environment! Connect to the Paybox administration interface to generate the key (see the manual)
|
123
|
+
|
124
|
+
In the view Helper you want to create a paybox form, add:
|
125
|
+
|
126
|
+
include Paybox::System::Rails::Helpers
|
127
|
+
|
128
|
+
|
129
|
+
Then use the `paybox_hidden_fields` helper with the same Hash you may use with the `hash_form_fields_from` method (bellow).
|
130
|
+
|
131
|
+
Example of the view:
|
132
|
+
|
133
|
+
<form method="POST" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
|
134
|
+
<%= paybox_hidden_fields :site => "ABCDEFG", :rang => "01" # , ... See bellow for the Hash you have to create %>
|
135
|
+
</form>
|
136
|
+
|
137
|
+
IMPORTANT! I recommend you to create the form HTML tags in pure HTML and not use form\_tag or form\_for Rails helpers as Paybox will not like the additional fields that Rails adds with these helpers.
|
138
|
+
|
139
|
+
In the controller(s) that contains the action(s) called by Paybox (for example : when a payment is made (IPN) or canceled), to check the integrity of the response, use the `check_paybox_integrity!` before\_filter provided by the module `Paybox::System::Rails::Integrity`.
|
140
|
+
|
141
|
+
class PurchasedProductsController < ApplicationController
|
142
|
+
include Paybox::System::Rails::Integrity
|
143
|
+
|
144
|
+
before_filter :check_paybox_integrity!
|
145
|
+
|
146
|
+
def ipn
|
147
|
+
if params[:error] == "00000"
|
148
|
+
# Yipee, the payment is confirmed!
|
149
|
+
# ...
|
150
|
+
end
|
151
|
+
|
152
|
+
render :text => "OK"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
IMPORTANT! To use the `check_paybox_integrity!` before\_filter you have to tell Paybox to append the signature in a parameter called `sign`.
|
157
|
+
|
158
|
+
So the `PBX_RETOUR` parameter (`:retour` key in the Hash) must finish by : `sign:K`.
|
159
|
+
See the official manual for more information on the `PBX_RETOUR` variable.
|
160
|
+
For example, you may use : `:retour => "amount:M;reference:R;autorization:A;error:E;sign:K"` in the form fields generation method.
|
161
|
+
|
162
|
+
Contributing to Paybox System for Ruby
|
163
|
+
--------------------------------------
|
164
|
+
|
165
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
166
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
167
|
+
* Fork the project.
|
168
|
+
* Start a feature/bugfix branch.
|
169
|
+
* Commit and push until you are happy with your contribution.
|
170
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
171
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
172
|
+
|
173
|
+
Copyright
|
174
|
+
---------
|
175
|
+
|
176
|
+
Copyright (c) 2012 Nicolas Blanco & Keley Consulting. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "paybox_system"
|
18
|
+
gem.homepage = "http://github.com/slainer68/paybox_system"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Paybox System e-commerce gateway Ruby implementation}
|
21
|
+
gem.description = %Q{Paybox System e-commerce gateway Ruby implementation}
|
22
|
+
gem.email = "slainer68@gmail.com"
|
23
|
+
gem.authors = ["Nicolas Blanco"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "paybox_system #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/docs/pubkey.pem
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
-----BEGIN PUBLIC KEY-----
|
2
|
+
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDe+hkicNP7ROHUssGNtHwiT2Ew
|
3
|
+
HFrSk/qwrcq8v5metRtTTFPE/nmzSkRnTs3GMpi57rBdxBBJW5W9cpNyGUh0jNXc
|
4
|
+
VrOSClpD5Ri2hER/GcNrxVRP7RlWOqB1C03q4QYmwjHZ+zlM4OUhCCAtSWflB4wC
|
5
|
+
Ka1g88CjFwRw/PB9kwIDAQAB
|
6
|
+
-----END PUBLIC KEY-----
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "time"
|
2
|
+
require "openssl"
|
3
|
+
require "base64"
|
4
|
+
require "rack"
|
5
|
+
|
6
|
+
module Paybox
|
7
|
+
module System
|
8
|
+
class Base
|
9
|
+
@@config = {}
|
10
|
+
|
11
|
+
def self.config
|
12
|
+
@@config
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config=(new_config)
|
16
|
+
@@config = new_config
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.hash_form_fields_from(options = {})
|
20
|
+
raise StandardError, "missing :secret_key in config Hash" unless @@config[:secret_key]
|
21
|
+
|
22
|
+
formatted_options = Hash[options.map { |k, v| ["PBX_#{k.to_s.upcase}", v] }]
|
23
|
+
formatted_options["PBX_HASH"] = "SHA512"
|
24
|
+
|
25
|
+
date_iso = Time.now.iso8601
|
26
|
+
formatted_options["PBX_TIME"] = date_iso
|
27
|
+
|
28
|
+
base_params_query = formatted_options.to_a.map { |a| a.join("=") }.join("&")
|
29
|
+
|
30
|
+
key = @@config[:secret_key]
|
31
|
+
|
32
|
+
binary_key = [key].pack("H*")
|
33
|
+
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha512'),
|
34
|
+
binary_key, base_params_query).upcase
|
35
|
+
|
36
|
+
formatted_options["PBX_HMAC"] = signature
|
37
|
+
|
38
|
+
formatted_options
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.check_response?(params, sign)
|
42
|
+
digest = OpenSSL::Digest::SHA1.new
|
43
|
+
public_key = OpenSSL::PKey::RSA.new(File.read(File.expand_path(File.dirname(__FILE__) + '/../docs/pubkey.pem')))
|
44
|
+
|
45
|
+
public_key.verify(digest, Base64.decode64(Rack::Utils.unescape(sign)), params)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Paybox
|
2
|
+
module System
|
3
|
+
module Rails
|
4
|
+
module Integrity
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
protected
|
8
|
+
def check_paybox_integrity!
|
9
|
+
raise Error, "Bad response" unless params[:error].present? && params[:sign].present?
|
10
|
+
|
11
|
+
request_fullpath = request.fullpath
|
12
|
+
|
13
|
+
request_params = request_fullpath[request_fullpath.index("?")+1..request_fullpath.index("&sign")-1]
|
14
|
+
request_sign = request_fullpath[request_fullpath.index("&sign")+6..-1]
|
15
|
+
|
16
|
+
raise Error, "Bad Paybox integrity test" unless Paybox::System::Base.check_response?(request_params, request_sign)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Helpers
|
21
|
+
def paybox_hidden_fields(opts = {})
|
22
|
+
out = ""
|
23
|
+
formatted_options = Paybox::System::Base.hash_form_fields_from(opts)
|
24
|
+
|
25
|
+
formatted_options.each do |o, v|
|
26
|
+
out << hidden_field_tag(o, Rack::Utils.escape(v))
|
27
|
+
out << "\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
out.html_safe
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "paybox_system"
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nicolas Blanco"]
|
12
|
+
s.date = "2012-02-16"
|
13
|
+
s.description = "Paybox System e-commerce gateway Ruby implementation"
|
14
|
+
s.email = "slainer68@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".travis.yml",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"docs/pubkey.pem",
|
30
|
+
"lib/paybox_system.rb",
|
31
|
+
"lib/paybox_system/rails/helpers.rb",
|
32
|
+
"paybox_system.gemspec",
|
33
|
+
"spec/paybox_system_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/slainer68/paybox_system"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = "1.8.15"
|
40
|
+
s.summary = "Paybox System e-commerce gateway Ruby implementation"
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
48
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
51
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
54
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
55
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
58
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
63
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
66
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Paybox::System::Base" do
|
4
|
+
subject { Paybox::System::Base }
|
5
|
+
|
6
|
+
describe ".config" do
|
7
|
+
it "has an empty config hash" do
|
8
|
+
subject.config.should be_a(Hash)
|
9
|
+
subject.config.should be_empty
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a setter and getter" do
|
13
|
+
subject.config = { :test => "pipo" }
|
14
|
+
subject.config.should == { :test => "pipo" }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".hash_form_fields_from" do
|
19
|
+
it "raises an exception if no :secret_key in config" do
|
20
|
+
expect { subject.hash_form_fields_from }.to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with :secret_key in config hash" do
|
24
|
+
before(:each) do
|
25
|
+
subject.config = { :secret_key => "ABCDEFGH12345" }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return a formatted hash of Paybox fields" do
|
29
|
+
OpenSSL::HMAC.should_receive(:hexdigest).and_return("abcdefg")
|
30
|
+
h = subject.hash_form_fields_from({ :aaa => "aaa", :bbb => "bbb", :ccc => "ccc" })
|
31
|
+
h.should be_a(Hash)
|
32
|
+
h.keys.should include("PBX_AAA", "PBX_BBB", "PBX_CCC", "PBX_HASH", "PBX_TIME", "PBX_HMAC")
|
33
|
+
|
34
|
+
h["PBX_HASH"].should == "SHA512"
|
35
|
+
h["PBX_HMAC"].should == "ABCDEFG"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".check_response?" do
|
41
|
+
before(:each) do
|
42
|
+
@paybox_response_params = "reference=id%204f3c497294b3026bfa000001&error=00001"
|
43
|
+
@paybox_response_signature = "NuHxwhK%2BENWuXSXeqtGLa2Zezc7ttXvDvCuJa8h4iWXfDSkHCRAYgPazS1Fo%2Fn%2Bk8%2FksD5C6jP0%2Fgf9xQR0JndC0MPKvA6eDeDknEdAsQAriS%2Fk7vjazARAAY1h%2Bt4zROoMVWI8Ph5u%2Bcf6nKuShUOOBuoqyomVphJLKxVMfGtM%3D"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should verify Paybox response integrity" do
|
47
|
+
Paybox::System::Base.should be_check_response(@paybox_response_params, @paybox_response_signature)
|
48
|
+
Paybox::System::Base.should_not be_check_response(@paybox_response_params.upcase, @paybox_response_signature)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'paybox_system'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :rspec
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paybox_system
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicolas Blanco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70174361107940 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70174361107940
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70174361122620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.8.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70174361122620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc
|
38
|
+
requirement: &70174361120800 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.12'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70174361120800
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &70174361118560 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70174361118560
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &70174361116960 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.8.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70174361116960
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: &70174361116200 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70174361116200
|
80
|
+
description: Paybox System e-commerce gateway Ruby implementation
|
81
|
+
email: slainer68@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files:
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- .rspec
|
90
|
+
- .travis.yml
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- docs/pubkey.pem
|
98
|
+
- lib/paybox_system.rb
|
99
|
+
- lib/paybox_system/rails/helpers.rb
|
100
|
+
- paybox_system.gemspec
|
101
|
+
- spec/paybox_system_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: http://github.com/slainer68/paybox_system
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: -2365665651547652987
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.15
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Paybox System e-commerce gateway Ruby implementation
|
131
|
+
test_files: []
|