webirr 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 8767fa7d918d0ff92dd7ef661d765a83f1c178c7ac3f71b3863d5ec12e4d3ef0
4
- data.tar.gz: a4cdfb5614bffebcee32be661a1b8e444aa0cbd84205323a6e1562b1b80703c5
3
+ metadata.gz: a58f69399972243af73a6d145553b69620e2e529404d94eebb98cbe74fa5b54c
4
+ data.tar.gz: e2b79637d60fb9c4b8f605ab2ef5cc2423c45f37b0c4e60d5757847bade732db
5
5
  SHA512:
6
- metadata.gz: c29b008f7d10eb12c27b7c3631cd50e901c49f7c01e0342f829da71029541e2d21ee80487af62976f3b7801337df83611bc680c2f575c4d21382c87bbfd2b15a
7
- data.tar.gz: 533d4af1f858f4cbe466a7ce2ea3924f53c5d026327def0632a90e4fc2abece0e426ce3693fce71d0ad1f6c17c5a4b2171de5c41e3f6386b18ee384ec7c2fa73
6
+ metadata.gz: 3c535eb9761eb175ce32136cc6dffcb65944dc6323c2fd52edde66d60328253a0ea42de26285e0e552f68223f4b6b73becf26daf8515aa4dfbeb28353bc72648
7
+ data.tar.gz: aa3ee6f965398424b8e034edafac3824ed0f15d4068285ea5cea5b408d1055038111e36cb00e8ef99d6acc7cb22b8d50d91f15da3a743333dc8ba3253eb892fc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,3 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2022-09-06
1
+ ## [0.1.3] - 2022-09-06
4
2
 
5
3
  - Initial release
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Webirr
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/webirr`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Official Ruby gem for WeBirr Payment Gateway APIs
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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 WeBirrClient
28
+
29
+ ## Examples
30
+ ### Creating a new Bill / Updating an existing Bill on WeBirr Servers
31
+
32
+ ```rb
33
+ require 'bill'
34
+ require '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 = WeBirrClient.new(api_key, true)
43
+
44
+ bill = 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 'bill'
97
+ require '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 = WeBirrClient.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 'bill'
165
+ require 'webirr_client'
166
+
167
+ // Get Payment Status of Bill
168
+ def get_webirr_payment_status
169
+ api_key = 'YOUR_API_KEY'
170
+ merchant_id = 'YOUR_MERCHANT_ID'
171
+
172
+ webirr_client = WeBirrClient.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/bill.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
 
3
5
  class Bill
@@ -9,7 +11,7 @@ class Bill
9
11
  :merchant_id,
10
12
  :time
11
13
 
12
- def as_json(options = {})
14
+ def as_json(_options = {})
13
15
  {
14
16
  customerCode: @customer_code,
15
17
  customerName: @customer_name,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webirr
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/webirr_client.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "faraday"
2
4
 
3
5
  class WebirrClient
@@ -6,7 +8,7 @@ class WebirrClient
6
8
  @client =
7
9
  Faraday.new(
8
10
  url:
9
- "#{is_test_env ? "https://api.webirr.com/" : "https://api.webirr.com:8080/"}",
11
+ (is_test_env ? "https://api.webirr.com/einvoice/api/" : "https://api.webirr.com:8080/einvoice/api/").to_s,
10
12
  params: {
11
13
  "api_key" => @api_key
12
14
  },
@@ -18,7 +20,7 @@ class WebirrClient
18
20
 
19
21
  def create_bill(bill)
20
22
  response =
21
- @client.post("einvoice/api/postbill") { |req| req.body = bill.to_json }
23
+ @client.post("postbill") { |req| req.body = bill.to_json }
22
24
  if response.success?
23
25
  JSON.parse(response.body)
24
26
  else
@@ -28,7 +30,7 @@ class WebirrClient
28
30
 
29
31
  def update_bill(bill)
30
32
  response =
31
- @client.put("einvoice/api/postbill") { |req| req.body = bill.to_json }
33
+ @client.put("postbill") { |req| req.body = bill.to_json }
32
34
  if response.success?
33
35
  JSON.parse(response.body)
34
36
  else
@@ -37,7 +39,7 @@ class WebirrClient
37
39
  end
38
40
 
39
41
  def delete_bill(payment_code)
40
- response = @client.put("einvoice/api/deletebill?wbc_code=#{payment_code}")
42
+ response = @client.put("deletebill?wbc_code=#{payment_code}")
41
43
  if response.success?
42
44
  JSON.parse(response.body)
43
45
  else
@@ -47,7 +49,7 @@ class WebirrClient
47
49
 
48
50
  def get_payment_status(payment_code)
49
51
  response =
50
- @client.get("einvoice/api/getPaymentStatus?wbc_code=#{payment_code}")
52
+ @client.get("getPaymentStatus?wbc_code=#{payment_code}")
51
53
  if response.success?
52
54
  JSON.parse(response.body)
53
55
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webirr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yohannes Aregay
@@ -52,7 +52,7 @@ metadata:
52
52
  allowed_push_host: https://rubygems.org/
53
53
  homepage_uri: https://github.com/johnhailu/webirr
54
54
  source_code_uri: https://github.com/johnhailu/webirr
55
- changelog_uri: https://github.com/johnhailu/CHANGELOG.md
55
+ changelog_uri: https://github.com/johnhailu/webirr/CHANGELOG.md
56
56
  post_install_message:
57
57
  rdoc_options: []
58
58
  require_paths: