gladepay 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a114d1a41146f108872a1ed8a606e2285b11fb3c
4
- data.tar.gz: 67ef19a43afc2be8ece696721f7578c984a38fec
3
+ metadata.gz: b0210dc48d4de061b0a7ffd3710af03c25399331
4
+ data.tar.gz: 1f029306e5c948919f5a311d93e6d17ed129e175
5
5
  SHA512:
6
- metadata.gz: 5ab76dc31fcd61bf3bd4b84832e12f4af8e2ef77be863adc5e0e1ed74c21ae8b89773e4c3ee248dceb362312c15057adcb25b4d881088329c441195dd16b4d6c
7
- data.tar.gz: 893da1a82060d39f3dd765bd0f842f584c145d7741e56fb11a364209e6154051ca4202448d02142a97f0291142598043e42d33467e4059d0be450eddded2ad5a
6
+ metadata.gz: d194a3767ff8534ab6a9f4477189331a75a63415a8e2b83a4654ab7c2b7ba8adfdb2171ca93a513e8477a2edf3c1b4543073ac079cb62a9caa89e6065e11dd75
7
+ data.tar.gz: 2ba3526ce35d5f9fec65c7fa490ca1dbd6d806b4a0136f956b8d2ad2b21c006d6657310bb421be2eed905ce71507ec5c227618fdb007469b183aff5f886f2c51
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,13 @@
1
+ before_script:
2
+ - ruby -v
3
+ - which ruby
4
+ - gem install bundler --no-ri --no-rdoc
5
+ - bundle install --quiet
6
+
7
+ minitest:
8
+ script:
9
+ - bundle exec rake test
10
+
11
+ rubocop:
12
+ script:
13
+ - bundle exec rubocop
data/.rubocop.yml ADDED
@@ -0,0 +1,119 @@
1
+ # AllCops:
2
+ # Exclude:
3
+ # - 'bin/**/**'
4
+
5
+ Metrics/LineLength:
6
+ # This will disable the rule completely, regardless what other options you put
7
+ # Enabled: false
8
+ # Change the default 80 chars limit value
9
+ Max: 120
10
+ # If you want the rule only apply to a specific folder/file
11
+ Include:
12
+ - 'app/**/*'
13
+ # If you want the rule not to apply to a specific folder/file
14
+ Exclude:
15
+ - 'bin/**/*'
16
+ Metrics/MethodLength:
17
+ CountComments: false # count full line comments?
18
+ # Max: 10
19
+ # Max: 25
20
+ Max: 70
21
+
22
+ Metrics/ClassLength:
23
+ Max: 400
24
+
25
+ Metrics/AbcSize:
26
+ # The ABC size is a calculated magnitude, so this number can be an Integer or
27
+ # a Float.
28
+ Max: 35
29
+ # Max: 15
30
+
31
+ # Avoid complex methods.
32
+ Metrics/CyclomaticComplexity:
33
+ Max: 15
34
+ # Max: 6
35
+
36
+ Style/OptionalArguments:
37
+ Description: Checks for optional arguments that do not appear at the end of the argument
38
+ list
39
+ StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#optional-arguments
40
+ Enabled: false
41
+
42
+
43
+ Style/StringLiterals:
44
+ EnforcedStyle: single_quotes
45
+ Exclude:
46
+ - 'bin/**/*'
47
+ - './Rakefile'
48
+
49
+ Layout/AlignParameters:
50
+ # Alignment of parameters in multi-line method calls.
51
+ #
52
+ # The `with_first_parameter` style aligns the following lines along the same
53
+ # column as the first parameter.
54
+ #
55
+ # method_call(a,
56
+ # b)
57
+ #
58
+ # The `with_fixed_indentation` style aligns the following lines with one
59
+ # level of indentation relative to the start of the line with the method call.
60
+ #
61
+ # method_call(a,
62
+ # b)
63
+ EnforcedStyle: with_first_parameter
64
+ SupportedStyles:
65
+ - with_first_parameter
66
+ - with_fixed_indentation
67
+ # By default, the indentation width from Layout/IndentationWidth is used
68
+ # But it can be overridden by setting this parameter
69
+ IndentationWidth: ~
70
+ Exclude:
71
+ - 'bin/**/**'
72
+
73
+ Style/ExpandPathArguments:
74
+ Exclude:
75
+ - 'bin/**/**'
76
+ - './Rakefile'
77
+ - './gladepay.gemspec'
78
+
79
+ Style/PerlBackrefs:
80
+ Exclude:
81
+ - 'bin/**/**'
82
+
83
+ Metrics/PerceivedComplexity:
84
+ Exclude:
85
+ - 'bin/**/**'
86
+ Max: 15
87
+ # Max: 7
88
+
89
+ Style/SpecialGlobalVars:
90
+ Exclude:
91
+ - 'bin/**/**'
92
+
93
+ Style/IfUnlessModifier:
94
+ Exclude:
95
+ - 'bin/**/**'
96
+
97
+ Style/BlockComments:
98
+ Exclude:
99
+ - 'bin/**/**'
100
+ - 'spec/**/**'
101
+
102
+ Layout/AccessModifierIndentation:
103
+ Exclude:
104
+ - 'bin/**/**'
105
+
106
+ Metrics/BlockLength:
107
+ Exclude:
108
+ - 'bin/**/**'
109
+
110
+ Style/RedundantReturn:
111
+ Enabled: false
112
+
113
+ Style/HashSyntax:
114
+ Exclude:
115
+ - 'Rakefile'
116
+
117
+ Style/Encoding:
118
+ Exclude:
119
+ - './gladepay.gemspec'
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in gladepay.gemspec
6
6
  gemspec
