gladepay 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/README.md +49 -3
- data/bin/bundle +105 -0
- data/bin/htmldiff +29 -0
- data/bin/ldiff +29 -0
- data/bin/rake +29 -0
- data/bin/restclient +29 -0
- data/bin/rspec +29 -0
- data/gladepay.gemspec +6 -0
- data/lib/gladepay/error.rb +10 -0
- data/lib/gladepay/modules/api.rb +4 -0
- data/lib/gladepay/utils/utils.rb +26 -0
- data/lib/gladepay/version.rb +2 -2
- data/lib/gladepay.rb +202 -2
- metadata +41 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a114d1a41146f108872a1ed8a606e2285b11fb3c
|
4
|
+
data.tar.gz: 67ef19a43afc2be8ece696721f7578c984a38fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ab76dc31fcd61bf3bd4b84832e12f4af8e2ef77be863adc5e0e1ed74c21ae8b89773e4c3ee248dceb362312c15057adcb25b4d881088329c441195dd16b4d6c
|
7
|
+
data.tar.gz: 893da1a82060d39f3dd765bd0f842f584c145d7741e56fb11a364209e6154051ca4202448d02142a97f0291142598043e42d33467e4059d0be450eddded2ad5a
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,53 @@ Or install it yourself as:
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
|
28
|
+
|
29
|
+
@initialize = {
|
30
|
+
"action"=> "initiate",
|
31
|
+
"paymentType"=> "card",
|
32
|
+
"user"=> {
|
33
|
+
"firstname"=> "Chinaka",
|
34
|
+
"lastname"=> "Light",
|
35
|
+
"email"=> "test@gladepay.com",
|
36
|
+
"ip"=> "192.168.33.10",
|
37
|
+
"fingerprint"=> "cccvxbxbxb"
|
38
|
+
},
|
39
|
+
"card"=>{
|
40
|
+
"card_no"=> "5438898014560229",
|
41
|
+
"expiry_month"=> "09",
|
42
|
+
"expiry_year"=> "19",
|
43
|
+
"ccv"=> "789",
|
44
|
+
"pin"=> "3310"
|
45
|
+
},
|
46
|
+
"amount"=> "10000",
|
47
|
+
"country"=> "NG",
|
48
|
+
"currency"=> "NGN"
|
49
|
+
}
|
50
|
+
|
51
|
+
@merchant_key = "GP0000001" #Test Data
|
52
|
+
@merchant_secret = "123456789"
|
53
|
+
live = true #for live server, default false for test server
|
54
|
+
|
55
|
+
# Demp or Test Server Instance
|
56
|
+
gladepay = Gladepay.new(@merchant_key, @merchant_secret) # Or
|
57
|
+
#gladepay = Gladepay.new(@merchant_key, @merchant_secret, false)
|
58
|
+
|
59
|
+
#LIVE SERVER Instance
|
60
|
+
#gladepay = Gladepay.new(@merchant_key, @merchant_secret, true) #for live server
|
61
|
+
|
62
|
+
#Get Response
|
63
|
+
response = gladepay.card_payment( @initialize['user'], @initialize['card'], @initialize['amount'], @initialize['country'], @initialize['currency'])
|
64
|
+
|
65
|
+
#Validate OTP
|
66
|
+
if(response['status'] == 202)
|
67
|
+
response = gladepay.validateOTP(response['txnRef'], '12345')
|
68
|
+
end
|
69
|
+
|
70
|
+
#Verify Transaction
|
71
|
+
response = gladepay.verifyTransaction(response['txnRef'])
|
72
|
+
|
73
|
+
puts response["message"] #Transaction Successful
|
74
|
+
|
29
75
|
```
|
30
76
|
|
31
77
|
|
@@ -37,7 +83,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
37
83
|
|
38
84
|
## Contributing
|
39
85
|
|
40
|
-
Bug reports and pull requests are welcome on GitHub at https://
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://gitlab.com/gladepay-apis/gladepay-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
41
87
|
|
42
88
|
## License
|
43
89
|
|
@@ -45,4 +91,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
45
91
|
|
46
92
|
## Code of Conduct
|
47
93
|
|
48
|
-
Everyone interacting in the Gladepay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://
|
94
|
+
Everyone interacting in the Gladepay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/gladepay-apis/gladepay-ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/bundle
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby2.4
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
27
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1 || ">= 0.a"
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||= begin
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version || "#{Gem::Requirement.default}.a"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_bundler!
|
71
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
72
|
+
|
73
|
+
# must dup string for RG < 1.8 compatibility
|
74
|
+
activate_bundler(bundler_version.dup)
|
75
|
+
end
|
76
|
+
|
77
|
+
def activate_bundler(bundler_version)
|
78
|
+
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
|
79
|
+
bundler_version = "< 2"
|
80
|
+
end
|
81
|
+
gem_error = activation_error_handling do
|
82
|
+
gem "bundler", bundler_version
|
83
|
+
end
|
84
|
+
return if gem_error.nil?
|
85
|
+
require_error = activation_error_handling do
|
86
|
+
require "bundler/version"
|
87
|
+
end
|
88
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
89
|
+
warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
|
90
|
+
exit 42
|
91
|
+
end
|
92
|
+
|
93
|
+
def activation_error_handling
|
94
|
+
yield
|
95
|
+
nil
|
96
|
+
rescue StandardError, LoadError => e
|
97
|
+
e
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
m.load_bundler!
|
102
|
+
|
103
|
+
if m.invoked_as_script?
|
104
|
+
load Gem.bin_path("bundler", "bundle")
|
105
|
+
end
|
data/bin/htmldiff
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby2.4
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'htmldiff' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("diff-lcs", "htmldiff")
|
data/bin/ldiff
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby2.4
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'ldiff' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("diff-lcs", "ldiff")
|
data/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby2.4
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/restclient
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby2.4
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'restclient' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rest-client", "restclient")
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby2.4
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/gladepay.gemspec
CHANGED
@@ -24,4 +24,10 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.15"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
|
29
|
+
#Dependencies
|
30
|
+
spec.required_ruby_version = '>= 2.0.0'
|
31
|
+
spec.add_runtime_dependency 'rest-client', '~> 2.0'
|
32
|
+
|
27
33
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'gladepay/error.rb'
|
2
|
+
|
3
|
+
module Utils
|
4
|
+
|
5
|
+
def Utils.serverErrorHandler(e)
|
6
|
+
if (e.response == nil)
|
7
|
+
raise e
|
8
|
+
return
|
9
|
+
end
|
10
|
+
error = GladepayServerError.new(e.response);
|
11
|
+
case e.response.code
|
12
|
+
when 400
|
13
|
+
raise error, "HTTP Code 400: A validation or client side error occurred and the request was not fulfilled. "
|
14
|
+
when 401
|
15
|
+
raise error, "HTTP Code 401: The request was not authorized. This can be triggered by passing an invalid secret key in the authorization header or the lack of one"
|
16
|
+
when 404
|
17
|
+
raise error, "HTTP Code 404: Request could not be fulfilled as the request resource does not exist."
|
18
|
+
when 500, 501,502,503,504
|
19
|
+
raise error, "Unrecognized Response from Gateway"
|
20
|
+
else
|
21
|
+
raise error, "HTTP Code #{e.response.code}: #{e.response.body}"
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/gladepay/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.1.
|
1
|
+
class Gladepay
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
end
|
data/lib/gladepay.rb
CHANGED
@@ -1,5 +1,205 @@
|
|
1
|
+
require "rest_client"
|
1
2
|
require "gladepay/version"
|
3
|
+
require "gladepay/error"
|
4
|
+
require "gladepay/modules/api"
|
5
|
+
require "gladepay/utils/utils"
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
class Gladepay
|
9
|
+
|
10
|
+
include API
|
11
|
+
|
12
|
+
attr_reader :merchant_key, :merchant_secret, :base_url, :live
|
13
|
+
|
14
|
+
def initialize(merchant_key=nil, merchant_secret=nil, live=false)
|
15
|
+
|
16
|
+
if(merchant_key.nil?)
|
17
|
+
@merchant_key = ENV['MERCHANT_KEY']
|
18
|
+
else
|
19
|
+
@merchant_key = merchant_key
|
20
|
+
end
|
21
|
+
|
22
|
+
if(merchant_secret.nil?)
|
23
|
+
@merchant_secret = ENV['MERCHANT_SECRET']
|
24
|
+
else
|
25
|
+
@merchant_secret = merchant_secret
|
26
|
+
end
|
27
|
+
|
28
|
+
if(live)
|
29
|
+
@base_url = BASE_URL
|
30
|
+
@live = live
|
31
|
+
else
|
32
|
+
@base_url = DEMO_BASE_URL
|
33
|
+
@live = live
|
34
|
+
end
|
35
|
+
|
36
|
+
unless !@merchant_key.nil?
|
37
|
+
raise GladepayBadKeyError, "No merchant key supplied and couldn't find any in environment variables. Make sure to set merchant key as an environment variable MERCHANT_KEY"
|
38
|
+
end
|
39
|
+
|
40
|
+
unless @merchant_key[0..1] == 'GP'
|
41
|
+
raise GladepayBadKeyError, "Invalid merchant key #{@merchant_key}"
|
42
|
+
end
|
43
|
+
|
44
|
+
unless !@merchant_secret.nil?
|
45
|
+
raise GladepayBadKeyError, "No merchant secret supplied and couldn't find any in environment variables. Make sure to set the merchant secret as an environment variable MERCHANT_SECRET"
|
46
|
+
end
|
47
|
+
|
48
|
+
unless @merchant_secret.to_i.to_s == @merchant_secret
|
49
|
+
raise GladepayBadKeyError, "Invalid merchant secret #{@merchant_secret}"
|
50
|
+
end
|
51
|
+
|
52
|
+
unless (!@base_url.nil? && !@base_url.is_a?(TrueClass))
|
53
|
+
raise GladepayBadKeyError, "Invalid BaseUrl Must SPECIFY LIVE or DEMO server"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def getBaseUrl
|
59
|
+
return @base_url
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def card_payment(user_details = {}, card_details = {}, amount, country, currency)
|
64
|
+
|
65
|
+
requests = {
|
66
|
+
'user' => user_details,
|
67
|
+
'card' => card_details,
|
68
|
+
'amount' => amount,
|
69
|
+
'country' => country,
|
70
|
+
'currency' => currency
|
71
|
+
}
|
72
|
+
|
73
|
+
initiateTransactionResponse = initiateTransaction(requests)
|
74
|
+
|
75
|
+
if(initiateTransactionResponse.has_key?'status')
|
76
|
+
|
77
|
+
chargeCardResponse = chargeCard(requests, initiateTransactionResponse['txnRef'], initiateTransactionResponse['apply_auth'])
|
78
|
+
|
79
|
+
# if(chargeCardResponse.has_key['status'])
|
80
|
+
if(chargeCardResponse['status'] == 202)
|
81
|
+
if(chargeCardResponse.has_key?'validate')
|
82
|
+
respond_ar = {
|
83
|
+
"status" =>202,
|
84
|
+
"txnRef" => chargeCardResponse['txnRef'],
|
85
|
+
"message" => "Please require the user to enter an OTP and call `validateOTP` with the `txnRef`"
|
86
|
+
}
|
87
|
+
return respond_ar
|
88
|
+
elsif (chargeCardResponse.has_key?'authURL')
|
89
|
+
respond_ar = {
|
90
|
+
"status" =>202,
|
91
|
+
"txnRef" => chargeCardResponse['txnRef'],
|
92
|
+
"authURL" => chargeCardResponse['authURL'],
|
93
|
+
"message" => "Please load the link contained in `authURL` for the user to calidate Payment"
|
94
|
+
}
|
95
|
+
return respond_ar.to_json
|
96
|
+
else
|
97
|
+
respond_ar = {
|
98
|
+
"status" =>500,
|
99
|
+
"message" => "Unrecognized Response from Gateway."
|
100
|
+
}
|
101
|
+
return respond_ar
|
102
|
+
end
|
103
|
+
else
|
104
|
+
respond_ar = {
|
105
|
+
"status" => 500,
|
106
|
+
"message" => initiateTransactionResponse['message']
|
107
|
+
}
|
108
|
+
return respond_ar
|
109
|
+
end
|
110
|
+
else
|
111
|
+
respond_ar = {
|
112
|
+
"status" =>500,
|
113
|
+
"message" => "Unrecognized Response from Gateway."
|
114
|
+
}
|
115
|
+
return respond_ar
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def initiateTransaction(request)
|
121
|
+
|
122
|
+
request_data = {
|
123
|
+
"action" => "initiate",
|
124
|
+
"paymentType" => "card",
|
125
|
+
"user" => request['user'],
|
126
|
+
"card" => request['card'],
|
127
|
+
"amount"=> request['amount'],
|
128
|
+
"country"=>request['country'],
|
129
|
+
"currency"=>request['currency']
|
130
|
+
}
|
131
|
+
|
132
|
+
result = callPutAPI('payment', request_data);
|
133
|
+
|
134
|
+
return result
|
135
|
+
end
|
136
|
+
|
137
|
+
def chargeCard(request, txn_ref, auth_type)
|
138
|
+
request_data = {
|
139
|
+
"action" => "charge",
|
140
|
+
"paymentType" => "card",
|
141
|
+
"user" => request['user'],
|
142
|
+
"card" => request['card'],
|
143
|
+
"amount"=> request['amount'],
|
144
|
+
"country"=>request['country'],
|
145
|
+
"currency"=>request['currency'],
|
146
|
+
"txnRef"=>txn_ref,
|
147
|
+
"auth_type"=> auth_type
|
148
|
+
}
|
149
|
+
|
150
|
+
result = callPutAPI('payment', request_data);
|
151
|
+
|
152
|
+
return result
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
def validateOTP(txn_ref, otp)
|
157
|
+
request_data = {
|
158
|
+
"action" => "validate",
|
159
|
+
"txnRef"=>txn_ref,
|
160
|
+
"otp"=> otp
|
161
|
+
}
|
162
|
+
|
163
|
+
result = callPutAPI('payment', request_data);
|
164
|
+
|
165
|
+
return result
|
166
|
+
end
|
167
|
+
|
168
|
+
def verifyTransaction(txn_ref)
|
169
|
+
request_data = {
|
170
|
+
"action" => "verify",
|
171
|
+
"txnRef"=>txn_ref
|
172
|
+
}
|
173
|
+
|
174
|
+
result = callPutAPI('payment', request_data);
|
175
|
+
|
176
|
+
return result
|
177
|
+
end
|
178
|
+
|
179
|
+
def callPutAPI(api_method, data = {})
|
180
|
+
result = nil
|
181
|
+
begin
|
182
|
+
jdata = JSON.generate(data)
|
183
|
+
response = RestClient.put "#{@base_url}/#{api_method}" , jdata, {content_type: :json, accept: :json, key: "#{@merchant_secret}", mid: "#{@merchant_key}"}
|
184
|
+
# return response
|
185
|
+
unless (response.code == 200 || response.code == 201)
|
186
|
+
raise GladepayServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
|
187
|
+
end
|
188
|
+
|
189
|
+
result = JSON.parse(response.body)
|
190
|
+
|
191
|
+
unless(result['status'] != 0 )
|
192
|
+
raise GladepayServerError.new(response), "Server Message: #{result['message']}"
|
193
|
+
end
|
194
|
+
|
195
|
+
rescue JSON::ParserError => jsonerr
|
196
|
+
raise GladepayServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
|
197
|
+
|
198
|
+
rescue GladepayServerError => e
|
199
|
+
Utils.serverErrorHandler(e)
|
200
|
+
end
|
201
|
+
return result
|
202
|
+
|
203
|
+
end
|
2
204
|
|
3
|
-
module Gladepay
|
4
|
-
# Your code goes here...
|
5
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gladepay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chinaka Light
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
55
83
|
description: A Gem that simplifies payment with Gladepay APIs.
|
56
84
|
email:
|
57
85
|
- light@yottabitconsulting.com
|
@@ -60,16 +88,26 @@ extensions: []
|
|
60
88
|
extra_rdoc_files: []
|
61
89
|
files:
|
62
90
|
- ".gitignore"
|
91
|
+
- ".rspec"
|
63
92
|
- ".travis.yml"
|
64
93
|
- CODE_OF_CONDUCT.md
|
65
94
|
- Gemfile
|
66
95
|
- LICENSE.txt
|
67
96
|
- README.md
|
68
97
|
- Rakefile
|
98
|
+
- bin/bundle
|
69
99
|
- bin/console
|
100
|
+
- bin/htmldiff
|
101
|
+
- bin/ldiff
|
102
|
+
- bin/rake
|
103
|
+
- bin/restclient
|
104
|
+
- bin/rspec
|
70
105
|
- bin/setup
|
71
106
|
- gladepay.gemspec
|
72
107
|
- lib/gladepay.rb
|
108
|
+
- lib/gladepay/error.rb
|
109
|
+
- lib/gladepay/modules/api.rb
|
110
|
+
- lib/gladepay/utils/utils.rb
|
73
111
|
- lib/gladepay/version.rb
|
74
112
|
homepage: https://gitlab.com/gladepay-apis/gladepay-ruby
|
75
113
|
licenses:
|
@@ -83,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
121
|
requirements:
|
84
122
|
- - ">="
|
85
123
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
124
|
+
version: 2.0.0
|
87
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
126
|
requirements:
|
89
127
|
- - ">="
|