k2-connect-ruby 0.0.3 → 1.0.0
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/Gemfile.lock +1 -1
- data/README.md +84 -17
- data/lib/k2-connect-ruby.rb +2 -2
- 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 +0 -0
- 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 +0 -0
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.yml +3 -1
- data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +3 -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
- metadata +12 -10
- 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: 6f16b31dad92f44afc4fecd11658daedb06dd25dc248dc91aac55108e231c567
|
4
|
+
data.tar.gz: f92ca5e74163589b853eaad34856cc9477b0ea0be2794a207070f4a6e02e5906
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c3e9fb52c6d643c0aa19bc7295db3f03a6b2831b6bff0fd804f49505895242e86ee551c37f0da6b417a86728c0ae4f330d612e82f961d6f9ec55da44c972881
|
7
|
+
data.tar.gz: 2098c75cdc7f5f86a65dcfe0bdc42138bba2a87eb05e0c244bf5c0e7accd3d5977b0d6ae22840ad423b2b0157980998cbcf8aa2ba791f5f3f41ea86d64701204
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# K2ConnectRuby For Rails
|
2
2
|
|
3
|
+
[](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
|
|
@@ -290,7 +317,7 @@ The Following Details should be passed for either **Blind** or **Targeted** Tran
|
|
290
317
|
- value `REQUIRED`
|
291
318
|
- callback_url `REQUIRED`
|
292
319
|
|
293
|
-
The Params are passed as the argument containing all the form data sent. A Successful Response is returned with the URL of the
|
320
|
+
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
321
|
|
295
322
|
Sample code example:
|
296
323
|
|
@@ -312,6 +339,46 @@ To Query the most recent initiated Transfer Request:
|
|
312
339
|
|
313
340
|
A HTTP Response will be returned in a JSON Payload, accessible with the k2_response_body variable.
|
314
341
|
|
342
|
+
### Polling
|
343
|
+
|
344
|
+
Tallows you to poll transactions received on the Kopo Kopo system within a certain time range, and either a company or a specific till.
|
345
|
+
|
346
|
+
First Create the K2Notification Object
|
347
|
+
|
348
|
+
k2_notification = K2Notification.new(access_token)
|
349
|
+
|
350
|
+
#### Send SMS Notification
|
351
|
+
|
352
|
+
The Following Details should be passed for creating the notification:
|
353
|
+
|
354
|
+
- fromTime `REQUIRED`
|
355
|
+
- toTime `REQUIRED`
|
356
|
+
- scope `REQUIRED`
|
357
|
+
- scopeReference `REQUIRED`
|
358
|
+
- callback_url `REQUIRED`
|
359
|
+
|
360
|
+
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.
|
361
|
+
|
362
|
+
Sample code example:
|
363
|
+
|
364
|
+
```ruby
|
365
|
+
k2_notification = K2Notification.new(your_access_token)
|
366
|
+
# Blind or Targeted Transfer
|
367
|
+
k2_notification.send_sms_transaction_notification(request_payload)
|
368
|
+
```
|
369
|
+
|
370
|
+
#### Query Request
|
371
|
+
|
372
|
+
To Query the status of the prior initiated Notification Request pass the location_url response as shown:
|
373
|
+
|
374
|
+
k2_notification.query_resource_url(k2_notification.location_url)
|
375
|
+
|
376
|
+
To Query the most recent initiated Transfer Request:
|
377
|
+
|
378
|
+
k2_notification.query_resource
|
379
|
+
|
380
|
+
A HTTP Response will be returned in a JSON Payload, accessible with the k2_response_body variable.
|
381
|
+
|
315
382
|
### Parsing the JSON Payload
|
316
383
|
|
317
384
|
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
|
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'
|
@@ -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
File without changes
|
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 = []
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
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
6
|
revoke_token: oauth/revoke
|
@@ -13,5 +13,7 @@ endpoints: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
|
13
13
|
settlement_mobile_wallet: merchant_wallets
|
14
14
|
settlement_bank_account: merchant_bank_accounts
|
15
15
|
transfers: settlement_transfers
|
16
|
+
poll: polling
|
17
|
+
transaction_sms_notifications: transaction_sms_notifications
|
16
18
|
network_operators:
|
17
19
|
- SAFARICOM
|
@@ -11,10 +11,10 @@ module K2Connect
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Set up Headers
|
14
|
-
headers = { 'Content-Type': 'application/json', Accept: 'application/
|
14
|
+
headers = { 'Content-Type': 'application/json', Accept: 'application/json', Authorization: "Bearer #{access_token}" }
|
15
15
|
# For access token request
|
16
16
|
if path_url.include?('oauth/token/info')
|
17
|
-
headers = { 'Content-Type': 'application/json', Accept: 'application/
|
17
|
+
headers = { 'Content-Type': 'application/json', Accept: 'application/json', Authorization: "Bearer #{access_token}" }
|
18
18
|
elsif path_url.include?('oauth/')
|
19
19
|
headers = { 'Content-Type': 'application/json' }
|
20
20
|
end
|
@@ -25,7 +25,7 @@ module K2Connect
|
|
25
25
|
response_body = Yajl::Parser.parse(k2_response.body)
|
26
26
|
response_headers = Yajl::Parser.parse(k2_response.headers.to_json)
|
27
27
|
response_code = k2_response.code.to_s
|
28
|
-
raise K2ConnectionError.new(response_code)
|
28
|
+
raise K2ConnectionError.new(response_code) unless response_code[0].eql?(2.to_s)
|
29
29
|
|
30
30
|
unless request_type.eql?('get')
|
31
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
|
{
|
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: 1.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: 2021-
|
11
|
+
date: 2021-07-12 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
|
@@ -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'
|