7
7
  # gem 'rspec', '~> 3.0'
8
8
  # gem 'rest-client', '~> 2.0'
9
- # gem 'rest-client'
9
+ gem 'rest-client'
10
+ gem 'rubocop' # , require: false
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Gladepay Ruby
2
2
 
3
+ ![Build Status](https://gitlab.com/gladepay-apis/gladepay-ruby/badges/develop/build.svg) ![Gem Version](https://badge.fury.io/rb/gladepay.svg)
4
+
3
5
  GladePay is the leading digital payments provider with focus across African countries, dedicated to creating simple payments solution for African businesses. We are focused on building trust between buyers and sellers by providing simple solutions using the payment options (online or offline) preferred with complete security and efficiency.
4
6
 
5
7
  A RUBY Gem Or library that simplifies payment with Gladepay APIs
@@ -26,51 +28,90 @@ Or install it yourself as:
26
28
 
27
29
  ```ruby
28
30
 
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
31
+ @initialize =
32
+ {
33
+ 'action' => 'initiate',
34
+ 'paymentType' => 'card',
35
+ 'user' => {
36
+ 'firstname' => 'Chinaka',
37
+ 'lastname' => 'Light',
38
+ 'email' => 'test@gladepay.com',
39
+ 'ip' => '192.168.33.10',
40
+ 'fingerprint' => 'cccvxbxbxb'
41
+ },
42
+ 'card' => {
43
+ 'card_no' => '5438898014560229',
44
+ 'expiry_month' => '09',
45
+ 'expiry_year' => '19',
46
+ 'ccv' => '789',
47
+ 'pin' => '3310'
48
+ },
49
+ 'amount' => '10000',
50
+ 'country' => 'NG',
51
+ 'currency' => 'NGN'
52
+ }
53
+
54
+ @merchant_key = "GP0000001" #Test Data
55
+ @merchant_secret = "123456789"
56
+ live = true #for live server, default false for test server
57
+
58
+ # Demp or Test Server Instance
59
+ gladepay = Gladepay.new(@merchant_key, @merchant_secret) # Or
60
+
61
+ # gladepay = Gladepay.new(@merchant_key, @merchant_secret, false)
62
+
63
+ #LIVE SERVER Instance
64
+ # gladepay = Gladepay.new(@merchant_key, @merchant_secret, true) #for live server
61
65
 
62
- #Get Response
63
- response = gladepay.card_payment( @initialize['user'], @initialize['card'], @initialize['amount'], @initialize['country'], @initialize['currency'])
66
+ #Get Response
67
+ response = gladepay.card_payment(
68
+ @initialize['user'],
69
+ @initialize['card'],
70
+ @initialize['amount'],
71
+ @initialize['country'],
72
+ @initialize['currency']
73
+ )
74
+
75
+ # If OTP is required
76
+ response = gladepay.validate_otp(response['txnRef'], '12345')
77
+
78
+ #Verify Transaction
79
+ response = gladepay.verify_transaction(response['txnRef'])
64
80
 
65
- #Validate OTP
66
- if(response['status'] == 202)
67
- response = gladepay.validateOTP(response['txnRef'], '12345')
68
- end
81
+ puts response["message"] #Transaction Successful
69
82
 
70
- #Verify Transaction
71
- response = gladepay.verifyTransaction(response['txnRef'])
83
+ #Other methods
84
+ #Get list of all Banks:
85
+
86
+ all_banks_response = gladepay.all_banks
87
+
88
+ #Get list of banks that support account payments:
89
+ supported_banks_response = gladepay.supported_banks_account_payment
90
+
91
+ #Get Details of a card:
92
+ card_details_response = gladepay.card_details(card_number)
93
+
94
+ #Get the charges applicable to a card: (first six digit of the card no)
95
+ card_charges_response = gladepay.card_charges(amount, card_no)
96
+
97
+ #charge with token
98
+ response = gladepay.charge_with_token(
99
+ user,
100
+ token,
101
+ amount
102
+ )
103
+
104
+ #Perform Money transfer:
105
+ money_transfer_response = gladepay.money_transfer(amount, bankcode, account_number, 'Mark Silas', 'Narration')
106
+
107
+ #Verify status of Money transfer:
108
+ verify_money_transfer_response = gladepay.verify_money_transfer(txnRef)
72
109
 
73
- puts response["message"] #Transaction Successful
110
+ #Verify Account Name:
111
+ account_name_verification_response = gladepay.verify_account_name(bankcode, account_number)
112
+
113
+ #Return Values
114
+ All methods return an array.
74
115
 
75
116
  ```
76
117
 
data/gladepay.gemspec CHANGED
@@ -1,33 +1,33 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "gladepay/version"
5
+ require 'gladepay/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "gladepay"
8
+ spec.name = 'gladepay'
8
9
  spec.version = Gladepay::VERSION
9
- spec.authors = ["Chinaka Light"]
10
- spec.email = ["light@yottabitconsulting.com"]
10
+ spec.authors = ['Chinaka Light']
11
+ spec.email = ['light@yottabitconsulting.com']
11
12
 
12
- spec.summary = %q{A Gem that simplifies payment with Gladepay APIs.}
13
- spec.description = %q{A Gem that simplifies payment with Gladepay APIs.}
14
- spec.homepage = "https://gitlab.com/gladepay-apis/gladepay-ruby"
15
- spec.license = "MIT"
13
+ spec.summary = %s(A Gem that simplifies payment with Gladepay APIs.)
14
+ spec.description = %s(A Gem that simplifies payment with Gladepay APIs.)
15
+ spec.homepage = 'https://gitlab.com/gladepay-apis/gladepay-ruby'
16
+ spec.license = 'MIT'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
19
  f.match(%r{^(test|spec|features)/})
19
20
  end
20
- spec.bindir = "exe"
21
+ spec.bindir = 'exe'
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
+ spec.require_paths = ['lib']
23
24
 
24
- spec.add_development_dependency "bundler", "~> 1.15"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency 'bundler', '~> 1.15'
26
+ spec.add_development_dependency 'minitest', '~> 5.0'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
27
28
  spec.add_development_dependency 'rspec', '~> 3.0'
28
29
 
29
- #Dependencies
30
- spec.required_ruby_version = '>= 2.0.0'
30
+ # Dependencies
31
+ spec.required_ruby_version = '>= 2.2'
31
32
  spec.add_runtime_dependency 'rest-client', '~> 2.0'
32
-
33
33
  end
data/lib/gladepay.rb CHANGED
@@ -1,205 +1,301 @@
1
- require "rest_client"
2
- require "gladepay/version"
3
- require "gladepay/error"
4
- require "gladepay/modules/api"
5
- require "gladepay/utils/utils"
1
+ require 'rest_client'
2
+ require 'gladepay/version'
3
+ require 'gladepay/error'
4
+ require 'gladepay/modules/api'
5
+ require 'gladepay/utils/utils'
6
6
  require 'json'
7
7
 
8
+ # => Gladepay Class: \nWrapps Gladepay API Gateway For Ruby
8
9
  class Gladepay
10
+ include Api
9
11
 
10
- include API
12
+ attr_reader :merchant_key, :merchant_secret, :base_url, :live
11
13
 
12
- attr_reader :merchant_key, :merchant_secret, :base_url, :live
14
+ def initialize(merchant_key = nil, merchant_secret = nil, live = false)
15
+ @merchant_key = if merchant_key.nil?
16
+ ENV['MERCHANT_KEY']
17
+ else
18
+ merchant_key
19
+ end
13
20
 
14
- def initialize(merchant_key=nil, merchant_secret=nil, live=false)
21
+ @merchant_secret = if merchant_secret.nil?
22
+ ENV['MERCHANT_SECRET']
23
+ else
24
+ merchant_secret
25
+ end
15
26
 
16
- if(merchant_key.nil?)
17
- @merchant_key = ENV['MERCHANT_KEY']
18
- else
19
- @merchant_key = merchant_key
20
- end
27
+ @live = live
21
28
 
22
- if(merchant_secret.nil?)
23
- @merchant_secret = ENV['MERCHANT_SECRET']
24
- else
25
- @merchant_secret = merchant_secret
26
- end
29
+ @base_url = if @live
30
+ BASE_URL
31
+ else
32
+ DEMO_BASE_URL
33
+ end
27
34
 
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
+ if @merchant_key.nil?
36
+ 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'
37
+ end
35
38
 
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
+ raise GladepayBadKeyError, "Invalid merchant key #{@merchant_key}" unless @merchant_key[0..1] == 'GP'
39
40
 
40
- unless @merchant_key[0..1] == 'GP'
41
- raise GladepayBadKeyError, "Invalid merchant key #{@merchant_key}"
41
+ if @merchant_secret.nil?
42
+ 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'
42
43
  end
43
44
 
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
45
+ raise GladepayBadKeyError, "Invalid merchant secret #{@merchant_secret}" unless @merchant_secret.to_i.to_s == @merchant_secret
51
46
 
52
- unless (!@base_url.nil? && !@base_url.is_a?(TrueClass))
53
- raise GladepayBadKeyError, "Invalid BaseUrl Must SPECIFY LIVE or DEMO server"
54
- end
47
+ raise GladepayBadKeyError, 'Invalid BaseUrl Must SPECIFY LIVE or DEMO server' if @base_url.nil? && !@base_url.is_a?(TrueClass)
48
+ end
55
49
 
50
+ def current_base_url
51
+ return @base_url
56
52
  end
57
53
 
58
- def getBaseUrl
59
- return @base_url
54
+ def card_payment(user_details = {}, card_details = {}, amount, country, currency)
55
+ requests = {
56
+ 'user' => user_details,
57
+ 'card' => card_details,
58
+ 'amount' => amount,
59
+ 'country' => country,
60
+ 'currency' => currency
61
+ }
62
+
63
+ initiate_transaction_response = initiate_transaction(requests)
64
+
65
+ if initiate_transaction_response.key? 'status'
66
+ charge_card_response = charge_card(requests, initiate_transaction_response['txnRef'], initiate_transaction_response['apply_auth'])
67
+
68
+ if charge_card_response['status'] == 202
69
+ if charge_card_response.key? 'validate'
70
+ respond_ar = {
71
+ 'status' => 202,
72
+ 'txnRef' => charge_card_response['txnRef'],
73
+ 'message' => 'Please require the user to enter an OTP and call `validateOTP` with the `txnRef`'
74
+ }
75
+ return respond_ar
76
+ elsif charge_card_response.key? 'authURL'
77
+ respond_ar = {
78
+ 'status' => 202,
79
+ 'txnRef' => charge_card_response['txnRef'],
80
+ 'authURL' => charge_card_response['authURL'],
81
+ 'message' => 'Please load the link contained in `authURL` for the user to validate Payment'
82
+ }
83
+ return respond_ar.to_json
84
+ else
85
+ respond_ar = {
86
+ 'status' => 500,
87
+ 'message' => 'Unrecognized Response from Gateway.'
88
+ }
89
+ return respond_ar
90
+ end
91
+ else
92
+ respond_ar = {
93
+ 'status' => 500,
94
+ 'message' => initiate_transaction_response['message']
95
+ }
96
+ return respond_ar
97
+ end
98
+
99
+ else
100
+ respond_ar = {
101
+ 'status' => 500,
102
+ 'message' => 'Unrecognized Response from Gateway.'
103
+ }
104
+ return respond_ar
105
+ end
60
106
  end
61
107
 
108
+ def initiate_transaction(request)
109
+ request_data = {
110
+ 'action' => 'initiate',
111
+ 'paymentType' => 'card',
112
+ 'user' => request['user'],
113
+ 'card' => request['card'],
114
+ 'amount' => request['amount'],
115
+ 'country' => request['country'],
116
+ 'currency' => request['currency']
117
+ }
62
118
 
63
- def card_payment(user_details = {}, card_details = {}, amount, country, currency)
119
+ result = call_put_api('payment', request_data)
64
120
 
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
- }
121
+ return result
122
+ end
149
123
 
