ipay-rest 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/.gempush.yml +33 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/.keep +0 -0
- data/ipay-rest.gemspec +31 -0
- data/lib/ipay/rest/client.rb +30 -0
- data/lib/ipay/rest/constants.rb +9 -0
- data/lib/ipay/rest/error.rb +35 -0
- data/lib/ipay/rest/object.rb +20 -0
- data/lib/ipay/rest/objects/initiator.rb +5 -0
- data/lib/ipay/rest/objects/transaction.rb +5 -0
- data/lib/ipay/rest/objects/transaction_status.rb +5 -0
- data/lib/ipay/rest/objects/ussd_push.rb +5 -0
- data/lib/ipay/rest/resource.rb +49 -0
- data/lib/ipay/rest/resources/transaction.rb +58 -0
- data/lib/ipay/rest/version.rb +5 -0
- data/lib/ipay/rest.rb +18 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3719474558131f6d1f0ca3cd1cfa71327010e6659fa796442a52d3667ea300f0
|
4
|
+
data.tar.gz: 7ede8399bb0483b165cb49faa96cd1ba7b4ee37a9820b3bfa194305057adb6aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72786c1d980c6801fef43204a380040b58a2ebaecf275c31455e3b5e6730b91435782a9ca1685e255afb293aa0f8ae7504a6ae3b839df81a5578091ccf46e4fc
|
7
|
+
data.tar.gz: d8bb45b5a2c30870b78bb1774266891eb94fdb3eb8eb77b66a0c7e1aca38b76bcbc57548a585628e15f860352499ab6c023fec1fbac30cff832bca84bffc1d68
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Publish Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
name: Build + Publish
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@master
|
18
|
+
- name: Set up Ruby 2.6
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
version: 2.6.x
|
22
|
+
|
23
|
+
- name: Publish to RubyGems
|
24
|
+
run: |
|
25
|
+
mkdir -p $HOME/.gem
|
26
|
+
touch $HOME/.gem/credentials
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
28
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
+
gem build *.gemspec
|
30
|
+
mv *.gem gemfiles/
|
31
|
+
gem push gemfiles/*.gem
|
32
|
+
env:
|
33
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at thesamuelralak@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ipay-rest (0.1.1)
|
5
|
+
faraday (~> 2.5)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
faraday (2.5.1)
|
12
|
+
faraday-net_http (>= 2.0, < 3.1)
|
13
|
+
ruby2_keywords (>= 0.0.4)
|
14
|
+
faraday-net_http (3.0.0)
|
15
|
+
rake (12.3.3)
|
16
|
+
rspec (3.11.0)
|
17
|
+
rspec-core (~> 3.11.0)
|
18
|
+
rspec-expectations (~> 3.11.0)
|
19
|
+
rspec-mocks (~> 3.11.0)
|
20
|
+
rspec-core (3.11.0)
|
21
|
+
rspec-support (~> 3.11.0)
|
22
|
+
rspec-expectations (3.11.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.11.0)
|
25
|
+
rspec-mocks (3.11.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.11.0)
|
28
|
+
rspec-support (3.11.0)
|
29
|
+
ruby2_keywords (0.0.5)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
ipay-rest!
|
36
|
+
rake (~> 12.0)
|
37
|
+
rspec (~> 3.0)
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Samuel Ralak
|
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,84 @@
|
|
1
|
+
# Ipay::Rest
|
2
|
+
|
3
|
+
A Ruby API Wrapper for the iPay Rest API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ipay-rest'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ipay-rest
|
20
|
+
|
21
|
+
## Setup
|
22
|
+
|
23
|
+
Ensure that the following environment variables are set
|
24
|
+
|
25
|
+
```shell
|
26
|
+
LIVE=0 # set to 1 for production environment
|
27
|
+
VID=demo
|
28
|
+
IPAY_SECRET_KEY=demoCHANGED
|
29
|
+
IPAY_BASE_URL=https://apis.ipayafrica.com/payments/v2/
|
30
|
+
IPAY_CURRENCY=KES # defaults to kes
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
#
|
37
|
+
# initialize new client
|
38
|
+
#
|
39
|
+
>> client = Ipay::Rest::Client.new
|
40
|
+
=> #<Ipay::Rest::Client>
|
41
|
+
|
42
|
+
#
|
43
|
+
# initiate an iPay transaction
|
44
|
+
#
|
45
|
+
>> client.transaction.initiate(oid: "rand13", inv: "rand13", amount: 10, tel: "0706311322", eml: "test@mail.com", cbk: "https://webhook.site/d31d7a1f-b54b-4d0a-85bd-ad7fbcf70329")
|
46
|
+
=> #<Ipay::Rest::Initiator:0x0000000127ad4f80 @attributes=#<OpenStruct header_status=200, status=1, data={"sid"=>"RANDEM315E0166024821954305324DEMO", "oid"=>"rand13", "amount"=>"10", "account"=>"AT2222230339Z", "payment_channels"=>[{"name"=>"MPESA", "paybill"=>"261144"}, {"name"=>"AIRTEL", "paybill"=>"510800"}, {"name"=>"EQUITEL", "paybill"=>"510800"}], "hash"=>"f6ee6f800c0b0029d4e35617a1cd7f7eef1b1ffe82d55d72a209aa38ea2da304"}>>
|
47
|
+
|
48
|
+
#
|
49
|
+
# trigger stk push (mpesa) or ussd push (airtel)
|
50
|
+
#
|
51
|
+
>> client.transaction.push(channel: "mpesa", phone: "0706311322", sid: "RANDEM315E0166025040998533804DEMO")
|
52
|
+
=> #<Ipay::Rest::UssdPush:0x000000014d885f60 @attributes=#<OpenStruct header_status=200, status=1, text="A Payment request has been sent to the MPESA number 0706311322">>
|
53
|
+
|
54
|
+
#
|
55
|
+
# check status of a transaction
|
56
|
+
#
|
57
|
+
>> client.transaction.status(sid: "RANDEM315E0166025040998533804DEMO")
|
58
|
+
=> #<Ipay::Rest::TransactionStatus:0x000000014d9d2ad0 @attributes=#<OpenStruct status="aei7p7yrx4ae34", txncd="QHB72TPZBP", msisdn_id="SAMUEL OYENGO", msisdn_idnum="254706311322", p1="1", p2="2", p3="3", p4="4", uyt=1523817820, agt=912100205, qwh=40888604, ifd=1216531831, afd=1897686359, poi=1978274833, id="rand14", ivm="rand14", mc="10.00", channel="MPESA">>
|
59
|
+
|
60
|
+
#
|
61
|
+
# query transaction by the order id
|
62
|
+
#
|
63
|
+
>> client.transaction.search(oid: "rand14")
|
64
|
+
=> #<Ipay::Rest::TransactionStatus:0x000000014b5739f0 @attributes=#<OpenStruct header_status=200, status=1, text="payment record found", data={"vid"=>"demo", "oid"=>"rand14", "transaction_amount"=>"10.00", "transaction_code"=>"QHB72TPZBP", "telephone"=>"254706311322", "firstname"=>"SAMUEL", "lastname"=>"OYENGO", "paid_at"=>"2022-08-11 23:41:49", "payment_mode"=>"MPESA", "sid"=>"RANDEM315E0166025040998533804DEMO"}, hash="847876734b40ff598366b5f7b089eb481a100d223e41b8f14df6fdcabcbe2325">>
|
65
|
+
```
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
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.
|
70
|
+
|
71
|
+
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).
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/samuelralak/ipay-rest. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/samuelralak/ipay-rest/blob/master/CODE_OF_CONDUCT.md).
|
76
|
+
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
81
|
+
|
82
|
+
## Code of Conduct
|
83
|
+
|
84
|
+
Everyone interacting in the Ipay::Rest project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/samuelralak/ipay-rest/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ipay/rest"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gemfiles/.keep
ADDED
File without changes
|
data/ipay-rest.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/ipay/rest/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "ipay-rest"
|
5
|
+
spec.version = Ipay::Rest::VERSION
|
6
|
+
spec.authors = ["Samuel Ralak"]
|
7
|
+
spec.email = ["ralakk@hey.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{iPay Rest API Wrapper}
|
10
|
+
spec.description = %q{A Ruby interface to the iPay REST API https://dev.ipayafrica.com/C2B.html}
|
11
|
+
spec.homepage = "https://github.com/samuelralak/ipay-rest"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/samuelralak/ipay-rest"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/samuelralak/ipay-rest"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
# Gem dependencies
|
29
|
+
#
|
30
|
+
spec.add_dependency 'faraday', '~> 2.5'
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Ipay
|
4
|
+
module Rest
|
5
|
+
class Client
|
6
|
+
attr_reader :adapter
|
7
|
+
|
8
|
+
def initialize(adapter: Faraday.default_adapter)
|
9
|
+
@adapter = adapter
|
10
|
+
end
|
11
|
+
|
12
|
+
def connection
|
13
|
+
@connection ||= Faraday.new do |conn|
|
14
|
+
conn.url_prefix = Ipay::Rest::BASE_URL
|
15
|
+
conn.request :url_encoded
|
16
|
+
conn.response :json, content_type: "application/json"
|
17
|
+
conn.adapter @adaptor
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def transaction
|
22
|
+
TransactionResource.new(self )
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
"#<Ipay::Rest::Client>"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Ipay
|
2
|
+
module Rest
|
3
|
+
LIVE = ENV.fetch("LIVE") { 0 }
|
4
|
+
VID = ENV.fetch("VID") { "demo" }
|
5
|
+
SECRET_KEY = ENV.fetch("IPAY_SECRET_KEY") { "demoCHANGED" }
|
6
|
+
BASE_URL=ENV.fetch("IPAY_BASE_URL") { "https://apis.ipayafrica.com/payments/v2/" }
|
7
|
+
DEFAULT_CURRENCY=ENV.fetch("IPAY_CURRENCY") { "KES" }
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ipay
|
2
|
+
module Rest
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class FailedTransactionError < StandardError
|
6
|
+
def to_s
|
7
|
+
'Failed transaction. Not all parameters fulfilled. A notification of this transaction sent to the merchant.'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class PendingTransactionError < StandardError
|
12
|
+
def to_s
|
13
|
+
'Pending: Incoming Mobile Money Transaction Not found. Please try again in 5 minutes.'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class UsedCodeError < StandardError
|
18
|
+
def to_s
|
19
|
+
'Used: This code has been used already. A notification of this transaction sent to the merchant.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class PaymentDeficitError < StandardError
|
24
|
+
def to_s
|
25
|
+
'Less: The amount that you have sent via mobile money is LESS than what was required to validate this transaction.'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class OverPaymentError < StandardError
|
30
|
+
def to_s
|
31
|
+
'More: The amount that you have sent via mobile money is MORE than what was required to validate this transaction.'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Ipay
|
4
|
+
module Rest
|
5
|
+
class Object
|
6
|
+
def initialize(attributes)
|
7
|
+
@attributes = OpenStruct.new(attributes)
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
attribute = @attributes.send(method, *args, &block)
|
12
|
+
attribute.is_a?(Hash) ? Object.new(attribute) : attribute
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to_missing?(method, include_private = false )
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module Ipay
|
4
|
+
module Rest
|
5
|
+
class Resource
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(url, body:, headers: {})
|
13
|
+
body[:hash] = create_hash(body.values.join(""))
|
14
|
+
handle_response client.connection.post(url, body, default_headers.merge(headers))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def default_headers
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
def handle_response(response)
|
24
|
+
status = response.body['status'] || response.body['header_status']
|
25
|
+
|
26
|
+
case status
|
27
|
+
when 0
|
28
|
+
raise Error, response.body['text']
|
29
|
+
when "fe2707etr5s4wq"
|
30
|
+
raise FailedTransactionError
|
31
|
+
when "bdi6p2yy76etrs"
|
32
|
+
raise PendingTransactionError
|
33
|
+
when "cr5i3pgy9867e1"
|
34
|
+
raise UsedCodeError
|
35
|
+
when "dtfi4p7yty45wq"
|
36
|
+
raise PaymentDeficitError
|
37
|
+
when "eq3i7p5yt7645e"
|
38
|
+
raise OverPaymentError
|
39
|
+
end
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_hash(data_string)
|
45
|
+
OpenSSL::HMAC.hexdigest('sha256', Ipay::Rest::SECRET_KEY, data_string)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Ipay
|
2
|
+
module Rest
|
3
|
+
class TransactionResource < Resource
|
4
|
+
def initiate(oid:, inv:, amount:, tel:, eml:, cbk:, **params)
|
5
|
+
body = initiate_params.merge({oid: oid, inv: inv, amount: amount, tel: tel, eml: eml, cbk: cbk}, params)
|
6
|
+
Initiator.new post("transact", body: body).body
|
7
|
+
end
|
8
|
+
|
9
|
+
def status(sid:)
|
10
|
+
body = status_params.merge({sid: sid})
|
11
|
+
TransactionStatus.new post("transact/mobilemoney", body: body).body
|
12
|
+
end
|
13
|
+
|
14
|
+
def search(oid:)
|
15
|
+
body = search_params.merge({oid: oid})
|
16
|
+
Transaction.new post("transaction/search", body: body).body
|
17
|
+
end
|
18
|
+
|
19
|
+
def push(channel:, phone:, sid:)
|
20
|
+
body = push_params.merge({phone: phone, sid: sid})
|
21
|
+
UssdPush.new post("transact/push/#{channel}", body: body).body
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def initiate_params
|
27
|
+
Hash[
|
28
|
+
live: Ipay::Rest::LIVE,
|
29
|
+
oid: nil,
|
30
|
+
inv: nil,
|
31
|
+
amount: nil,
|
32
|
+
tel: nil,
|
33
|
+
eml: nil,
|
34
|
+
vid: Ipay::Rest::VID,
|
35
|
+
curr: Ipay::Rest::DEFAULT_CURRENCY,
|
36
|
+
p1: "1",
|
37
|
+
p2: "2",
|
38
|
+
p3: "3",
|
39
|
+
p4: "4",
|
40
|
+
cst: 0,
|
41
|
+
cbk: nil,
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
def push_params
|
46
|
+
Hash[phone: nil, vid: Ipay::Rest::VID, sid: nil]
|
47
|
+
end
|
48
|
+
|
49
|
+
def status_params
|
50
|
+
Hash[sid: nil, vid: Ipay::Rest::VID]
|
51
|
+
end
|
52
|
+
|
53
|
+
def search_params
|
54
|
+
Hash[oid: nil, vid: Ipay::Rest::VID]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/ipay/rest.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "ipay/rest/version"
|
2
|
+
require "ipay/rest/constants"
|
3
|
+
|
4
|
+
module Ipay
|
5
|
+
module Rest
|
6
|
+
autoload :Client, "ipay/rest/client"
|
7
|
+
autoload :Error, "ipay/rest/error"
|
8
|
+
autoload :Object, "ipay/rest/object"
|
9
|
+
autoload :Resource, "ipay/rest/resource"
|
10
|
+
|
11
|
+
autoload :Initiator, 'ipay/rest/objects/initiator'
|
12
|
+
autoload :Transaction, 'ipay/rest/objects/transaction'
|
13
|
+
autoload :TransactionStatus, 'ipay/rest/objects/transaction_status'
|
14
|
+
autoload :UssdPush, 'ipay/rest/objects/ussd_push'
|
15
|
+
|
16
|
+
autoload :TransactionResource, 'ipay/rest/resources/transaction'
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipay-rest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Ralak
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.5'
|
27
|
+
description: A Ruby interface to the iPay REST API https://dev.ipayafrica.com/C2B.html
|
28
|
+
email:
|
29
|
+
- ralakk@hey.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".github/workflows/.gempush.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".travis.yml"
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- gemfiles/.keep
|
47
|
+
- ipay-rest.gemspec
|
48
|
+
- lib/ipay/rest.rb
|
49
|
+
- lib/ipay/rest/client.rb
|
50
|
+
- lib/ipay/rest/constants.rb
|
51
|
+
- lib/ipay/rest/error.rb
|
52
|
+
- lib/ipay/rest/object.rb
|
53
|
+
- lib/ipay/rest/objects/initiator.rb
|
54
|
+
- lib/ipay/rest/objects/transaction.rb
|
55
|
+
- lib/ipay/rest/objects/transaction_status.rb
|
56
|
+
- lib/ipay/rest/objects/ussd_push.rb
|
57
|
+
- lib/ipay/rest/resource.rb
|
58
|
+
- lib/ipay/rest/resources/transaction.rb
|
59
|
+
- lib/ipay/rest/version.rb
|
60
|
+
homepage: https://github.com/samuelralak/ipay-rest
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/samuelralak/ipay-rest
|
65
|
+
source_code_uri: https://github.com/samuelralak/ipay-rest
|
66
|
+
changelog_uri: https://github.com/samuelralak/ipay-rest
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.3.0
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubygems_version: 3.3.7
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: iPay Rest API Wrapper
|
86
|
+
test_files: []
|