interswitch 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +9 -0
- data/interswitch.gemspec +34 -0
- data/lib/interswitch.rb +82 -0
- data/lib/interswitch/auth_data.rb +15 -0
- data/lib/interswitch/rest_secure.rb +107 -0
- data/lib/interswitch/secure_data.rb +149 -0
- data/lib/interswitch/version.rb +5 -0
- data/test/interswitch/rest_secure_test.rb +27 -0
- data/test/interswitch/secure_data_test.rb +14 -0
- data/test/interswitch_test.rb +14 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f545796c457d4aa3181ab31d464801a52d8113e
|
4
|
+
data.tar.gz: 6dfca6ac3d1a093c8aa6275424c883eb34d04f67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 356153a40cc93cfdf0dfdc40ffc7437b948c7d47babf10c005be63d4cbeadf5257ea32cc30d4e809b812ddc3cd54c3a06ee774b66456cc992aa4c5f95b8ec9a7
|
7
|
+
data.tar.gz: de2c02acac6f96fe8c768ec01b4f6336b91f9a423053f7d7a4adf3c9b095ca32a1600faa4ed0861266c84d332e63f16fe2453b63d22ce1914ce7bdb7244a065f
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Nnaemeka.Okoroafor
|
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.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Interswitch
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/interswitch`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'interswitch'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install interswitch
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/interswitch.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/interswitch.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'interswitch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "interswitch"
|
8
|
+
spec.version = InterswitchVersion::VERSION
|
9
|
+
spec.authors = ["Nnaemeka.Okoroafor"]
|
10
|
+
spec.email = ["nnaemeka.okoroafor@interswitchgroup.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Perform common actions for interacting with Interswitch payment systems}
|
13
|
+
spec.description = %q{A utility gem with basic interswitch payment functionalities}
|
14
|
+
spec.homepage = 'https://github.com/techquest/interswitch_ruby'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.test_files = `git ls-files -- test/*`.split("\n")
|
21
|
+
|
22
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'addressable'
|
28
|
+
spec.add_development_dependency 'rest-client'
|
29
|
+
spec.add_development_dependency 'mocha'
|
30
|
+
spec.add_runtime_dependency 'addressable'
|
31
|
+
spec.add_runtime_dependency 'rest-client'
|
32
|
+
spec.add_runtime_dependency 'oauth2'
|
33
|
+
|
34
|
+
end
|
data/lib/interswitch.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require "interswitch/version"
|
2
|
+
require "interswitch/secure_data"
|
3
|
+
require "interswitch/rest_secure"
|
4
|
+
require "interswitch/auth_data"
|
5
|
+
require 'oauth2'
|
6
|
+
require 'rest-client'
|
7
|
+
|
8
|
+
class Interswitch
|
9
|
+
include SecureData
|
10
|
+
include AuthData
|
11
|
+
include RestSecure
|
12
|
+
|
13
|
+
@client_token = nil
|
14
|
+
@client_id = nil
|
15
|
+
@secret_key = nil
|
16
|
+
@client = nil
|
17
|
+
@environment = nil
|
18
|
+
@token_url = nil
|
19
|
+
|
20
|
+
def init(client_id, secret_key, environment = "SANDBOX")
|
21
|
+
@client_id = client_id
|
22
|
+
@secret_key = secret_key
|
23
|
+
@environment = environment
|
24
|
+
if environment == "SANDBOX"
|
25
|
+
@token_url = InterswitchVersion::SANDBOX_URL
|
26
|
+
else
|
27
|
+
@token_url = InterswitchVersion::PROD_URL
|
28
|
+
end
|
29
|
+
|
30
|
+
@client = OAuth2::Client.new(@client_id, @secret_key, :site => @token_url, :token_url => "/passport/oauth/token")
|
31
|
+
oauth_response = @client.client_credentials.get_token
|
32
|
+
@client_token = oauth_response.token
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def send(uri, http_method, content_type, data, access_token, http_headers={}, signed_parameters = nil)
|
37
|
+
auth_headers = generate_auth_headers(:client_id => @client_id, :secret => @secret_key,
|
38
|
+
:http_method => http_method,
|
39
|
+
:url => uri, :content_type => content_type)
|
40
|
+
if access_token == nil || access_token.length == 0
|
41
|
+
access_token = @client_token
|
42
|
+
end
|
43
|
+
|
44
|
+
auth_headers['Authorization'] = "Bearer #{access_token}"
|
45
|
+
if !http_headers.empty?
|
46
|
+
http_headers.each { |key, value|
|
47
|
+
auth_headers[key] = value
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
payload = content_type == 'json' ? data.to_json : data.to_xml
|
52
|
+
|
53
|
+
response = nil
|
54
|
+
begin
|
55
|
+
if (http_method.casecmp("post"))
|
56
|
+
response = RestClient::Request.execute(:url => uri, :method => :post, :payload => payload, :headers => auth_headers, :ssl_version => 'TLSv1_2')
|
57
|
+
elsif (http_method.casecmp("put"))
|
58
|
+
response = RestClient::Request.execute(:url => uri, :method => :put, :payload => payload, :headers => auth_headers, :ssl_version => 'TLSv1_2')
|
59
|
+
else
|
60
|
+
response = RestClient.get(uri, data, :headers => auth_headers)
|
61
|
+
end
|
62
|
+
rescue => e
|
63
|
+
response = e.response
|
64
|
+
puts response
|
65
|
+
end
|
66
|
+
|
67
|
+
return response
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_client_token
|
72
|
+
@client_token
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_password_token(username, password)
|
76
|
+
oauth_response = @client.password.get_token(username, password)
|
77
|
+
oauth_response.token
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module AuthData
|
5
|
+
|
6
|
+
def get_auth_data( public_cert, version, pan, exp_date, cvv, pin)
|
7
|
+
auth_data = version + "Z" + pan + "Z" + pin + "Z" + exp_date + "Z" + cvv
|
8
|
+
raw = File.read(public_cert)
|
9
|
+
certificate = OpenSSL::X509::Certificate.new raw
|
10
|
+
public_key = OpenSSL::PKey::RSA.new(certificate.public_key)
|
11
|
+
encrypted_string = Base64.encode64(public_key.public_encrypt(auth_data))
|
12
|
+
return encrypted_string
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'addressable/uri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'digest'
|
5
|
+
require 'base64'
|
6
|
+
require 'rack'
|
7
|
+
|
8
|
+
module RestSecure
|
9
|
+
def generate_auth_headers(hash={})
|
10
|
+
|
11
|
+
if !valid_params(hash)
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
|
15
|
+
client_id = hash[:client_id]
|
16
|
+
secret = hash[:secret]
|
17
|
+
http_method = hash[:http_method]
|
18
|
+
url = hash[:url]
|
19
|
+
tran_parameters = hash[:tran_parameters]
|
20
|
+
content_type = hash[:content_type]
|
21
|
+
|
22
|
+
nonce = generate_nonce
|
23
|
+
authorization = generate_authorization client_id
|
24
|
+
timestamp = generate_timestamp
|
25
|
+
signature = generate_signature(client_id, secret, url, http_method, timestamp, nonce, tran_parameters)
|
26
|
+
|
27
|
+
headers = {
|
28
|
+
"Signature" => signature,
|
29
|
+
"Timestamp" => timestamp,
|
30
|
+
"Nonce" => nonce,
|
31
|
+
"Authorization" => authorization,
|
32
|
+
"SignatureMethod" => "SHA1",
|
33
|
+
"Content-Type" => content_type
|
34
|
+
}
|
35
|
+
|
36
|
+
return headers
|
37
|
+
|
38
|
+
rescue => e
|
39
|
+
puts "Error occured #{e.message}"
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_signature(client_id, secret, url, http_method, timestamp, nonce, tran_parameters)
|
44
|
+
|
45
|
+
url = url.sub("http://", "https://")
|
46
|
+
encoded_url = Rack::Utils.escape(url).to_s
|
47
|
+
puts encoded_url
|
48
|
+
base_string = http_method + "&" +
|
49
|
+
encoded_url + "&" +
|
50
|
+
timestamp + "&" +
|
51
|
+
nonce + "&" +
|
52
|
+
client_id + "&" +
|
53
|
+
secret
|
54
|
+
|
55
|
+
temp_parameters = ""
|
56
|
+
if tran_parameters && tran_parameters.kind_of?(Array) && tran_parameters.count > 0
|
57
|
+
tran_parameters.each do |tran_parameter|
|
58
|
+
temp_parameters = temp_parameters + "&" + tran_parameter.to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
full_string_to_be_signed = base_string + temp_parameters
|
63
|
+
signature = Base64.encode64((Digest::SHA1.new() << full_string_to_be_signed).digest).strip
|
64
|
+
|
65
|
+
return signature
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_authorization(client_id)
|
69
|
+
"InterswitchAuth #{Base64.encode64(client_id)}"
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def generate_timestamp
|
74
|
+
Time.now.to_i.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def generate_nonce
|
78
|
+
SecureRandom.random_number(99999999999999999999999).to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def valid_params(hash={})
|
83
|
+
|
84
|
+
if hash[:client_id].to_s.strip.length == 0
|
85
|
+
puts ">>>Empty client id supplied.."
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
|
89
|
+
if hash[:secret].to_s.strip.length == 0
|
90
|
+
puts ">>>Empty secret supplied.."
|
91
|
+
return false
|
92
|
+
end
|
93
|
+
|
94
|
+
if hash[:http_method].to_s.strip.length == 0
|
95
|
+
puts ">>>Empty http method supplied.."
|
96
|
+
return false
|
97
|
+
end
|
98
|
+
|
99
|
+
if hash[:url].to_s.strip.length == 0
|
100
|
+
puts ">>>Empty url supplied.."
|
101
|
+
return false
|
102
|
+
end
|
103
|
+
|
104
|
+
return true
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
module SecureData
|
4
|
+
|
5
|
+
|
6
|
+
def get_secure_data(public_cert_path, pan, exp_date, cvv, pin, transaction_parameters = {})
|
7
|
+
|
8
|
+
pin_des_key = SecureRandom.hex(16)
|
9
|
+
mac_des_key = "00000000000000000000000000000000"
|
10
|
+
header_bytes = "4D"
|
11
|
+
|
12
|
+
format_version_bytes = "10"
|
13
|
+
mac_version_bytes = "10"
|
14
|
+
pan_diff = 20 - pan.length
|
15
|
+
pan = pan_diff.to_s + pan
|
16
|
+
|
17
|
+
if pan.to_s.strip.length != 0
|
18
|
+
pan = pan.ljust(20, 'F')
|
19
|
+
end
|
20
|
+
customer_id_bytes = pan
|
21
|
+
mac_data = self.get_mac_data_version_9(transaction_parameters)
|
22
|
+
mac_bytes = hex_to_bin(get_mac(mac_data, mac_des_key, 11))[0..7]
|
23
|
+
|
24
|
+
|
25
|
+
footer_bytes = "5A"
|
26
|
+
other_bytes = "0000000000000000000000000000"
|
27
|
+
secure_bytes = header_bytes + format_version_bytes + mac_version_bytes +
|
28
|
+
pin_des_key + mac_des_key + customer_id_bytes + mac_bytes +other_bytes + footer_bytes
|
29
|
+
|
30
|
+
raw = File.read(public_cert_path)
|
31
|
+
certificate = OpenSSL::X509::Certificate.new raw
|
32
|
+
public_key = OpenSSL::PKey::RSA.new(certificate.public_key)
|
33
|
+
encrypted_secure = public_key.public_encrypt(hex_to_bin(secure_bytes)).unpack('H*').first
|
34
|
+
pin_block = get_pin_block(pin, cvv, exp_date, pin_des_key)
|
35
|
+
|
36
|
+
secure_data = {}
|
37
|
+
secure_data[:secure] = encrypted_secure
|
38
|
+
secure_data[:pin_block] = pin_block
|
39
|
+
return secure_data
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_key
|
44
|
+
triple_des = OpenSSL::Cipher::Cipher.new('des-ede-cbc')
|
45
|
+
triple_des.encrypt
|
46
|
+
return triple_des.random_key.unpack('H*').first
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def bin_to_hex(string)
|
51
|
+
string.each_byte.map { |b| b.to_s(16) }.join
|
52
|
+
end
|
53
|
+
|
54
|
+
def hex_to_bin(string)
|
55
|
+
string.scan(/../).map { |x| x.hex }.join
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_mac (mac_data, mac_key, mac_version)
|
59
|
+
mac_cipher = ""
|
60
|
+
if mac_version.to_i == 8
|
61
|
+
cipher = OpenSSL::Cipher::Cipher.new('AES-128-CBC-HMAC-SHA1')
|
62
|
+
cipher.encrypt
|
63
|
+
key = cipher.random_key
|
64
|
+
mac_cipher = cipher.update(mac_data) + cipher.final
|
65
|
+
elsif mac_version.to_i == 12
|
66
|
+
cipher = OpenSSL::Cipher::Cipher.new('AES-256-CBC-HMAC-SHA1')
|
67
|
+
cipher.encrypt
|
68
|
+
mac_cipher = cipher.update(mac_data) + cipher.final
|
69
|
+
else
|
70
|
+
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE-CBC')
|
71
|
+
cipher.encrypt
|
72
|
+
cipher.key = mac_key
|
73
|
+
mac_cipher = cipher.update(mac_data) + cipher.final
|
74
|
+
end
|
75
|
+
return mac_cipher.unpack('H*').first
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def get_mac_data_version_9(transaction_parameters)
|
80
|
+
mac_data = ""
|
81
|
+
puts transaction_parameters
|
82
|
+
if transaction_parameters["tid"] != nil
|
83
|
+
mac_data += transaction_parameters["tid"].to_s
|
84
|
+
end
|
85
|
+
|
86
|
+
if transaction_parameters['msisdn'] != nil
|
87
|
+
mac_data += transaction_parameters['msisdn'].to_s
|
88
|
+
end
|
89
|
+
|
90
|
+
if transaction_parameters["cardName"] != nil
|
91
|
+
mac_data += transaction_parameters["cardName"].to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
if transaction_parameters["ttid"] != nil
|
95
|
+
mac_data += transaction_parameters["ttid"].to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
if transaction_parameters["amt"] != nil
|
99
|
+
mac_data += transaction_parameters["amt"].to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
if transaction_parameters["toAcctNo"] != nil
|
103
|
+
mac_data += transaction_parameters["toAcctNo"].to_s
|
104
|
+
end
|
105
|
+
|
106
|
+
if transaction_parameters["toBankCode"] != nil
|
107
|
+
mac_data = transaction_parameters["toBankCode"].to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
if transaction_parameters["toBankCode"] != nil
|
111
|
+
mac_data = transaction_parameters["toBankCode"].to_s
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
return mac_data
|
116
|
+
end
|
117
|
+
|
118
|
+
def get_pin_block(pin, cvv2, expiry_date, key_bytes)
|
119
|
+
pin_new = pin == nil || pin.length == 0 ? "0000" : pin
|
120
|
+
cvv2_new = cvv2 == nil || cvv2.length == 0 ? "000" : cvv2
|
121
|
+
expiry_date_new = expiry_date == nil || expiry_date.length == 0 ? "0000" : expiry_date
|
122
|
+
|
123
|
+
pin_block_string = pin_new + cvv2_new + expiry_date_new
|
124
|
+
|
125
|
+
pin_block_string_length = pin_block_string.length.to_s
|
126
|
+
pin_block_string_length_length = pin_block_string_length.length
|
127
|
+
clear_pin_block = pin_block_string_length_length.to_s + pin_block_string_length.to_s + pin_block_string
|
128
|
+
|
129
|
+
random_digit = 0
|
130
|
+
pin_pad_length = 16 - clear_pin_block.length
|
131
|
+
|
132
|
+
for i in 1..pin_pad_length
|
133
|
+
|
134
|
+
clear_pin_block = clear_pin_block + random_digit.to_s
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
des_ede = OpenSSL::Cipher::Cipher.new('des-ede')
|
139
|
+
des_ede.padding = 1
|
140
|
+
des_ede.key = key_bytes
|
141
|
+
des_ede.encrypt
|
142
|
+
encrypted_pin_block = des_ede.update(clear_pin_block) + des_ede.final
|
143
|
+
pin_block_hex = encrypted_pin_block.unpack('H*').first
|
144
|
+
|
145
|
+
return pin_block_hex[0..15]
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'interswitch/rest_secure'
|
3
|
+
require 'base64'
|
4
|
+
class RestSecureTest < Test::Unit::TestCase
|
5
|
+
include RestSecure
|
6
|
+
def test_generate_authorization
|
7
|
+
assert_equal "InterswitchAuth " + Base64.encode64('IKIAC48CB151885D99D0F15395F124AA6E4C24BE952D'), generate_authorization('IKIAC48CB151885D99D0F15395F124AA6E4C24BE952D')
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def test_generate_auth_headers
|
12
|
+
http_method = "POST"
|
13
|
+
url = "https://developer.interswitchng.com"
|
14
|
+
tran_parameters = ["44", "sum"]
|
15
|
+
client_id = 'IKIAC48CB151885D99D0F15395F124AA6E4C24BE952D'
|
16
|
+
secret = 'W60Ce5PlidQ72fMEyZ2qXlFPrStoQb004zFmtJHF5Z0='
|
17
|
+
|
18
|
+
headers = generate_auth_headers(
|
19
|
+
:client_id => client_id,
|
20
|
+
:secret => secret,
|
21
|
+
:http_method => http_method,
|
22
|
+
:url => url,
|
23
|
+
:tran_parameters => tran_parameters
|
24
|
+
)
|
25
|
+
#TODO test headers
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "interswitch/secure_data"
|
2
|
+
|
3
|
+
class SecureDataTest < Test::Unit::TestCase
|
4
|
+
include SecureData
|
5
|
+
def test_get_secure_data
|
6
|
+
cert_path = "C:/paymentgateway.crt"
|
7
|
+
pan = "6280511000000095"
|
8
|
+
pin = "1111"
|
9
|
+
expiry_date = "5004"
|
10
|
+
cvv = "111"
|
11
|
+
secure_data = get_secure_data(cert_path, pan, expiry_date, cvv, pin, {})
|
12
|
+
assert secure_data != nil
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'interswitch'
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha/test_unit'
|
5
|
+
require 'json'
|
6
|
+
class InterswitchTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_init
|
9
|
+
interswitch = Interswitch.new
|
10
|
+
interswitch.init("IKIA9614B82064D632E9B6418DF358A6A4AEA84D7218", "XCTiBtLy1G9chAnyg0z3BcaFK4cVpwDg/GTw2EmjTZ8=")
|
11
|
+
assert interswitch.client_token != nil
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interswitch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nnaemeka.Okoroafor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: addressable
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rest-client
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: oauth2
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: A utility gem with basic interswitch payment functionalities
|
126
|
+
email:
|
127
|
+
- nnaemeka.okoroafor@interswitchgroup.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- Gemfile
|
133
|
+
- LICENSE.txt
|
134
|
+
- README.md
|
135
|
+
- Rakefile
|
136
|
+
- interswitch.gemspec
|
137
|
+
- lib/interswitch.rb
|
138
|
+
- lib/interswitch/auth_data.rb
|
139
|
+
- lib/interswitch/rest_secure.rb
|
140
|
+
- lib/interswitch/secure_data.rb
|
141
|
+
- lib/interswitch/version.rb
|
142
|
+
- test/interswitch/rest_secure_test.rb
|
143
|
+
- test/interswitch/secure_data_test.rb
|
144
|
+
- test/interswitch_test.rb
|
145
|
+
homepage: https://github.com/techquest/interswitch_ruby
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.6.7
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Perform common actions for interacting with Interswitch payment systems
|
169
|
+
test_files:
|
170
|
+
- test/interswitch/rest_secure_test.rb
|
171
|
+
- test/interswitch/secure_data_test.rb
|
172
|
+
- test/interswitch_test.rb
|