150
- result = callPutAPI('payment', request_data);
124
+ def charge_card(request, txn_ref, auth_type)
125
+ request_data = {
126
+ 'action' => 'charge',
127
+ 'paymentType' => 'card',
128
+ 'user' => request['user'],
129
+ 'card' => request['card'],
130
+ 'amount' => request['amount'],
131
+ 'country' => request['country'],
132
+ 'currency' => request['currency'],
133
+ 'txnRef' => txn_ref,
134
+ 'auth_type' => auth_type
135
+ }
136
+
137
+ result = call_put_api('payment', request_data)
138
+
139
+ return result
140
+ end
151
141
 
152
- return result
142
+ def charge_with_token(user_details = {}, token, amount)
143
+ request_data = {
144
+ 'action' => 'charge',
145
+ 'paymentType' => 'token',
146
+ 'token' => token,
147
+ 'user' => user_details,
148
+ 'amount' => amount
149
+ }
150
+
151
+ token_response = call_put_api('payment', request_data)
152
+
153
+ response = if token_response.key? 'status'
154
+ if token_response['status'] == 200
155
+ {
156
+ 'status' => 200,
157
+ 'txnRef' => token_response['txnRef'],
158
+ 'message' => 'Successful Payment'
159
+ }
160
+ else
161
+ {
162
+ 'status' => 500,
163
+ 'message' => 'Error Processing'
164
+ }
165
+ end
166
+ else
167
+ {
168
+ 'status' => 500,
169
+ 'message' => 'Unrecognized Response from Gateway.'
170
+ }
171
+ end
172
+ return response
153
173
  end
