webirr 0.1.3 → 0.1.5
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/CHANGELOG.md +1 -3
- data/Gemfile.lock +2 -2
- data/README.md +203 -3
- data/lib/webirr/bill.rb +31 -0
- data/lib/webirr/client.rb +70 -0
- data/lib/webirr/version.rb +1 -1
- data/webirr.gemspec +39 -0
- metadata +6 -5
- data/lib/bill.rb +0 -27
- data/lib/webirr_client.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3c0cc887b42d61cbfe75ecb0f01cb1786a9939375ebaa2c3aaf4a2450295219
|
4
|
+
data.tar.gz: 4f51f4a4ccb1f7017a99b11122861571b5d5f934daf269c281bdf20e23637db4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c44c63531e08b3e8ead77a290fd9b7c955c1344cd0e28b434afca667ec32129c3e1aca551b127e5c219b2be2ef906502c6f379b58c1a8a795506265652e6f38
|
7
|
+
data.tar.gz: 4a9b4eed7e56fcb3b64c97c35dccbf5c2304f7f44cfa54fe7cd4a42f538f64725fd6fd339e1009f124e2e489b722a4b45d0132c3210efb4afd0fc7dcc14eb03a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
webirr (0.1.
|
4
|
+
webirr (0.1.5)
|
5
|
+
faraday (~> 2.5)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -53,7 +54,6 @@ PLATFORMS
|
|
53
54
|
x86_64-linux
|
54
55
|
|
55
56
|
DEPENDENCIES
|
56
|
-
faraday (~> 2.5)
|
57
57
|
rake (~> 13.0)
|
58
58
|
rspec (~> 3.0)
|
59
59
|
rubocop (~> 1.21)
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Webirr
|
2
2
|
|
3
|
-
|
3
|
+
Official Ruby gem for WeBirr Payment Gateway APIs
|
4
4
|
|
5
|
-
|
5
|
+
This gem provides convenient access to WeBirr Payment Gateway APIs from Ruby Applications.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,207 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
The library needs to be configured with a *merchant Id* & *API key*. You can get it by contacting [webirr.com](https://webirr.com)
|
26
|
+
|
27
|
+
> You can use this library for production or test environments. you will need to set is_test_env=true for test, and false for production apps when creating objects of class WeBirr::Client
|
28
|
+
|
29
|
+
## Examples
|
30
|
+
### Creating a new Bill / Updating an existing Bill on WeBirr Servers
|
31
|
+
|
32
|
+
```rb
|
33
|
+
require 'webirr/bill'
|
34
|
+
require 'webirr/webirr_client'
|
35
|
+
|
36
|
+
# Create & Update Bill
|
37
|
+
def create_bill
|
38
|
+
api_key = 'YOUR_API_KEY'
|
39
|
+
merchant_id = 'YOUR_MERCHANT_ID'
|
40
|
+
|
41
|
+
# client to use test envionment
|
42
|
+
webirr_client = WeBirr::Client.new(api_key, true)
|
43
|
+
|
44
|
+
bill = Webirr::Bill.new
|
45
|
+
bill.amount = "120.45"
|
46
|
+
bill.customer_code = "C001" # it can be email address or phone number if you dont have customer code
|
47
|
+
bill.customer_name = "Yohannes Aregay Hailu"
|
48
|
+
bill.time = "2022-09-06 14:20:26" # your bill time, always in this format
|
49
|
+
bill.description = "Food delivery"
|
50
|
+
bill.bill_reference = "ruby/2022/001" # your unique reference number
|
51
|
+
bill.merchant_id = merchant_id
|
52
|
+
|
53
|
+
puts "\nCreating Bill..."
|
54
|
+
|
55
|
+
res = webirr_client.create_bill(bill)
|
56
|
+
|
57
|
+
if (res["error"].blank?)
|
58
|
+
# success
|
59
|
+
payment_code = res["res"] # returns paymentcode such as 429 723 975
|
60
|
+
puts "\nPayment Code = #{payment_code}" # we may want to save payment code in local db.
|
61
|
+
else
|
62
|
+
# fail
|
63
|
+
puts "\nerror: #{res["error"]}"
|
64
|
+
puts "\nerrorCode: #{res["errorCode"]}" # can be used to handle specific busines error such as ERROR_INVLAID_INPUT_DUP_REF
|
65
|
+
end
|
66
|
+
|
67
|
+
#pp res
|
68
|
+
|
69
|
+
# Update existing bill if it is not paid
|
70
|
+
bill.amount = "278.00"
|
71
|
+
bill.customer_name = 'John ruby'
|
72
|
+
#bill.bill_reference = "WE CAN NOT CHANGE THIS"
|
73
|
+
|
74
|
+
puts "\nUpdating Bill..."
|
75
|
+
|
76
|
+
res = webirr_client.update_bill(bill)
|
77
|
+
|
78
|
+
if (res["error"].blank?)
|
79
|
+
# success
|
80
|
+
puts "\nbill is updated succesfully" #res.res will be 'OK' no need to check here!
|
81
|
+
else
|
82
|
+
# fail
|
83
|
+
puts "\nerror: #{res["error"]}"
|
84
|
+
puts "\nerrorCode: #{res["errorCode"]}" # can be used to handle specific busines error such as ERROR_INVLAID_INPUT
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
create_bill()
|
89
|
+
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
### Getting Payment status of an existing Bill from WeBirr Servers
|
94
|
+
|
95
|
+
```rb
|
96
|
+
require 'webirr/bill'
|
97
|
+
require 'webirr/webirr_client'
|
98
|
+
|
99
|
+
# Get Payment Status of Bill
|
100
|
+
def get_webirr_payment_status
|
101
|
+
api_key = 'YOUR_API_KEY'
|
102
|
+
merchant_id = 'YOUR_MERCHANT_ID'
|
103
|
+
|
104
|
+
# client to use test envionment
|
105
|
+
webirr_client = WeBirr::Client.new(api_key, true)
|
106
|
+
|
107
|
+
payment_code = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL' # suchas as '141 263 782'
|
108
|
+
|
109
|
+
puts "\nGetting Payment Status..."
|
110
|
+
|
111
|
+
res = webirr_client.get_payment_status(payment_code)
|
112
|
+
|
113
|
+
if (res["error"].blank?)
|
114
|
+
# success
|
115
|
+
if (res["res"]["status"] == 2)
|
116
|
+
data = res["res"]["data"]
|
117
|
+
puts "\nbill is paid"
|
118
|
+
puts "\nbill payment detail"
|
119
|
+
puts "\nBank: #{data["bankID"]}"
|
120
|
+
puts "\nBank Reference Number: #{data["paymentReference"]}"
|
121
|
+
puts "\nAmount Paid: #{data["amount"]}"
|
122
|
+
else
|
123
|
+
puts "\nbill is pending payment"
|
124
|
+
end
|
125
|
+
else
|
126
|
+
# fail
|
127
|
+
puts "\nerror: #{res["error"]}"
|
128
|
+
puts "\nerrorCode: #{res["errorCode"]}" # can be used to handle specific busines error such as ERROR_INVLAID_INPUT
|
129
|
+
end
|
130
|
+
|
131
|
+
#pp res
|
132
|
+
end
|
133
|
+
|
134
|
+
get_webirr_payment_status()
|
135
|
+
|
136
|
+
```
|
137
|
+
|
138
|
+
*Sample object returned from get_payment_status()*
|
139
|
+
|
140
|
+
```javascript
|
141
|
+
{
|
142
|
+
error: null,
|
143
|
+
res: {
|
144
|
+
status: 2,
|
145
|
+
data: {
|
146
|
+
id: 111112347,
|
147
|
+
paymentReference: '8G3303GHJN',
|
148
|
+
confirmed: true,
|
149
|
+
confirmedTime: '2021-07-03 10:25:35',
|
150
|
+
bankID: 'cbe_birr',
|
151
|
+
time: '2021-07-03 10:25:33',
|
152
|
+
amount: '4.60',
|
153
|
+
wbcCode: '624 549 955'
|
154
|
+
}
|
155
|
+
},
|
156
|
+
errorCode: null
|
157
|
+
}
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
### Getting Payment status of an existing Bill from WeBirr Servers
|
162
|
+
|
163
|
+
```rb
|
164
|
+
require 'webirr/bill'
|
165
|
+
require 'webirr/webirr_client'
|
166
|
+
|
167
|
+
// Get Payment Status of Webirr::Bill
|
168
|
+
def get_webirr_payment_status
|
169
|
+
api_key = 'YOUR_API_KEY'
|
170
|
+
merchant_id = 'YOUR_MERCHANT_ID'
|
171
|
+
|
172
|
+
webirr_client = WeBirr::Client.new(api_key, true)
|
173
|
+
|
174
|
+
payment_code = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL' // suchas as '141 263 782'
|
175
|
+
|
176
|
+
puts "\nGetting Payment Status..."
|
177
|
+
|
178
|
+
res = webirr_client.get_payment_status(payment_code)
|
179
|
+
|
180
|
+
if (res["error"].blank?)
|
181
|
+
# success
|
182
|
+
if (res["res"]["status"] == 2)
|
183
|
+
data = res["res"]["data"]
|
184
|
+
puts "\nbill is paid"
|
185
|
+
puts "\nbill payment detail"
|
186
|
+
puts "\nBank: #{data["bankID"]}"
|
187
|
+
puts "\nBank Reference Number: #{data["paymentReference"]}"
|
188
|
+
puts "\nAmount Paid: #{data["amount"]}"
|
189
|
+
else
|
190
|
+
puts "\nbill is pending payment"
|
191
|
+
end
|
192
|
+
else
|
193
|
+
# fail
|
194
|
+
puts "\nerror: #{res["error"]}"
|
195
|
+
puts "\nerrorCode: #{res["errorCode"]}" # can be used to handle specific busines error such as ERROR_INVLAID_INPUT
|
196
|
+
end
|
197
|
+
|
198
|
+
//pp res
|
199
|
+
end
|
200
|
+
get_webirr_payment_status()
|
201
|
+
|
202
|
+
```
|
203
|
+
|
204
|
+
*Sample object returned from getPaymentStatus()*
|
205
|
+
|
206
|
+
```javascript
|
207
|
+
{
|
208
|
+
error: null,
|
209
|
+
res: {
|
210
|
+
status: 2,
|
211
|
+
data: {
|
212
|
+
id: 111112347,
|
213
|
+
paymentReference: '8G3303GHJN',
|
214
|
+
confirmed: true,
|
215
|
+
confirmedTime: '2021-07-03 10:25:35',
|
216
|
+
bankID: 'cbe_birr',
|
217
|
+
time: '2021-07-03 10:25:33',
|
218
|
+
amount: '4.60',
|
219
|
+
wbcCode: '624 549 955'
|
220
|
+
}
|
221
|
+
},
|
222
|
+
errorCode: null
|
223
|
+
}
|
224
|
+
|
225
|
+
```
|
26
226
|
|
27
227
|
## Development
|
28
228
|
|
data/lib/webirr/bill.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Webirr
|
6
|
+
class Bill
|
7
|
+
attr_accessor :customer_code,
|
8
|
+
:customer_name,
|
9
|
+
:amount,
|
10
|
+
:description,
|
11
|
+
:bill_reference,
|
12
|
+
:merchant_id,
|
13
|
+
:time
|
14
|
+
|
15
|
+
def as_json(_options = {})
|
16
|
+
{
|
17
|
+
customerCode: @customer_code,
|
18
|
+
customerName: @customer_name,
|
19
|
+
amount: @amount,
|
20
|
+
description: @description,
|
21
|
+
billReference: @bill_reference,
|
22
|
+
merchantID: @merchant_id,
|
23
|
+
time: @time
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_json(*options)
|
28
|
+
as_json(*options).to_json(*options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
|
5
|
+
module Webirr
|
6
|
+
class Client
|
7
|
+
def initialize(api_key, is_test_env)
|
8
|
+
@api_key = api_key
|
9
|
+
@client =
|
10
|
+
Faraday.new(
|
11
|
+
url:
|
12
|
+
(is_test_env ? "https://api.webirr.com/" : "https://api.webirr.com:8080/").to_s,
|
13
|
+
params: {
|
14
|
+
"api_key" => @api_key
|
15
|
+
},
|
16
|
+
headers: {
|
17
|
+
"Content-Type" => "application/json"
|
18
|
+
}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_bill(bill)
|
23
|
+
response =
|
24
|
+
@client.post("einvoice/api/postbill") { |req| req.body = bill.to_json }
|
25
|
+
if response.success?
|
26
|
+
JSON.parse(response.body)
|
27
|
+
else
|
28
|
+
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def update_bill(bill)
|
33
|
+
response =
|
34
|
+
@client.put("einvoice/api/postbill") { |req| req.body = bill.to_json }
|
35
|
+
if response.success?
|
36
|
+
JSON.parse(response.body)
|
37
|
+
else
|
38
|
+
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete_bill(payment_code)
|
43
|
+
response = @client.put("einvoice/api/deletebill?wbc_code=#{payment_code}")
|
44
|
+
if response.success?
|
45
|
+
JSON.parse(response.body)
|
46
|
+
else
|
47
|
+
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_payment_status(payment_code)
|
52
|
+
response =
|
53
|
+
@client.get("einvoice/api/getPaymentStatus?wbc_code=#{payment_code}")
|
54
|
+
if response.success?
|
55
|
+
JSON.parse(response.body)
|
56
|
+
else
|
57
|
+
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_stat
|
62
|
+
response = @client.get("merchant/stat")
|
63
|
+
if response.success?
|
64
|
+
JSON.parse(response.body)
|
65
|
+
else
|
66
|
+
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/webirr/version.rb
CHANGED
data/webirr.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/webirr/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "webirr"
|
7
|
+
spec.version = Webirr::VERSION
|
8
|
+
spec.authors = ["Yohannes Aregay"]
|
9
|
+
spec.email = ["emailtoyohannes@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Official Ruby Client Library for WeBirr Payment Gateway APIs"
|
12
|
+
spec.description = "Official Ruby Client Library for WeBirr Payment Gateway APIs"
|
13
|
+
spec.homepage = "https://github.com/johnhailu/webirr"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.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/johnhailu/webirr"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/johnhailu/webirr/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 do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
spec.add_dependency "faraday", "~> 2.5"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webirr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yohannes Aregay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -40,11 +40,12 @@ files:
|
|
40
40
|
- LICENSE.txt
|
41
41
|
- README.md
|
42
42
|
- Rakefile
|
43
|
-
- lib/bill.rb
|
44
43
|
- lib/webirr.rb
|
44
|
+
- lib/webirr/bill.rb
|
45
|
+
- lib/webirr/client.rb
|
45
46
|
- lib/webirr/version.rb
|
46
|
-
- lib/webirr_client.rb
|
47
47
|
- sig/webirr.rbs
|
48
|
+
- webirr.gemspec
|
48
49
|
homepage: https://github.com/johnhailu/webirr
|
49
50
|
licenses:
|
50
51
|
- MIT
|
@@ -52,7 +53,7 @@ metadata:
|
|
52
53
|
allowed_push_host: https://rubygems.org/
|
53
54
|
homepage_uri: https://github.com/johnhailu/webirr
|
54
55
|
source_code_uri: https://github.com/johnhailu/webirr
|
55
|
-
changelog_uri: https://github.com/johnhailu/CHANGELOG.md
|
56
|
+
changelog_uri: https://github.com/johnhailu/webirr/CHANGELOG.md
|
56
57
|
post_install_message:
|
57
58
|
rdoc_options: []
|
58
59
|
require_paths:
|
data/lib/bill.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require "json"
|
2
|
-
|
3
|
-
class Bill
|
4
|
-
attr_accessor :customer_code,
|
5
|
-
:customer_name,
|
6
|
-
:amount,
|
7
|
-
:description,
|
8
|
-
:bill_reference,
|
9
|
-
:merchant_id,
|
10
|
-
:time
|
11
|
-
|
12
|
-
def as_json(options = {})
|
13
|
-
{
|
14
|
-
customerCode: @customer_code,
|
15
|
-
customerName: @customer_name,
|
16
|
-
amount: @amount,
|
17
|
-
description: @description,
|
18
|
-
billReference: @bill_reference,
|
19
|
-
merchantID: @merchant_id,
|
20
|
-
time: @time
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_json(*options)
|
25
|
-
as_json(*options).to_json(*options)
|
26
|
-
end
|
27
|
-
end
|
data/lib/webirr_client.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require "faraday"
|
2
|
-
|
3
|
-
class WebirrClient
|
4
|
-
def initialize(api_key, is_test_env)
|
5
|
-
@api_key = api_key
|
6
|
-
@client =
|
7
|
-
Faraday.new(
|
8
|
-
url:
|
9
|
-
"#{is_test_env ? "https://api.webirr.com/" : "https://api.webirr.com:8080/"}",
|
10
|
-
params: {
|
11
|
-
"api_key" => @api_key
|
12
|
-
},
|
13
|
-
headers: {
|
14
|
-
"Content-Type" => "application/json"
|
15
|
-
}
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_bill(bill)
|
20
|
-
response =
|
21
|
-
@client.post("einvoice/api/postbill") { |req| req.body = bill.to_json }
|
22
|
-
if response.success?
|
23
|
-
JSON.parse(response.body)
|
24
|
-
else
|
25
|
-
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def update_bill(bill)
|
30
|
-
response =
|
31
|
-
@client.put("einvoice/api/postbill") { |req| req.body = bill.to_json }
|
32
|
-
if response.success?
|
33
|
-
JSON.parse(response.body)
|
34
|
-
else
|
35
|
-
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def delete_bill(payment_code)
|
40
|
-
response = @client.put("einvoice/api/deletebill?wbc_code=#{payment_code}")
|
41
|
-
if response.success?
|
42
|
-
JSON.parse(response.body)
|
43
|
-
else
|
44
|
-
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def get_payment_status(payment_code)
|
49
|
-
response =
|
50
|
-
@client.get("einvoice/api/getPaymentStatus?wbc_code=#{payment_code}")
|
51
|
-
if response.success?
|
52
|
-
JSON.parse(response.body)
|
53
|
-
else
|
54
|
-
{ "error" => "http error #{response.status} #{response.reason_phrase}" }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|