k2-connect-ruby 0.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -14
- data/README.md +117 -33
- data/lib/k2-connect-ruby/k2_entity/entity.rb +8 -0
- data/lib/k2-connect-ruby/{k2_financial_entity → k2_entity}/k2_entity.rb +0 -0
- data/lib/k2-connect-ruby/{k2_financial_entity/entities → k2_entity/k2_financial_entities}/k2_pay.rb +9 -5
- data/lib/k2-connect-ruby/{k2_financial_entity/entities → k2_entity/k2_financial_entities}/k2_settlement.rb +0 -0
- data/lib/k2-connect-ruby/{k2_financial_entity/entities → k2_entity/k2_financial_entities}/k2_stk.rb +0 -0
- data/lib/k2-connect-ruby/{k2_financial_entity/entities → k2_entity/k2_financial_entities}/k2_transfer.rb +0 -0
- data/lib/k2-connect-ruby/k2_entity/k2_notification.rb +41 -0
- data/lib/k2-connect-ruby/k2_entity/k2_polling.rb +40 -0
- data/lib/k2-connect-ruby/{k2_financial_entity → k2_entity}/k2_subscribe.rb +1 -1
- data/lib/k2-connect-ruby/{k2_financial_entity → k2_entity}/k2_token.rb +28 -2
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +1 -1
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.yml +6 -1
- data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +6 -3
- data/lib/k2-connect-ruby/k2_utilities/spec_modules/spec_config.rb +1 -1
- data/lib/k2-connect-ruby/utilities.rb +3 -0
- data/lib/k2-connect-ruby/version.rb +1 -1
- data/lib/k2-connect-ruby.rb +2 -2
- metadata +13 -11
- data/lib/k2-connect-ruby/k2_financial_entity/entity.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31eba87b4eac68ac9e84013a18c31fbd9947329ed46b2baa0635634612fad44d
|
4
|
+
data.tar.gz: d00eecefb30ff3c58bb6487913b0fdde209f1b2452dfcf742722be7e5a7a189e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da32a40989d406aaac05646153edf4dfe18ec2c21eaf97a61c3ef1dc94a9571a57a7fa658fa822716d0c4c413ff04305a2c51deafab4fb8771aaab501453872b
|
7
|
+
data.tar.gz: fff96cacf6ec1888f3ab2dd2aca2683a1d042f9fbae335f19a71919f4250fac534594f5c6960b6f6a6e6c9d30b83009f3f0aa9c764796591f8cda9009e441133
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
k2-connect-ruby (0.0
|
4
|
+
k2-connect-ruby (1.0.0)
|
5
5
|
activemodel (~> 6.1.3.1)
|
6
6
|
activesupport (~> 6.1.3.1)
|
7
7
|
rest-client (~> 2.1.0)
|
@@ -10,18 +10,18 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activemodel (6.1.3.
|
14
|
-
activesupport (= 6.1.3.
|
15
|
-
activesupport (6.1.3.
|
13
|
+
activemodel (6.1.3.2)
|
14
|
+
activesupport (= 6.1.3.2)
|
15
|
+
activesupport (6.1.3.2)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
19
19
|
tzinfo (~> 2.0)
|
20
20
|
zeitwerk (~> 2.3)
|
21
|
-
addressable (2.
|
21
|
+
addressable (2.8.0)
|
22
22
|
public_suffix (>= 2.0.2, < 5.0)
|
23
23
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.1.
|
24
|
+
concurrent-ruby (1.1.9)
|
25
25
|
crack (0.4.5)
|
26
26
|
rexml
|
27
27
|
diff-lcs (1.4.4)
|
@@ -45,19 +45,19 @@ GEM
|
|
45
45
|
rspec (>= 2.99.0, < 4.0)
|
46
46
|
hashdiff (1.0.1)
|
47
47
|
http-accept (1.7.0)
|
48
|
-
http-cookie (1.0.
|
48
|
+
http-cookie (1.0.4)
|
49
49
|
domain_name (~> 0.5)
|
50
|
-
i18n (1.
|
50
|
+
i18n (1.10.0)
|
51
51
|
concurrent-ruby (~> 1.0)
|
52
52
|
listen (3.5.1)
|
53
53
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
54
54
|
rb-inotify (~> 0.9, >= 0.9.10)
|
55
55
|
lumberjack (1.2.8)
|
56
56
|
method_source (1.0.0)
|
57
|
-
mime-types (3.
|
57
|
+
mime-types (3.4.1)
|
58
58
|
mime-types-data (~> 3.2015)
|
59
|
-
mime-types-data (3.
|
60
|
-
minitest (5.
|
59
|
+
mime-types-data (3.2022.0105)
|
60
|
+
minitest (5.15.0)
|
61
61
|
nenv (0.3.0)
|
62
62
|
netrc (0.11.0)
|
63
63
|
notiffany (0.1.3)
|
@@ -100,14 +100,14 @@ GEM
|
|
100
100
|
concurrent-ruby (~> 1.0)
|
101
101
|
unf (0.1.4)
|
102
102
|
unf_ext
|
103
|
-
unf_ext (0.0.
|
103
|
+
unf_ext (0.0.8)
|
104
104
|
vcr (6.0.0)
|
105
105
|
webmock (3.12.2)
|
106
106
|
addressable (>= 2.3.6)
|
107
107
|
crack (>= 0.3.2)
|
108
108
|
hashdiff (>= 0.4.0, < 2.0.0)
|
109
109
|
yajl-ruby (1.4.1)
|
110
|
-
zeitwerk (2.4
|
110
|
+
zeitwerk (2.5.4)
|
111
111
|
|
112
112
|
PLATFORMS
|
113
113
|
ruby
|
@@ -124,4 +124,4 @@ DEPENDENCIES
|
|
124
124
|
webmock (~> 3.12.2)
|
125
125
|
|
126
126
|
BUNDLED WITH
|
127
|
-
2.2.
|
127
|
+
2.2.21
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# K2ConnectRuby For Rails
|
2
2
|
|
3
|
+
[![Gem](https://img.shields.io/gem/v/k2-connect-ruby?style=for-the-badge)](https://rubygems.org/gems/k2-connect-ruby)
|
4
|
+
|
3
5
|
Ruby SDK for connection to the Kopo Kopo API.
|
4
6
|
This documentation gives you the specifications for connecting your systems to the Kopo Kopo Application.
|
5
7
|
Primarily, the library provides functionality to do the following:
|
@@ -16,20 +18,22 @@ All calls made without authentication will also fail.
|
|
16
18
|
|
17
19
|
## LINKS
|
18
20
|
|
19
|
-
- [Installation](
|
20
|
-
- [Usage](
|
21
|
-
- [Authorization](
|
22
|
-
- [Webhook Subscription](
|
23
|
-
- [
|
24
|
-
- [
|
25
|
-
- [
|
26
|
-
- [
|
27
|
-
|
28
|
-
|
29
|
-
- [
|
30
|
-
- [
|
31
|
-
- [
|
32
|
-
- [
|
21
|
+
- [Installation](#installation)
|
22
|
+
- [Usage](#installation)
|
23
|
+
- [Authorization](#authorization)
|
24
|
+
- [Webhook Subscription](#webhook-subscription)
|
25
|
+
- [SMS Notifications](#sms-notifications)
|
26
|
+
- [STK Push](#stk-push)
|
27
|
+
- [PAY](#pay)
|
28
|
+
- [Transfers](#transfers)
|
29
|
+
- [Polling](#polling)
|
30
|
+
- [Parsing the JSON Payload](#parsing-the-json-payload)
|
31
|
+
- [Development](#development)
|
32
|
+
- [Author](#author)
|
33
|
+
- [Contributing](#contributing)
|
34
|
+
- [License](#license)
|
35
|
+
- [Changelog](#changelog)
|
36
|
+
- [Code of Conduct](#code-of-conduct)
|
33
37
|
|
34
38
|
## Installation
|
35
39
|
|
@@ -90,9 +94,32 @@ your_request = {
|
|
90
94
|
}
|
91
95
|
k2subscriber.webhook_subscribe(your_request)
|
92
96
|
```
|
97
|
+
|
98
|
+
### SMS Notifications
|
99
|
+
|
100
|
+
To create an SMS notification request by calling on the send_sms_transaction_notification method.
|
101
|
+
Ensure the following arguments are passed:
|
102
|
+
- webhook_event_reference `REQUIRED`
|
103
|
+
- message `REQUIRED`
|
104
|
+
- callback_url `REQUIRED`
|
105
|
+
|
106
|
+
Code example;
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
require 'k2-connect-ruby'
|
110
|
+
k2_token = K2AccessToken.new('your_client_id', 'your_client_secret').request_token
|
111
|
+
k2_notification = K2Notification.new(k2_token)
|
112
|
+
|
113
|
+
request_payload = {
|
114
|
+
webhook_event_reference: 'c271535c-687f-4a40-a589-8b66b894792e',
|
115
|
+
message: 'message',
|
116
|
+
callback_url: 'callback_url'
|
117
|
+
}
|
118
|
+
k2_notification.send_sms_transaction_notification(request_payload)
|
119
|
+
```
|
120
|
+
|
93
121
|
|
94
|
-
|
95
|
-
### STK-Push
|
122
|
+
### STK-Push
|
96
123
|
|
97
124
|
#### Receive Payments
|
98
125
|
|
@@ -175,6 +202,17 @@ Add a PAY Recipient, with the following arguments:
|
|
175
202
|
- bank_branch_ref `REQUIRED`
|
176
203
|
- settlement_method: 'EFT' or 'RTS' `REQUIRED`
|
177
204
|
|
205
|
+
**Paybill** PAY Recipient
|
206
|
+
- type: 'paybill' `REQUIRED`
|
207
|
+
- paybill_name `REQUIRED`
|
208
|
+
- paybill_number `REQUIRED`
|
209
|
+
- paybill_account_number `REQUIRED`
|
210
|
+
|
211
|
+
**Till** PAY Recipient
|
212
|
+
- type: 'till' `REQUIRED`
|
213
|
+
- till_name `REQUIRED`
|
214
|
+
- till_number `REQUIRED`
|
215
|
+
|
178
216
|
|
179
217
|
k2_pay.add_recipients(your_input)
|
180
218
|
|
@@ -194,6 +232,9 @@ The following arguments should be passed within a hash:
|
|
194
232
|
- destination_type `REQUIRED`
|
195
233
|
- currency default is `KES`
|
196
234
|
- value `REQUIRED`
|
235
|
+
- description `REQUIRED`
|
236
|
+
- category
|
237
|
+
- tags
|
197
238
|
- callback_url `REQUIRED`
|
198
239
|
|
199
240
|
A Successful Response is returned with the URL of the Payment resource in the HTTP Location Header.
|
@@ -222,7 +263,25 @@ Code example;
|
|
222
263
|
k2_pay = K2Pay.new(your_access_token)
|
223
264
|
k2_pay.add_recipient(your_recipient_input)
|
224
265
|
k2_pay.query_resource(k2_pay.recipients_location_url)
|
225
|
-
|
266
|
+
|
267
|
+
your_request = {
|
268
|
+
destination_type: "mobile_wallet",
|
269
|
+
destination_reference: "example_reference",
|
270
|
+
amount: {
|
271
|
+
"currency": "KES",
|
272
|
+
"value": "500"
|
273
|
+
},
|
274
|
+
description: "k2-connect",
|
275
|
+
category: "general",
|
276
|
+
tags: ["tag_1", "tag_2"],
|
277
|
+
metadata: {
|
278
|
+
"something": "",
|
279
|
+
"something_else": "Something else"
|
280
|
+
},
|
281
|
+
_links: { "callback_url": "https://example.site/example" }
|
282
|
+
}
|
283
|
+
|
284
|
+
k2_pay.create_payment(your_request)
|
226
285
|
k2_pay.query_resource(k2_pay.payments_location_url)
|
227
286
|
```
|
228
287
|
|
@@ -290,7 +349,7 @@ The Following Details should be passed for either **Blind** or **Targeted** Tran
|
|
290
349
|
- value `REQUIRED`
|
291
350
|
- callback_url `REQUIRED`
|
292
351
|
|
293
|
-
The Params are passed as the argument containing all the form data sent. A Successful Response is returned with the URL of the
|
352
|
+
The Params are passed as the argument containing all the form data sent. A Successful Response is returned with the URL of the transfer request in the HTTP Location Header.
|
294
353
|
|
295
354
|
Sample code example:
|
296
355
|
|
@@ -312,6 +371,46 @@ To Query the most recent initiated Transfer Request:
|
|
312
371
|
|
313
372
|
A HTTP Response will be returned in a JSON Payload, accessible with the k2_response_body variable.
|
314
373
|
|
374
|
+
### Polling
|
375
|
+
|
376
|
+
Allows you to poll transactions received on the Kopo Kopo system within a certain time range, and either a company or a specific till.
|
377
|
+
|
378
|
+
First Create the K2Notification Object
|
379
|
+
|
380
|
+
k2_notification = K2Notification.new(access_token)
|
381
|
+
|
382
|
+
#### Send SMS Notification
|
383
|
+
|
384
|
+
The Following Details should be passed for creating the notification:
|
385
|
+
|
386
|
+
- fromTime `REQUIRED`
|
387
|
+
- toTime `REQUIRED`
|
388
|
+
- scope `REQUIRED`
|
389
|
+
- scopeReference `REQUIRED`
|
390
|
+
- callback_url `REQUIRED`
|
391
|
+
|
392
|
+
The Params are passed as the argument containing all the form data sent. A Successful Response is returned with the URL of the request in the HTTP Location Header.
|
393
|
+
|
394
|
+
Sample code example:
|
395
|
+
|
396
|
+
```ruby
|
397
|
+
k2_notification = K2Notification.new(your_access_token)
|
398
|
+
# Blind or Targeted Transfer
|
399
|
+
k2_notification.send_sms_transaction_notification(request_payload)
|
400
|
+
```
|
401
|
+
|
402
|
+
#### Query Request
|
403
|
+
|
404
|
+
To Query the status of the prior initiated Notification Request pass the location_url response as shown:
|
405
|
+
|
406
|
+
k2_notification.query_resource_url(k2_notification.location_url)
|
407
|
+
|
408
|
+
To Query the most recent initiated Transfer Request:
|
409
|
+
|
410
|
+
k2_notification.query_resource
|
411
|
+
|
412
|
+
A HTTP Response will be returned in a JSON Payload, accessible with the k2_response_body variable.
|
413
|
+
|
315
414
|
### Parsing the JSON Payload
|
316
415
|
|
317
416
|
The K2Client class will be use to parse the Payload received from Kopo Kopo, and to further consume the webhooks and split the responses into components, the K2Authenticator and
|
@@ -434,21 +533,6 @@ k2_components = K2ProcessResult.process(k2_parse.hash_body)
|
|
434
533
|
- `links_self`
|
435
534
|
- `links_resource`
|
436
535
|
- `sending_till`
|
437
|
-
|
438
|
-
6. Merchant to Merchant Transaction:
|
439
|
-
- `id`
|
440
|
-
- `resource_id`
|
441
|
-
- `topic`
|
442
|
-
- `created_at`
|
443
|
-
- `event_type`
|
444
|
-
- `reference`
|
445
|
-
- `origination_time`
|
446
|
-
- `amount`
|
447
|
-
- `currency`
|
448
|
-
- `status`
|
449
|
-
- `links_self`
|
450
|
-
- `links_resource`
|
451
|
-
- `resource_sending_merchant`
|
452
536
|
|
453
537
|
7. Process STK Push Payment Request Result
|
454
538
|
- `id`
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'k2-connect-ruby/k2_entity/k2_token'
|
2
|
+
require 'k2-connect-ruby/k2_entity/k2_polling'
|
3
|
+
require 'k2-connect-ruby/k2_entity/k2_subscribe'
|
4
|
+
require 'k2-connect-ruby/k2_entity/k2_notification'
|
5
|
+
require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk'
|
6
|
+
require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay'
|
7
|
+
require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer'
|
8
|
+
require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement'
|
File without changes
|
data/lib/k2-connect-ruby/{k2_financial_entity/entities → k2_entity/k2_financial_entities}/k2_pay.rb
RENAMED
@@ -34,11 +34,12 @@ class K2Pay < K2Entity
|
|
34
34
|
till_number: params[:till_number]
|
35
35
|
}
|
36
36
|
# In the case of bank pay recipient
|
37
|
-
elsif params[:type].eql?('
|
38
|
-
params = validate_input(params, @exception_array += %w[
|
37
|
+
elsif params[:type].eql?('paybill')
|
38
|
+
params = validate_input(params, @exception_array += %w[paybill_name paybill_number paybill_account_number])
|
39
39
|
k2_request_pay_recipient = {
|
40
|
-
|
41
|
-
|
40
|
+
paybill_name: params[:paybill_name],
|
41
|
+
paybill_number: params[:paybill_number],
|
42
|
+
paybill_account_number: params[:paybill_account_number]
|
42
43
|
}
|
43
44
|
else
|
44
45
|
raise ArgumentError, 'Undefined Payment Method.'
|
@@ -59,7 +60,7 @@ class K2Pay < K2Entity
|
|
59
60
|
# Create an outgoing Payment to a third party.
|
60
61
|
def create_payment(params)
|
61
62
|
# Validation
|
62
|
-
params = validate_input(params, @exception_array += %w[destination_reference destination_type currency value callback_url metadata])
|
63
|
+
params = validate_input(params, @exception_array += %w[destination_reference destination_type description category tags currency value callback_url metadata])
|
63
64
|
# The Request Body Parameters
|
64
65
|
k2_request_pay_amount = {
|
65
66
|
currency: params[:currency],
|
@@ -72,6 +73,9 @@ class K2Pay < K2Entity
|
|
72
73
|
create_payment_body = {
|
73
74
|
destination_reference: params[:destination_reference],
|
74
75
|
destination_type: params[:destination_type],
|
76
|
+
description: params[:description],
|
77
|
+
category: params[:category],
|
78
|
+
tags: params[:tags],
|
75
79
|
amount: k2_request_pay_amount,
|
76
80
|
meta_data: k2_request_pay_metadata,
|
77
81
|
_links: k2_request_links
|
File without changes
|
data/lib/k2-connect-ruby/{k2_financial_entity/entities → k2_entity/k2_financial_entities}/k2_stk.rb
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class K2Notification
|
2
|
+
include K2Validation, K2Utilities
|
3
|
+
attr_reader :location_url, :k2_response_body
|
4
|
+
attr_accessor :access_token
|
5
|
+
|
6
|
+
# Initialize with access_token
|
7
|
+
def initialize(access_token)
|
8
|
+
raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
|
9
|
+
@threads = []
|
10
|
+
@access_token = access_token
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sends transaction notifications via SMS
|
14
|
+
def send_sms_transaction_notification(params)
|
15
|
+
k2_request_links = {
|
16
|
+
callback_url: params[:callback_url]
|
17
|
+
}
|
18
|
+
k2_request_body = {
|
19
|
+
webhook_event_reference: params[:webhook_event_reference],
|
20
|
+
message: params[:message],
|
21
|
+
_links: k2_request_links,
|
22
|
+
}
|
23
|
+
subscribe_hash = make_hash(K2Config.path_url('transaction_sms_notifications'), 'post', @access_token,'Notification', k2_request_body)
|
24
|
+
@location_url = K2Connect.make_request(subscribe_hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Query Recent Webhook
|
28
|
+
def query_resource(location_url = @location_url)
|
29
|
+
query_hash = make_hash(location_url, 'get', @access_token, 'Notification', nil)
|
30
|
+
@threads << Thread.new do
|
31
|
+
sleep 0.25
|
32
|
+
@k2_response_body = K2Connect.make_request(query_hash)
|
33
|
+
end
|
34
|
+
@threads.each(&:join)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Query Specific Webhook URL
|
38
|
+
def query_resource_url(url)
|
39
|
+
query_resource(url)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Class for Polling Service
|
2
|
+
class K2Polling
|
3
|
+
include K2Validation, K2Utilities
|
4
|
+
attr_reader :location_url, :k2_response_body
|
5
|
+
attr_accessor :access_token
|
6
|
+
|
7
|
+
# Initialize with access token
|
8
|
+
def initialize(access_token)
|
9
|
+
raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
|
10
|
+
@threads = []
|
11
|
+
@access_token = access_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def poll(params)
|
15
|
+
k2_request_body = {
|
16
|
+
scope: params[:scope],
|
17
|
+
scope_reference: params[:scope_reference],
|
18
|
+
from_time: params[:from_time],
|
19
|
+
to_time: params[:to_time],
|
20
|
+
_links: { callback_url: params[:callback_url] }
|
21
|
+
}
|
22
|
+
poll_hash = make_hash(K2Config.path_url('poll'), 'post', @access_token,'Polling', k2_request_body)
|
23
|
+
@location_url = K2Connect.make_request(poll_hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Retrieve your newly created polling request by its resource location
|
27
|
+
def query_resource(location_url = @location_url)
|
28
|
+
query_hash = make_hash(location_url, 'get', @access_token, 'Polling', nil)
|
29
|
+
@threads << Thread.new do
|
30
|
+
sleep 0.25
|
31
|
+
@k2_response_body = K2Connect.make_request(query_hash)
|
32
|
+
end
|
33
|
+
@threads.each(&:join)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Retrieve your newly created polling request by specific resource location
|
37
|
+
def query_resource_url(url)
|
38
|
+
query_resource(url)
|
39
|
+
end
|
40
|
+
end
|
@@ -4,7 +4,7 @@ class K2Subscribe
|
|
4
4
|
attr_reader :location_url, :k2_response_body
|
5
5
|
attr_accessor :access_token, :webhook_secret
|
6
6
|
|
7
|
-
# Initialize with
|
7
|
+
# Initialize with access token
|
8
8
|
def initialize(access_token)
|
9
9
|
raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
|
10
10
|
@threads = []
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Class for Gaining Access Token
|
2
2
|
class K2AccessToken
|
3
|
-
attr_reader :access_token
|
3
|
+
attr_reader :access_token, :token_response
|
4
4
|
|
5
5
|
def initialize(client_id, client_secret)
|
6
6
|
validate_client_credentials(client_id, client_secret)
|
@@ -8,7 +8,6 @@ class K2AccessToken
|
|
8
8
|
@client_secret = client_secret
|
9
9
|
end
|
10
10
|
|
11
|
-
# Method for sending the request to K2 sandbox or Mock Server (Receives the access_token)
|
12
11
|
def request_token
|
13
12
|
token_params = {
|
14
13
|
client_id: @client_id,
|
@@ -19,6 +18,33 @@ class K2AccessToken
|
|
19
18
|
@access_token = K2Connect.make_request(token_hash)
|
20
19
|
end
|
21
20
|
|
21
|
+
def revoke_token(access_token)
|
22
|
+
token_params = {
|
23
|
+
client_id: @client_id,
|
24
|
+
client_secret: @client_secret,
|
25
|
+
token: access_token
|
26
|
+
}
|
27
|
+
token_hash = K2AccessToken.make_hash(K2Config.path_url('revoke_token'), 'post', 'Access Token', token_params)
|
28
|
+
@token_response = K2Connect.make_request(token_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
def introspect_token(access_token)
|
32
|
+
token_params = {
|
33
|
+
client_id: @client_id,
|
34
|
+
client_secret: @client_secret,
|
35
|
+
token: access_token
|
36
|
+
}
|
37
|
+
token_hash = K2AccessToken.make_hash(K2Config.path_url('introspect_token'), 'post', 'Access Token', token_params)
|
38
|
+
@token_response = K2Connect.make_request(token_hash)
|
39
|
+
end
|
40
|
+
|
41
|
+
def token_info(access_token)
|
42
|
+
token_hash = K2AccessToken.make_hash(K2Config.path_url('token_info'), 'get', 'Access Token', nil)
|
43
|
+
|
44
|
+
token_hash[:access_token] = access_token
|
45
|
+
@token_response = K2Connect.make_request(token_hash)
|
46
|
+
end
|
47
|
+
|
22
48
|
def validate_client_credentials(client_id, client_secret)
|
23
49
|
raise ArgumentError, 'Nil or Empty Client Id or Secret!' if client_id.blank? || client_secret.blank?
|
24
50
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
2
2
|
version: v1
|
3
|
-
base_url:
|
3
|
+
base_url: https://sandbox.kopokopo.com/
|
4
4
|
endpoints: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
5
5
|
oauth_token: oauth/token
|
6
|
+
revoke_token: oauth/revoke
|
7
|
+
introspect_token: oauth/introspect
|
8
|
+
token_info: oauth/token/info
|
6
9
|
webhook_subscriptions: webhook_subscriptions
|
7
10
|
pay_recipient: pay_recipients
|
8
11
|
payments: payments
|
@@ -10,5 +13,7 @@ endpoints: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
|
10
13
|
settlement_mobile_wallet: merchant_wallets
|
11
14
|
settlement_bank_account: merchant_bank_accounts
|
12
15
|
transfers: settlement_transfers
|
16
|
+
poll: polling
|
17
|
+
transaction_sms_notifications: transaction_sms_notifications
|
13
18
|
network_operators:
|
14
19
|
- SAFARICOM
|
@@ -11,8 +11,11 @@ module K2Connect
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Set up Headers
|
14
|
-
headers = { 'Content-Type': 'application/json', Accept: 'application/
|
15
|
-
|
14
|
+
headers = { 'Content-Type': 'application/json', Accept: 'application/json', Authorization: "Bearer #{access_token}" }
|
15
|
+
# For access token request
|
16
|
+
if path_url.include?('oauth/token/info')
|
17
|
+
headers = { 'Content-Type': 'application/json', Accept: 'application/json', Authorization: "Bearer #{access_token}" }
|
18
|
+
elsif path_url.include?('oauth/')
|
16
19
|
headers = { 'Content-Type': 'application/json' }
|
17
20
|
end
|
18
21
|
|
@@ -22,7 +25,7 @@ module K2Connect
|
|
22
25
|
response_body = Yajl::Parser.parse(k2_response.body)
|
23
26
|
response_headers = Yajl::Parser.parse(k2_response.headers.to_json)
|
24
27
|
response_code = k2_response.code.to_s
|
25
|
-
raise K2ConnectionError.new(response_code)
|
28
|
+
raise K2ConnectionError.new(response_code) unless response_code[0].eql?(2.to_s)
|
26
29
|
|
27
30
|
unless request_type.eql?('get')
|
28
31
|
# Returns the access token for authorization
|
@@ -25,7 +25,7 @@ module SpecConfig
|
|
25
25
|
def custom_stub_request(request_type, path_url, request_body, response_code)
|
26
26
|
request_body = request_body.to_s
|
27
27
|
request_uri = path_url
|
28
|
-
request_headers = { Authorization: "Bearer access_token", Accept: "application/
|
28
|
+
request_headers = { Authorization: "Bearer access_token", Accept: "application/json" }
|
29
29
|
|
30
30
|
if request_type.eql?('post')
|
31
31
|
request_headers['Content-Type'] = 'application/json'
|
@@ -6,6 +6,9 @@ require 'k2-connect-ruby/k2_utilities/config/k2_config'
|
|
6
6
|
require 'k2-connect-ruby/k2_utilities/k2_process_result'
|
7
7
|
require 'k2-connect-ruby/k2_utilities/k2_process_webhook'
|
8
8
|
|
9
|
+
# For Stub Requests
|
10
|
+
require 'k2-connect-ruby/k2_utilities/spec_modules/spec_config'
|
11
|
+
|
9
12
|
module K2Utilities
|
10
13
|
def make_hash(path_url, request, access_token, class_type, body)
|
11
14
|
{
|
data/lib/k2-connect-ruby.rb
CHANGED
@@ -14,8 +14,8 @@ require 'k2-connect-ruby/utilities'
|
|
14
14
|
require 'k2-connect-ruby/k2_services/payload_process'
|
15
15
|
|
16
16
|
# Entity
|
17
|
-
require 'k2-connect-ruby/
|
18
|
-
require 'k2-connect-ruby/
|
17
|
+
require 'k2-connect-ruby/k2_entity/k2_entity'
|
18
|
+
require 'k2-connect-ruby/k2_entity/entity'
|
19
19
|
|
20
20
|
# ActiveSupport
|
21
21
|
require 'active_support/core_ext/hash/indifferent_access'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k2-connect-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DavidKar1uk1
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -203,15 +203,17 @@ files:
|
|
203
203
|
- bin/setup
|
204
204
|
- k2-connect-ruby.gemspec
|
205
205
|
- lib/k2-connect-ruby.rb
|
206
|
+
- lib/k2-connect-ruby/k2_entity/entity.rb
|
207
|
+
- lib/k2-connect-ruby/k2_entity/k2_entity.rb
|
208
|
+
- lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb
|
209
|
+
- lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement.rb
|
210
|
+
- lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb
|
211
|
+
- lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer.rb
|
212
|
+
- lib/k2-connect-ruby/k2_entity/k2_notification.rb
|
213
|
+
- lib/k2-connect-ruby/k2_entity/k2_polling.rb
|
214
|
+
- lib/k2-connect-ruby/k2_entity/k2_subscribe.rb
|
215
|
+
- lib/k2-connect-ruby/k2_entity/k2_token.rb
|
206
216
|
- lib/k2-connect-ruby/k2_errors.rb
|
207
|
-
- lib/k2-connect-ruby/k2_financial_entity/entities/k2_pay.rb
|
208
|
-
- lib/k2-connect-ruby/k2_financial_entity/entities/k2_settlement.rb
|
209
|
-
- lib/k2-connect-ruby/k2_financial_entity/entities/k2_stk.rb
|
210
|
-
- lib/k2-connect-ruby/k2_financial_entity/entities/k2_transfer.rb
|
211
|
-
- lib/k2-connect-ruby/k2_financial_entity/entity.rb
|
212
|
-
- lib/k2-connect-ruby/k2_financial_entity/k2_entity.rb
|
213
|
-
- lib/k2-connect-ruby/k2_financial_entity/k2_subscribe.rb
|
214
|
-
- lib/k2-connect-ruby/k2_financial_entity/k2_token.rb
|
215
217
|
- lib/k2-connect-ruby/k2_services/client/k2_client.rb
|
216
218
|
- lib/k2-connect-ruby/k2_services/payload_process.rb
|
217
219
|
- lib/k2-connect-ruby/k2_services/payloads/k2_transaction.rb
|
@@ -259,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
261
|
- !ruby/object:Gem::Version
|
260
262
|
version: '0'
|
261
263
|
requirements: []
|
262
|
-
rubygems_version: 3.0.
|
264
|
+
rubygems_version: 3.0.3
|
263
265
|
signing_key:
|
264
266
|
specification_version: 4
|
265
267
|
summary: Ruby SDK for the Kopo Kopo K2 Connect API.
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require 'k2-connect-ruby/k2_financial_entity/k2_token'
|
2
|
-
require 'k2-connect-ruby/k2_financial_entity/k2_subscribe'
|
3
|
-
require 'k2-connect-ruby/k2_financial_entity/entities/k2_stk'
|
4
|
-
require 'k2-connect-ruby/k2_financial_entity/entities/k2_pay'
|
5
|
-
require 'k2-connect-ruby/k2_financial_entity/entities/k2_transfer'
|
6
|
-
require 'k2-connect-ruby/k2_financial_entity/entities/k2_settlement'
|