154
174
 
175
+ def account_payment(user_details, account_details = {}, amount)
176
+ request_data = {
177
+ 'action' => 'charge',
178
+ 'paymentType' => 'account',
179
+ 'user' => user_details,
180
+ 'account' => account_details,
181
+ 'amount' => amount
182
+ }
183
+
184
+ response = call_put_api('payment', request_data)
185
+ return response
186
+ end
155
187
 
156
- def validateOTP(txn_ref, otp)
157
- request_data = {
158
- "action" => "validate",
159
- "txnRef"=>txn_ref,
160
- "otp"=> otp
161
- }
188
+ def all_banks
189
+ request_data = {
190
+ 'inquire' => 'banks'
191
+ }
192
+ response = call_put_api('resources', request_data)
193
+ return response
194
+ end
162
195
 
163
- result = callPutAPI('payment', request_data);
196
+ def supported_banks_account_payment
197
+ request_data = {
198
+ 'inquire' => 'supported_chargable_banks'
199
+ }
200
+ response = call_put_api('resources', request_data)
201
+ return response
202
+ end
164
203
 
165
- return result
204
+ def card_details(card_number)
205
+ request_data = {
206
+ 'inquire' => 'card',
207
+ 'card_no' => card_number
208
+ }
209
+ response = call_put_api('resources', request_data)
210
+ return response
166
211
  end
