airtel-pesa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +12 -0
- data/airtel-pesa.gemspec +37 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/airtel/pesa/authorization.rb +49 -0
- data/lib/airtel/pesa/encryption.rb +27 -0
- data/lib/airtel/pesa/version.rb +7 -0
- data/lib/airtel/pesa.rb +39 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e06e465c534dece88a911bc1944ad38b61defedf7f9c0b79c57fc66bb76e265
|
4
|
+
data.tar.gz: 4ac9c8fb62277958960e74ac9fb6f1c4882bec4d28cf941d60e10a4ca74454cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ddab4e485aad11a7c98813258bf971b3ad585c30e8b3e02b9d91698db39f377efbe868a2989f3e58d26b9f69a85aff683f023a4d90b1e4d6666b1abe05cccf4
|
7
|
+
data.tar.gz: b4867c0b8166dd0d4ce94badb6cb0f8e44d8c4e10556e403b36f8e1b8ddae6d75cba695401fde3c0f76d10653e0b8a158f8b44909b0a35c44e1dd5250d70d4d7
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.2
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Sylvance
|
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,37 @@
|
|
1
|
+
# Airtel::Pesa
|
2
|
+
|
3
|
+
Airtel gem. This gem helps you carry out operations for Airtel the easy way.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'airtel-pesa'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install airtel-pesa
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Sylvance/airtel-pesa.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/airtel-pesa.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/airtel/pesa/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "airtel-pesa"
|
7
|
+
spec.version = Airtel::Pesa::VERSION
|
8
|
+
spec.authors = ["Sylvance"]
|
9
|
+
spec.email = ["9350722+Sylvance@users.noreply.github.com"]
|
10
|
+
|
11
|
+
spec.summary = "Airtel gem."
|
12
|
+
spec.description = "This gem helps you carry out operations for Airtel the easy way."
|
13
|
+
spec.homepage = "https://github.com/Sylvance/airtel-pesa"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/Sylvance/airtel-pesa"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/Sylvance/airtel-pesa/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
spec.add_dependency "colorize"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "airtel/pesa"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class Authorization
|
12
|
+
def initialize; end
|
13
|
+
|
14
|
+
def self.call
|
15
|
+
url = URI("https://openapiuat.airtel.africa/auth/oauth2/token")
|
16
|
+
|
17
|
+
http = Net::HTTP.new(url.host, url.port)
|
18
|
+
http.use_ssl = true
|
19
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
20
|
+
|
21
|
+
request = Net::HTTP::Post.new(url)
|
22
|
+
request["Content-Type"] = 'application/json'
|
23
|
+
request.body = JSON.dump(body)
|
24
|
+
|
25
|
+
response = http.request(request)
|
26
|
+
parsed_body = JSON.parse(response.read_body)
|
27
|
+
|
28
|
+
result = OpenStruct.new(
|
29
|
+
access_token: parsed_body["access_token"],
|
30
|
+
expires_in: parsed_body["expires_in"],
|
31
|
+
token_type: parsed_body["token_type"]
|
32
|
+
)
|
33
|
+
OpenStruct.new(result: result, error: nil)
|
34
|
+
rescue JSON::ParserError => error
|
35
|
+
OpenStruct.new(result: nil, error: error)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def body
|
41
|
+
{
|
42
|
+
"client_id": Airtel::Pesa.configuration.client_id,
|
43
|
+
"client_secret": Airtel::Pesa.configuration.client_secret,
|
44
|
+
"grant_type": "client_credentials"
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module Airtel
|
8
|
+
module Pesa
|
9
|
+
class Encryption
|
10
|
+
def initialize; end
|
11
|
+
|
12
|
+
def self.call
|
13
|
+
string = '3333';
|
14
|
+
public_key = OpenSSL::PKey::RSA.new(Base64.decode64(key))
|
15
|
+
encrypted_string = Base64.encode64(public_key.public_encrypt(string))
|
16
|
+
|
17
|
+
OpenStruct.new(result: encrypted_string, error: nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def key
|
23
|
+
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCkq3XbDI1s8Lu7SpUBP+bqOs/MC6PKWz6n/0UkqTiOZqKqaoZClI3BUDTrSIJsrN1Qx7ivBzsaAYfsB0CygSSWay4iyUcnMVEDrNVOJwtWvHxpyWJC5RfKBrweW9b8klFa/CfKRtkK730apy0Kxjg+7fF0tB4O3Ic9Gxuv4pFkbQIDAQAB"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/airtel/pesa.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "pesa/authorization"
|
4
|
+
require_relative "pesa/encryption"
|
5
|
+
require_relative "pesa/version"
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
module Airtel
|
9
|
+
module Pesa
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= OpenStruct.new(
|
14
|
+
client_id: nil,
|
15
|
+
client_secret: nil,
|
16
|
+
pass_key: nil,
|
17
|
+
short_code: nil,
|
18
|
+
response_type: nil,
|
19
|
+
callback_url: nil,
|
20
|
+
result_url: nil,
|
21
|
+
queue_time_out_url: nil,
|
22
|
+
default_description: nil,
|
23
|
+
enviroment: nil
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configure
|
28
|
+
yield(configuration)
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_recursive_ostruct(hash)
|
32
|
+
result = hash.each_with_object({}) do |(key, val), memo|
|
33
|
+
memo[key] = val.is_a?(Hash) ? to_recursive_ostruct(val) : val
|
34
|
+
end
|
35
|
+
|
36
|
+
OpenStruct.new(result)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: airtel-pesa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sylvance
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: This gem helps you carry out operations for Airtel the easy way.
|
28
|
+
email:
|
29
|
+
- 9350722+Sylvance@users.noreply.github.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".github/workflows/main.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".rubocop.yml"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- airtel-pesa.gemspec
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- lib/airtel/pesa.rb
|
47
|
+
- lib/airtel/pesa/authorization.rb
|
48
|
+
- lib/airtel/pesa/encryption.rb
|
49
|
+
- lib/airtel/pesa/version.rb
|
50
|
+
homepage: https://github.com/Sylvance/airtel-pesa
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
allowed_push_host: https://rubygems.org/
|
55
|
+
homepage_uri: https://github.com/Sylvance/airtel-pesa
|
56
|
+
source_code_uri: https://github.com/Sylvance/airtel-pesa
|
57
|
+
changelog_uri: https://github.com/Sylvance/airtel-pesa/CHANGELOG.md
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.4.0
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.2.22
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Airtel gem.
|
77
|
+
test_files: []
|