rpositivity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README +0 -0
- data/lib/r_positivity.rb +76 -0
- data/spec/r_positivity_spec.rb +102 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Giordano Scalzo <giordano.scalzo@cleancode.it>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
File without changes
|
data/lib/r_positivity.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'date'
|
2
|
+
require "digest/sha1"
|
3
|
+
|
4
|
+
module RPositivity
|
5
|
+
module Currency
|
6
|
+
EURO = "978"
|
7
|
+
end
|
8
|
+
|
9
|
+
module TxnType
|
10
|
+
SALE = "sale"
|
11
|
+
PREAUTH = "preauth"
|
12
|
+
POSTAUTH = "postauth"
|
13
|
+
VOID = "void"
|
14
|
+
end
|
15
|
+
|
16
|
+
module Mode
|
17
|
+
PAYONLY = "payonly"
|
18
|
+
PAYPLUS = "payplus"
|
19
|
+
PAYFULL = "payfull"
|
20
|
+
end
|
21
|
+
|
22
|
+
class RPositivity
|
23
|
+
TEST_URL = "https://test.ipg-online.com/connect/gateway/processing"
|
24
|
+
|
25
|
+
def initialize(storename, sharedSecret, args = {}, &block)
|
26
|
+
@chargetotal = "0.00"
|
27
|
+
@date = DateTime.now
|
28
|
+
@currency = Currency::EURO
|
29
|
+
@storename = storename
|
30
|
+
@sharedSecret = sharedSecret
|
31
|
+
@txntype = args[:txntype] || TxnType::SALE
|
32
|
+
@mode = args[:mode] || Mode::PAYONLY
|
33
|
+
@responseSuccessURL = args[:responseSuccessURL] || ""
|
34
|
+
@responseFailURL = args[:responseFailURL] || ""
|
35
|
+
instance_eval &block if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
def url
|
39
|
+
TEST_URL
|
40
|
+
end
|
41
|
+
|
42
|
+
def for(chargetotal, date = DateTime.now)
|
43
|
+
RPositivity.new(@storename, @sharedSecret,
|
44
|
+
:txntype => @txntype,
|
45
|
+
:mode => @mode,
|
46
|
+
:responseSuccessURL => @responseSuccessURL,
|
47
|
+
:responseFailURL => @responseFailURL) do
|
48
|
+
@chargetotal = "%.2f" % chargetotal
|
49
|
+
@date = date
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def params
|
54
|
+
{
|
55
|
+
:chargetotal => @chargetotal,
|
56
|
+
:storename => @storename,
|
57
|
+
:txndatetime => @date.strftime("%Y:%m:%d-%H:%M:%S"),
|
58
|
+
:currency => @currency,
|
59
|
+
:timezone => "CET",
|
60
|
+
:txntype => @txntype,
|
61
|
+
:mode => @mode,
|
62
|
+
:responseSuccessURL => @responseSuccessURL,
|
63
|
+
:responseFailURL => @responseFailURL,
|
64
|
+
:hash => hash,
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def hash
|
70
|
+
string_to_hash = @storename + @date.strftime("%Y:%m:%d-%H:%M:%S") + @chargetotal + @currency + @sharedSecret
|
71
|
+
ascii = string_to_hash.unpack("H*")
|
72
|
+
Digest::SHA1.hexdigest(ascii.to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
2
|
+
require "r_positivity"
|
3
|
+
|
4
|
+
describe "RPositivitySpec" do
|
5
|
+
|
6
|
+
def nowIs(fakeNow)
|
7
|
+
now = DateTime.parse(fakeNow)
|
8
|
+
DateTime.stub!(:now).and_return(now)
|
9
|
+
end
|
10
|
+
|
11
|
+
def empty_gw
|
12
|
+
RPositivity::RPositivity.new("1", "HZ4qjxXs5e")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return test url as default" do
|
16
|
+
empty_gw().url.should be_== "https://test.ipg-online.com/connect/gateway/processing"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return well format date as parameter" do
|
20
|
+
now = DateTime.parse('02-09-2010 11:30:44 AM')
|
21
|
+
rpositivity = RPositivity::RPositivity.new("1", "HZ4qjxXs5e").for(10, now)
|
22
|
+
rpositivity.params[:txndatetime].should be_== "2010:09:02-11:30:44"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return well format date forn now as default" do
|
26
|
+
nowIs('02-09-2010 11:30:44 AM')
|
27
|
+
empty_gw().params[:txndatetime].should be_== "2010:09:02-11:30:44"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return euro as default currency" do
|
31
|
+
empty_gw().params[:currency].should be_==RPositivity::Currency::EURO
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return CET as default TimeZone" do
|
35
|
+
empty_gw().params[:timezone].should be_=="CET"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return sale as default txntype" do
|
39
|
+
empty_gw().params[:txntype].should be_==RPositivity::TxnType::SALE
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be possible pass a different txntype" do
|
43
|
+
gw = RPositivity::RPositivity.new("1", "HZ4qjxXs5e", :txntype => RPositivity::TxnType::PREAUTH)
|
44
|
+
gw.params[:txntype].should be_==RPositivity::TxnType::PREAUTH
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have 0 as default chargetotal" do
|
48
|
+
empty_gw.params[:chargetotal].should be_=="0.00"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should need storename as parameter" do
|
52
|
+
gw = RPositivity::RPositivity.new("10012345678","HZ4qjxXs5e")
|
53
|
+
gw.params[:storename].should be_=="10012345678"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should need sharesecret as parameter" do
|
57
|
+
gw = RPositivity::RPositivity.new(10, "10012345678", "HZ4qjxXs5e")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return payonly as default mode" do
|
61
|
+
empty_gw.params[:mode].should be_==RPositivity::Mode::PAYONLY
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be possibile pass a different mode" do
|
65
|
+
gw = RPositivity::RPositivity.new("10012345678", "HZ4qjxXs5e", :mode => RPositivity::Mode::PAYPLUS)
|
66
|
+
gw.params[:mode].should be_==RPositivity::Mode::PAYPLUS
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be possible pass a responseSuccessURL" do
|
70
|
+
gw = RPositivity::RPositivity.new("10012345678", "HZ4qjxXs5e", :responseSuccessURL => "http://localhost")
|
71
|
+
gw.params[:responseSuccessURL].should be_=="http://localhost"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should be possible pass a responseFailURL" do
|
75
|
+
gw = RPositivity::RPositivity.new("10012345678", "HZ4qjxXs5e", :responseFailURL => "http://localhost")
|
76
|
+
gw.params[:responseFailURL].should be_=="http://localhost"
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
it "should return correct hash" do
|
81
|
+
nowIs('02-09-2010 02:55:30 PM')
|
82
|
+
gw = RPositivity::RPositivity.new("10012345678", "HZ4qjxXs5e").for(10)
|
83
|
+
gw.params[:hash].should be_=="bf478d3ad6f07e6d046897d2fd5c09176f8ea805"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should be possible generate 2 different indipendent gateway" do
|
87
|
+
common_gw = RPositivity::RPositivity.new("10012345678", "HZ4qjxXs5e", :responseFailURL => "http://localhost")
|
88
|
+
|
89
|
+
nowIs('02-09-2010 10:30:44 AM')
|
90
|
+
gw_for_100 = common_gw.for(100)
|
91
|
+
|
92
|
+
nowIs('02-09-2010 11:30:44 AM')
|
93
|
+
gw_for_123 = common_gw.for(123)
|
94
|
+
|
95
|
+
gw_for_100.params[:chargetotal].should be_=="100.00"
|
96
|
+
gw_for_100.params[:txndatetime].should be_== "2010:09:02-10:30:44"
|
97
|
+
|
98
|
+
gw_for_123.params[:chargetotal].should be_=="123.00"
|
99
|
+
gw_for_123.params[:txndatetime].should be_== "2010:09:02-11:30:44"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpositivity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Giordano Scalzo
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-03 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Simple wrapper to BNL e-Positivity payment gateway
|
23
|
+
email: giordano@scalzo.biz
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- README
|
33
|
+
- lib/r_positivity.rb
|
34
|
+
- spec/r_positivity_spec.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/gscalzo/RPositivity
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --charset=UTF-8
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 3
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Wrapper to BNL e-Positivity payment gateway.
|
69
|
+
test_files: []
|
70
|
+
|