167
212
 
168
- def verifyTransaction(txn_ref)
169
- request_data = {
170
- "action" => "verify",
171
- "txnRef"=>txn_ref
172
- }
213
+ def card_charges(card_no, amount)
214
+ request_data = {
215
+ 'inquire' => 'charges',
216
+ 'card_no' => card_no,
217
+ 'amount' => amount
218
+ }
219
+ response = call_put_api('resources', request_data)
220
+ return response
221
+ end
173
222
 
174
- result = callPutAPI('payment', request_data);
223
+ def validate_otp(txn_ref, otp)
224
+ request_data = {
225
+ 'action' => 'validate',
226
+ 'txnRef' => txn_ref,
227
+ 'otp' => otp
228
+ }
175
229
 
176
- return result
230
+ result = call_put_api('payment', request_data)
231
+ return result
177
232
  end
178
233
 
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
234
+ def verify_transaction(txn_ref)
235
+ request_data = {
236
+ 'action' => 'verify',
237
+ 'txnRef' => txn_ref
238
+ }
188
239
 
189
- result = JSON.parse(response.body)
240
+ result = call_put_api('payment', request_data)
190
241
 
191
- unless(result['status'] != 0 )
192
- raise GladepayServerError.new(response), "Server Message: #{result['message']}"
193
- end
242
+ return result
243
+ end
194
244
 
195
- rescue JSON::ParserError => jsonerr
196
- raise GladepayServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
245
+ def money_transfer(amount, bankcode, account_number, sender_name, narration)
246
+ request_data = {
247
+ 'action' => 'transfer',
248
+ 'amount' => amount,
249
+ 'bankcode' => bankcode,
250
+ 'accountnumber' => account_number,
251
+ 'sender_name' => sender_name,
252
+ 'narration' => narration
253
+ }
254
+ response = call_put_api('disburse', request_data)
255
+ return response
256
+ end
197
257
 
198
- rescue GladepayServerError => e
199
- Utils.serverErrorHandler(e)
200
- end
201
- return result
258
+ def verify_money_transfer(txn_ref)
259
+ request_data = {
260
+ 'action' => 'verify',
261
+ 'txnRef' => txn_ref
262
+ }
263
+ response = call_put_api('disburse', request_data)
264
+ return response
265
+ end
202
266
 
267
+ def verify_account_name(bankcode, account_number)
268
+ request_data = {
269
+ 'action' => 'accountname',
270
+ 'bankcode' => bankcode,
271
+ 'accountnumber' => account_number
272
+ }
273
+ response = call_put_api('resources', request_data)
274
+ return response
203
275
  end
204
276
 
277
+ def call_put_api(api_method, data = {})
278
+ result = nil
279
+ begin
280
+ jdata = JSON.generate(data)
281
+ base_url_with_method = current_base_url + '/' + api_method
282
+ response = RestClient.put base_url_with_method, jdata, content_type: :json, accept: :json, key: @merchant_secret, mid: @merchant_key
283
+
284
+ unless response.code == 200 || response.code == 201
285
+ raise GladepayServerError.new(response), 'HTTP Code ' + response.code.to_s + ': ' + response.body.to_s
286
+ end
287
+
288
+ result = JSON.parse(response.body)
289
+ # puts 'CALL_PUT_API:-RESULT '
290
+ # puts result
291
+
292
+ raise GladepayServerError.new(response), 'Server Message: '. result['message'].to_s unless result['status'] != 0
293
+ rescue JSON::ParserError => jsonerr
294
+ raise GladepayServerError.new(response), 'Invalid result data. Could not parse JSON response body \n' + jsonerr.message
295
+ rescue GladepayServerError => e
296
+ Utils.server_error_handler(e)
297
+ end
298
+
299
+ return result
300
+ end
205
301
  end
@@ -1,10 +1,10 @@
1
+ # Gladepay Server Error Handler
1
2
  class GladepayServerError < StandardError
2
- attr_reader :response
3
- def initialize(response=nil)
4
- @response = response
5
- end
6
-
3
+ attr_reader :response
4
+ def initialize(response = nil)
5
+ @response = response
6
+ end
7
7
  end
8
8
 
9
9
  class GladepayBadKeyError < StandardError
10
- end
10
+ end
@@ -1,4 +1,4 @@
1
- module API
2
- BASE_URL = "https://api.gladepay.com"
3
- DEMO_BASE_URL = "https://demo.api.gladepay.com"
4
- end
1
+ module Api
2
+ BASE_URL = 'https://api.gladepay.com'.freeze
3
+ DEMO_BASE_URL = 'https://demo.api.gladepay.com'.freeze
4
+ end
@@ -1,26 +1,22 @@
1
1
  require 'gladepay/error.rb'
2
2
 
3
+ # Utils Module To Handle Server Error
3
4
  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}"
5
+ def self.server_error_handler(error_par)
6
+ raise error if error_par.response.nil?
22
7
 
23
- end
24
- end
25
-
26
- end
8
+ error = GladepayServerError.new(error_par.response)
9
+ case error_par.response.code
10
+ when 400
11
+ raise error, 'HTTP Code 400: A validation or client side error occurred and the request was not fulfilled. '
12
+ when 401
13
+ 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'
14
+ when 404
15
+ raise error, 'HTTP Code 404: Request could not be fulfilled as the request resource does not exist.'
16
+ when 500, 501, 502, 503, 504
17
+ raise error, 'Unrecognized Response from Gateway'
18
+ else
19
+ raise error, "HTTP Code #{error_par.response.code}: #{error_par.response.body}"
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  class Gladepay
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'.freeze
3
3
  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.1
4
+ version: 0.1.2
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-25 00:00:00.000000000 Z
11
+ date: 2018-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.15'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '5.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -88,7 +88,9 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".gitlab-ci.yml"
91
92
  - ".rspec"
93
+ - ".rubocop.yml"
92
94
  - ".travis.yml"
93
95
  - CODE_OF_CONDUCT.md
94
96
  - Gemfile
@@ -121,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
123
  requirements:
122
124
  - - ">="
123
125
  - !ruby/object:Gem::Version
124
- version: 2.0.0
126
+ version: '2.2'
125
127
  required_rubygems_version: !ruby/object:Gem::Requirement
126
128
  requirements:
127
129
  - - ">="