k2-connect-ruby 1.0.0 → 3.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/.ruby-version +1 -0
- data/Gemfile.lock +78 -64
- data/README.md +103 -65
- data/k2-connect-ruby.gemspec +12 -11
- data/lib/k2-connect-ruby/{k2_entity/entity.rb → entity.rb} +5 -0
- data/lib/k2-connect-ruby/k2_entity/k2_entity.rb +24 -26
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb +92 -94
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement.rb +43 -44
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb +43 -44
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer.rb +35 -36
- data/lib/k2-connect-ruby/k2_entity/k2_notification.rb +34 -35
- data/lib/k2-connect-ruby/k2_entity/k2_polling.rb +32 -34
- data/lib/k2-connect-ruby/k2_entity/k2_subscribe.rb +34 -36
- data/lib/k2-connect-ruby/k2_entity/k2_token.rb +58 -54
- data/lib/k2-connect-ruby/k2_errors.rb +64 -62
- data/lib/k2-connect-ruby/k2_services/k2_client.rb +27 -0
- data/lib/k2-connect-ruby/k2_services/payload_process.rb +10 -5
- data/lib/k2-connect-ruby/k2_services/payloads/k2_transaction.rb +52 -46
- data/lib/k2-connect-ruby/k2_services/payloads/k2_webhooks.rb +57 -51
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/incoming_payment.rb +50 -42
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/outgoing_payment.rb +19 -11
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/transfer.rb +16 -8
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_received.rb +18 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_received.rb +13 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_reversed.rb +13 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/customer_created.rb +20 -12
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb +40 -32
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +49 -46
- data/lib/k2-connect-ruby/k2_utilities/k2_authenticator.rb +19 -0
- data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +39 -32
- data/lib/k2-connect-ruby/k2_utilities/k2_process_result.rb +42 -37
- data/lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb +51 -50
- data/lib/k2-connect-ruby/k2_utilities/k2_url_parse.rb +11 -6
- data/lib/k2-connect-ruby/k2_utilities/k2_validation.rb +104 -102
- data/lib/k2-connect-ruby/{utilities.rb → k2_utilities.rb} +8 -8
- data/lib/k2-connect-ruby/version.rb +1 -1
- data/lib/k2-connect-ruby.rb +7 -25
- metadata +56 -43
- data/lib/k2-connect-ruby/k2_services/client/k2_client.rb +0 -24
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_received.rb +0 -10
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_received.rb +0 -5
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_reversal.rb +0 -5
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/m2m_transaction.rb +0 -8
- data/lib/k2-connect-ruby/k2_utilities/k2_authorize.rb +0 -14
- data/lib/k2-connect-ruby/k2_utilities/spec_modules/spec_config.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39452b9ce27762de19e13888108a4e6500beb4e8f73e3319183ae2748be63b54
|
4
|
+
data.tar.gz: 40277be4b8a546de3a0da71658f9a4aa5e91d360bd1152844b97588e57fc843b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9824461475aca1c8adf231457a80c209a54bc05dfff5a9da7b2c58a27cf6d69340a9d207c780aba751b753ac69b801208a3d8d2987f32b39a7fc87f689b0cd0c
|
7
|
+
data.tar.gz: 82808613065a33e5a377f6207c135f2dc9bc973c0577992d272cd5b7655c83078c75083a3cd0fda1eacf4c2f96f220af1adaaf9ad12ee4eb0d211ca661caacc8
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.5
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
k2-connect-ruby (0.0
|
5
|
-
activemodel (~>
|
6
|
-
activesupport (~>
|
4
|
+
k2-connect-ruby (3.0.0)
|
5
|
+
activemodel (~> 7.2.2)
|
6
|
+
activesupport (~> 7.2.2)
|
7
|
+
json (~> 2.8.2)
|
7
8
|
rest-client (~> 2.1.0)
|
8
|
-
yajl-ruby (~> 1.4.1)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activemodel (
|
14
|
-
activesupport (=
|
15
|
-
activesupport (
|
16
|
-
|
13
|
+
activemodel (7.2.2)
|
14
|
+
activesupport (= 7.2.2)
|
15
|
+
activesupport (7.2.2)
|
16
|
+
base64
|
17
|
+
benchmark (>= 0.3)
|
18
|
+
bigdecimal
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
20
|
+
connection_pool (>= 2.2.5)
|
21
|
+
drb
|
17
22
|
i18n (>= 1.6, < 2)
|
23
|
+
logger (>= 1.4.2)
|
18
24
|
minitest (>= 5.1)
|
19
|
-
|
20
|
-
|
21
|
-
addressable (2.7
|
22
|
-
public_suffix (>= 2.0.2, <
|
25
|
+
securerandom (>= 0.3)
|
26
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
27
|
+
addressable (2.8.7)
|
28
|
+
public_suffix (>= 2.0.2, < 7.0)
|
29
|
+
base64 (0.2.0)
|
30
|
+
benchmark (0.4.0)
|
31
|
+
bigdecimal (3.1.8)
|
23
32
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.
|
25
|
-
|
33
|
+
concurrent-ruby (1.3.4)
|
34
|
+
connection_pool (2.4.1)
|
35
|
+
crack (1.0.0)
|
36
|
+
bigdecimal
|
26
37
|
rexml
|
27
|
-
diff-lcs (1.
|
28
|
-
domain_name (0.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
diff-lcs (1.5.1)
|
39
|
+
domain_name (0.6.20240107)
|
40
|
+
drb (2.2.1)
|
41
|
+
faker (3.5.1)
|
42
|
+
i18n (>= 1.8.11, < 2)
|
43
|
+
ffi (1.17.0)
|
44
|
+
formatador (1.1.0)
|
45
|
+
guard (2.19.0)
|
33
46
|
formatador (>= 0.2.4)
|
34
47
|
listen (>= 2.7, < 4.0)
|
35
48
|
lumberjack (>= 1.0.12, < 2.0)
|
36
49
|
nenv (~> 0.1)
|
37
50
|
notiffany (~> 0.0)
|
38
|
-
pry (>= 0.
|
51
|
+
pry (>= 0.13.0)
|
39
52
|
shellany (~> 0.0)
|
40
53
|
thor (>= 0.18.1)
|
41
54
|
guard-compat (1.2.1)
|
@@ -43,85 +56,86 @@ GEM
|
|
43
56
|
guard (~> 2.1)
|
44
57
|
guard-compat (~> 1.1)
|
45
58
|
rspec (>= 2.99.0, < 4.0)
|
46
|
-
hashdiff (1.
|
59
|
+
hashdiff (1.1.2)
|
47
60
|
http-accept (1.7.0)
|
48
|
-
http-cookie (1.0.
|
61
|
+
http-cookie (1.0.7)
|
49
62
|
domain_name (~> 0.5)
|
50
|
-
i18n (1.
|
63
|
+
i18n (1.14.6)
|
51
64
|
concurrent-ruby (~> 1.0)
|
52
|
-
|
65
|
+
json (2.8.2)
|
66
|
+
listen (3.9.0)
|
53
67
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
54
68
|
rb-inotify (~> 0.9, >= 0.9.10)
|
55
|
-
|
56
|
-
|
57
|
-
|
69
|
+
logger (1.6.1)
|
70
|
+
lumberjack (1.2.10)
|
71
|
+
method_source (1.1.0)
|
72
|
+
mime-types (3.6.0)
|
73
|
+
logger
|
58
74
|
mime-types-data (~> 3.2015)
|
59
|
-
mime-types-data (3.
|
60
|
-
minitest (5.
|
75
|
+
mime-types-data (3.2024.1105)
|
76
|
+
minitest (5.25.2)
|
61
77
|
nenv (0.3.0)
|
62
78
|
netrc (0.11.0)
|
63
79
|
notiffany (0.1.3)
|
64
80
|
nenv (~> 0.1)
|
65
81
|
shellany (~> 0.0)
|
66
|
-
pry (0.
|
82
|
+
pry (0.15.0)
|
67
83
|
coderay (~> 1.1)
|
68
84
|
method_source (~> 1.0)
|
69
|
-
public_suffix (
|
70
|
-
rake (13.
|
71
|
-
rb-fsevent (0.
|
72
|
-
rb-inotify (0.
|
85
|
+
public_suffix (6.0.1)
|
86
|
+
rake (13.2.1)
|
87
|
+
rb-fsevent (0.11.2)
|
88
|
+
rb-inotify (0.11.1)
|
73
89
|
ffi (~> 1.0)
|
74
90
|
rest-client (2.1.0)
|
75
91
|
http-accept (>= 1.7.0, < 2.0)
|
76
92
|
http-cookie (>= 1.0.2, < 2.0)
|
77
93
|
mime-types (>= 1.16, < 4.0)
|
78
94
|
netrc (~> 0.8)
|
79
|
-
rexml (3.
|
80
|
-
rspec (3.
|
81
|
-
rspec-core (~> 3.
|
82
|
-
rspec-expectations (~> 3.
|
83
|
-
rspec-mocks (~> 3.
|
84
|
-
rspec-core (3.
|
85
|
-
rspec-support (~> 3.
|
86
|
-
rspec-expectations (3.
|
95
|
+
rexml (3.3.9)
|
96
|
+
rspec (3.13.0)
|
97
|
+
rspec-core (~> 3.13.0)
|
98
|
+
rspec-expectations (~> 3.13.0)
|
99
|
+
rspec-mocks (~> 3.13.0)
|
100
|
+
rspec-core (3.13.2)
|
101
|
+
rspec-support (~> 3.13.0)
|
102
|
+
rspec-expectations (3.13.3)
|
87
103
|
diff-lcs (>= 1.2.0, < 2.0)
|
88
|
-
rspec-support (~> 3.
|
89
|
-
rspec-mocks (3.
|
104
|
+
rspec-support (~> 3.13.0)
|
105
|
+
rspec-mocks (3.13.2)
|
90
106
|
diff-lcs (>= 1.2.0, < 2.0)
|
91
|
-
rspec-support (~> 3.
|
107
|
+
rspec-support (~> 3.13.0)
|
92
108
|
rspec-nc (0.3.0)
|
93
109
|
rspec (>= 3)
|
94
110
|
terminal-notifier (>= 1.4)
|
95
|
-
rspec-support (3.
|
111
|
+
rspec-support (3.13.1)
|
112
|
+
securerandom (0.3.2)
|
96
113
|
shellany (0.0.1)
|
97
114
|
terminal-notifier (2.0.0)
|
98
|
-
thor (1.
|
99
|
-
tzinfo (2.0.
|
115
|
+
thor (1.3.2)
|
116
|
+
tzinfo (2.0.6)
|
100
117
|
concurrent-ruby (~> 1.0)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
webmock (3.12.2)
|
106
|
-
addressable (>= 2.3.6)
|
118
|
+
vcr (6.3.1)
|
119
|
+
base64
|
120
|
+
webmock (3.24.0)
|
121
|
+
addressable (>= 2.8.0)
|
107
122
|
crack (>= 0.3.2)
|
108
123
|
hashdiff (>= 0.4.0, < 2.0.0)
|
109
|
-
yajl-ruby (1.4.1)
|
110
|
-
zeitwerk (2.4.2)
|
111
124
|
|
112
125
|
PLATFORMS
|
113
126
|
ruby
|
114
127
|
|
115
128
|
DEPENDENCIES
|
116
|
-
bundler (~> 2.
|
117
|
-
|
129
|
+
bundler (~> 2.5.16)
|
130
|
+
faker (~> 3.5.1)
|
131
|
+
guard (~> 2.19)
|
118
132
|
guard-rspec (~> 4.7.3)
|
119
133
|
k2-connect-ruby!
|
120
|
-
rake (~> 13.
|
121
|
-
rspec (~> 3.
|
134
|
+
rake (~> 13.2.1)
|
135
|
+
rspec (~> 3.13.0)
|
122
136
|
rspec-nc (~> 0.3.0)
|
123
|
-
vcr (~> 6.
|
124
|
-
webmock (~> 3.
|
137
|
+
vcr (~> 6.3.1)
|
138
|
+
webmock (~> 3.24)
|
125
139
|
|
126
140
|
BUNDLED WITH
|
127
|
-
2.
|
141
|
+
2.5.16
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ All calls made without authentication will also fail.
|
|
25
25
|
- [SMS Notifications](#sms-notifications)
|
26
26
|
- [STK Push](#stk-push)
|
27
27
|
- [PAY](#pay)
|
28
|
+
- [Settlemennt accounts](#settlement-accounts)
|
28
29
|
- [Transfers](#transfers)
|
29
30
|
- [Polling](#polling)
|
30
31
|
- [Parsing the JSON Payload](#parsing-the-json-payload)
|
@@ -55,9 +56,21 @@ Add the require line to use the gem:
|
|
55
56
|
|
56
57
|
require 'k2-connect-ruby'
|
57
58
|
|
59
|
+
To set the base_url:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
K2ConnectRuby::K2Utilities::Config::K2Config.set_base_url("https://sandbox.kopokopo.com/")
|
63
|
+
```
|
64
|
+
|
65
|
+
To set the api version:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
K2ConnectRuby::K2Utilities::Config::K2Config.set_version(1)
|
69
|
+
```
|
70
|
+
|
58
71
|
### Authorization
|
59
72
|
|
60
|
-
Ensure you first Register your application with the [Kopo Kopo Sandbox](
|
73
|
+
Ensure you first Register your application with the [Kopo Kopo Sandbox](https://sandbox.kopokopo.com).
|
61
74
|
Once an application is registered you will obtain your `client_id` and `client_secret` (aka client credentials), which will be used to identify your application when calling the Kopo Kopo API.
|
62
75
|
|
63
76
|
For more Information, visit our [API docs]().
|
@@ -65,7 +78,7 @@ For more Information, visit our [API docs]().
|
|
65
78
|
In order to request for application authorization and receive an access token, we need to execute the client credentials flow, this is done so by having your application server make a HTTPS request to the Kopo Kopo authorization server, through the K2AccessToken class.
|
66
79
|
|
67
80
|
```ruby
|
68
|
-
k2_token =
|
81
|
+
k2_token = K2ConnectRuby::K2Entity::K2Token.new('your_client_id', 'your_client_secret').request_token
|
69
82
|
```
|
70
83
|
|
71
84
|
### Webhook Subscription
|
@@ -80,17 +93,16 @@ Ensure the following arguments are passed:
|
|
80
93
|
- scope reference: is `REQUIRED` if scope is till
|
81
94
|
|
82
95
|
Code example;
|
83
|
-
|
96
|
+
|
84
97
|
```ruby
|
85
98
|
require 'k2-connect-ruby'
|
86
|
-
k2_token =
|
87
|
-
k2subscriber = K2Subscribe.new(k2_token)
|
88
|
-
|
99
|
+
k2_token = K2ConnectRuby::K2Entity::K2Token.new('your_client_id', 'your_client_secret').request_token
|
100
|
+
k2subscriber = K2ConnectRuby::K2Entity::K2Subscribe.new(k2_token)
|
89
101
|
your_request = {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
102
|
+
event_type: 'buygoods_transaction_received',
|
103
|
+
url: callback_url,
|
104
|
+
scope: 'till',
|
105
|
+
scope_reference: '112233'
|
94
106
|
}
|
95
107
|
k2subscriber.webhook_subscribe(your_request)
|
96
108
|
```
|
@@ -107,13 +119,12 @@ Code example;
|
|
107
119
|
|
108
120
|
```ruby
|
109
121
|
require 'k2-connect-ruby'
|
110
|
-
k2_token =
|
111
|
-
k2_notification = K2Notification.new(k2_token)
|
112
|
-
|
122
|
+
k2_token = K2ConnectRuby::K2Entity::K2Token.new('your_client_id', 'your_client_secret').request_token
|
123
|
+
k2_notification = K2ConnectRuby::K2Entity::K2Notification.new(k2_token)
|
113
124
|
request_payload = {
|
114
|
-
|
115
|
-
|
116
|
-
|
125
|
+
webhook_event_reference: 'c271535c-687f-4a40-a589-8b66b894792e',
|
126
|
+
message: 'message',
|
127
|
+
callback_url: 'callback_url'
|
117
128
|
}
|
118
129
|
k2_notification.send_sms_transaction_notification(request_payload)
|
119
130
|
```
|
@@ -125,7 +136,7 @@ k2_notification.send_sms_transaction_notification(request_payload)
|
|
125
136
|
|
126
137
|
To receive payments from M-PESA users via STK Push we first create a K2Stk Object, passing the access_token that was created prior.
|
127
138
|
|
128
|
-
k2_stk = K2Stk.new(your_access_token)
|
139
|
+
k2_stk = K2ConnectRuby::K2Entity::K2Stk.new(your_access_token)
|
129
140
|
|
130
141
|
Afterwards we send a POST request for receiving Payments by calling the following method and passing the params value received from the POST Form Request:
|
131
142
|
|
@@ -159,7 +170,7 @@ As a result a JSON payload will be returned, accessible with the k2_response_bod
|
|
159
170
|
Code example;
|
160
171
|
|
161
172
|
```ruby
|
162
|
-
k2_stk = K2Stk.new(your_access_token)
|
173
|
+
k2_stk = K2ConnectRuby::K2Entity::K2Stk.new(your_access_token)
|
163
174
|
|
164
175
|
your_request = {
|
165
176
|
payment_channel: 'M-PESA',
|
@@ -181,7 +192,7 @@ k2_stk.query_resource(k2_stk.location_url)
|
|
181
192
|
First Create the K2Pay Object passing the access token
|
182
193
|
|
183
194
|
|
184
|
-
k2_pay = K2Pay.new(access_token)
|
195
|
+
k2_pay = K2ConnectRuby::K2Entity::K2Pay.new(access_token)
|
185
196
|
|
186
197
|
#### Add PAY Recipients
|
187
198
|
|
@@ -202,8 +213,20 @@ Add a PAY Recipient, with the following arguments:
|
|
202
213
|
- bank_branch_ref `REQUIRED`
|
203
214
|
- settlement_method: 'EFT' or 'RTS' `REQUIRED`
|
204
215
|
|
205
|
-
|
206
|
-
|
216
|
+
**Paybill** PAY Recipient
|
217
|
+
- type: 'paybill' `REQUIRED`
|
218
|
+
- paybill_name `REQUIRED`
|
219
|
+
- paybill_number `REQUIRED`
|
220
|
+
- paybill_account_number `REQUIRED`
|
221
|
+
|
222
|
+
**Till** PAY Recipient
|
223
|
+
- type: 'till' `REQUIRED`
|
224
|
+
- till_name `REQUIRED`
|
225
|
+
- till_number `REQUIRED`
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
k2_pay.add_recipients(your_input)
|
229
|
+
```
|
207
230
|
|
208
231
|
The type value can either be `mobile_wallet` or `bank_account`
|
209
232
|
|
@@ -221,6 +244,9 @@ The following arguments should be passed within a hash:
|
|
221
244
|
- destination_type `REQUIRED`
|
222
245
|
- currency default is `KES`
|
223
246
|
- value `REQUIRED`
|
247
|
+
- description `REQUIRED`
|
248
|
+
- category
|
249
|
+
- tags
|
224
250
|
- callback_url `REQUIRED`
|
225
251
|
|
226
252
|
A Successful Response is returned with the URL of the Payment resource in the HTTP Location Header.
|
@@ -246,10 +272,28 @@ As a result a JSON payload will be returned, accessible with the k2_response_bod
|
|
246
272
|
Code example;
|
247
273
|
|
248
274
|
```ruby
|
249
|
-
k2_pay = K2Pay.new(your_access_token)
|
275
|
+
k2_pay = K2ConnectRuby::K2Entity::K2Pay.new(your_access_token)
|
250
276
|
k2_pay.add_recipient(your_recipient_input)
|
251
277
|
k2_pay.query_resource(k2_pay.recipients_location_url)
|
252
|
-
|
278
|
+
|
279
|
+
your_request = {
|
280
|
+
destination_type: "mobile_wallet",
|
281
|
+
destination_reference: "example_reference",
|
282
|
+
amount: {
|
283
|
+
"currency": "KES",
|
284
|
+
"value": "500"
|
285
|
+
},
|
286
|
+
description: "k2-connect",
|
287
|
+
category: "general",
|
288
|
+
tags: ["tag_1", "tag_2"],
|
289
|
+
metadata: {
|
290
|
+
"something": "",
|
291
|
+
"something_else": "Something else"
|
292
|
+
},
|
293
|
+
_links: { "callback_url": "https://example.site/example" }
|
294
|
+
}
|
295
|
+
|
296
|
+
k2_pay.create_payment(your_request)
|
253
297
|
k2_pay.query_resource(k2_pay.payments_location_url)
|
254
298
|
```
|
255
299
|
|
@@ -273,7 +317,7 @@ Add pre-approved settlement accounts, to which one can transfer funds to. Can be
|
|
273
317
|
- settlement_method: 'EFT' or 'RTS' `REQUIRED`
|
274
318
|
|
275
319
|
```ruby
|
276
|
-
k2_settlement = K2Settlement.new(your_access_token)
|
320
|
+
k2_settlement = K2ConnectRuby::K2Entity::K2Settlement.new(your_access_token)
|
277
321
|
# Add a mobile merchant wallet
|
278
322
|
k2_settlement.add_settlement_account(merchant_wallet)
|
279
323
|
# Add a merchant bank account
|
@@ -286,7 +330,7 @@ This will Enable one to transfer funds to your settlement accounts.
|
|
286
330
|
|
287
331
|
First Create the K2Transfer Object
|
288
332
|
|
289
|
-
k2_transfers =
|
333
|
+
k2_transfers = K2ConnectRuby::K2Entity::K2Transfer.new(access_token)
|
290
334
|
|
291
335
|
#### Create Transfer Request
|
292
336
|
|
@@ -295,7 +339,7 @@ or one can have a `targeted` transfer with a specified settlement account in min
|
|
295
339
|
|
296
340
|
##### Blind Transfer
|
297
341
|
|
298
|
-
k2_transfers.transfer_funds(
|
342
|
+
k2_transfers.transfer_funds(params)
|
299
343
|
|
300
344
|
With `nil` representing that there are no specified destinations.
|
301
345
|
|
@@ -322,7 +366,7 @@ The Params are passed as the argument containing all the form data sent. A Succe
|
|
322
366
|
Sample code example:
|
323
367
|
|
324
368
|
```ruby
|
325
|
-
k2_transfer =
|
369
|
+
k2_transfer = K2ConnectRuby::K2Entity::K2Transfer.new(your_access_token)
|
326
370
|
# Blind or Targeted Transfer
|
327
371
|
k2_transfer.transfer_funds(your_input)
|
328
372
|
```
|
@@ -341,30 +385,35 @@ A HTTP Response will be returned in a JSON Payload, accessible with the k2_respo
|
|
341
385
|
|
342
386
|
### Polling
|
343
387
|
|
344
|
-
|
345
|
-
|
346
|
-
First Create the K2Notification Object
|
388
|
+
Allows you to poll transactions received on the Kopo Kopo system within a certain time range, and either for a company or a specific till.
|
347
389
|
|
348
|
-
|
390
|
+
First Create the K2Polling Object
|
349
391
|
|
350
|
-
|
392
|
+
k2_polling = K2ConnectRuby::K2Entity::K2Polling.new(access_token)
|
351
393
|
|
352
|
-
The
|
394
|
+
The following details should be passed:
|
353
395
|
|
354
|
-
- fromTime `REQUIRED`
|
355
|
-
- toTime `REQUIRED`
|
356
396
|
- scope `REQUIRED`
|
357
|
-
-
|
397
|
+
- scope_reference
|
398
|
+
- from_time `REQUIRED`
|
399
|
+
- to_time `REQUIRED`
|
358
400
|
- callback_url `REQUIRED`
|
359
401
|
|
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
402
|
Sample code example:
|
363
403
|
|
364
404
|
```ruby
|
365
|
-
|
366
|
-
|
367
|
-
|
405
|
+
your_input =
|
406
|
+
{
|
407
|
+
scope: "company",
|
408
|
+
scope_reference: "",
|
409
|
+
from_time: "2021-04-12T08:50:22+03:00",
|
410
|
+
to_time: "2021-04-19T08:50:22+03:00",
|
411
|
+
callback_url: 'https://call_back_to_your_app.your_application.com'
|
412
|
+
}
|
413
|
+
|
414
|
+
k2_polling = K2ConnectRuby::K2Entity::K2Polling.new("your_access_token")
|
415
|
+
k2_polling.poll(your_input)
|
416
|
+
k2_polling.location_url # => "https://sandbox.kopokopo.com/api/v1/polling/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c"
|
368
417
|
```
|
369
418
|
|
370
419
|
#### Query Request
|
@@ -388,7 +437,7 @@ K2ProcessResult Classes will be used.
|
|
388
437
|
|
389
438
|
First Create an Object of the K2Client class to Parse the response, passing the client_secret_key received from Kopo Kopo:
|
390
439
|
|
391
|
-
k2_parse = K2Client.new(client_secret)
|
440
|
+
k2_parse = K2ConnectRuby::K2Services::K2Client.new(client_secret)
|
392
441
|
|
393
442
|
###### Parse the request
|
394
443
|
|
@@ -398,14 +447,18 @@ First Create an Object of the K2Client class to Parse the response, passing the
|
|
398
447
|
|
399
448
|
Create an Object to receive the components resulting from processing the parsed request results which will be returned by the following method:
|
400
449
|
|
401
|
-
k2_components = K2ProcessResult.process(k2_parse.hash_body)
|
450
|
+
k2_components = K2ConnectRuby::K2Utilities::K2ProcessResult.process(k2_parse.hash_body, API_KEY, k2_parse.k2_signature)
|
451
|
+
|
452
|
+
or the parsed webhook results which will be returned by the following method:
|
453
|
+
|
454
|
+
k2_components = K2ConnectRuby::K2Utilities::K2ProcessWebhook.process(k2_parse.hash_body, API_KEY, k2_parse.k2_signature)
|
402
455
|
|
403
456
|
Code example:
|
404
457
|
|
405
458
|
```ruby
|
406
|
-
k2_parse = K2Client.new(
|
459
|
+
k2_parse = K2ConnectRuby::K2Services::K2Client.new(API_KEY)
|
407
460
|
k2_parse.parse_request(request)
|
408
|
-
k2_components = K2ProcessResult.process(k2_parse.hash_body)
|
461
|
+
k2_components = K2ConnectRuby::K2Utilities::K2ProcessResult.process(k2_parse.hash_body, API_KEY, k2_parse.k2_signature)
|
409
462
|
```
|
410
463
|
|
411
464
|
Below is a list of key symbols accessible for each of the Results retrieved after processing it into an Object.
|
@@ -501,23 +554,8 @@ k2_components = K2ProcessResult.process(k2_parse.hash_body)
|
|
501
554
|
- `links_self`
|
502
555
|
- `links_resource`
|
503
556
|
- `sending_till`
|
504
|
-
|
505
|
-
6. Merchant to Merchant Transaction:
|
506
|
-
- `id`
|
507
|
-
- `resource_id`
|
508
|
-
- `topic`
|
509
|
-
- `created_at`
|
510
|
-
- `event_type`
|
511
|
-
- `reference`
|
512
|
-
- `origination_time`
|
513
|
-
- `amount`
|
514
|
-
- `currency`
|
515
|
-
- `status`
|
516
|
-
- `links_self`
|
517
|
-
- `links_resource`
|
518
|
-
- `resource_sending_merchant`
|
519
557
|
|
520
|
-
|
558
|
+
6. Process STK Push Payment Request Result
|
521
559
|
- `id`
|
522
560
|
- `type`
|
523
561
|
- `initiation_time`
|
@@ -540,7 +578,7 @@ k2_components = K2ProcessResult.process(k2_parse.hash_body)
|
|
540
578
|
- `links_self`
|
541
579
|
- `callback_url`
|
542
580
|
|
543
|
-
|
581
|
+
7. Process PAY Result
|
544
582
|
- `id`
|
545
583
|
- `type`
|
546
584
|
- `created_at`
|
@@ -552,7 +590,7 @@ k2_components = K2ProcessResult.process(k2_parse.hash_body)
|
|
552
590
|
- `links_self`
|
553
591
|
- `callback_url`
|
554
592
|
|
555
|
-
|
593
|
+
8. Process Settlement Transfer Result
|
556
594
|
- `id`
|
557
595
|
- `type`
|
558
596
|
- `created_at`
|
@@ -567,13 +605,13 @@ If you want to convert the Object into a Hash or Array, the following methods ca
|
|
567
605
|
- Hash:
|
568
606
|
|
569
607
|
|
570
|
-
k2_hash_components = K2ProcessResult.return_obj_hash(k2_components)
|
608
|
+
k2_hash_components = K2ConnectRuby::K2Utilities::K2ProcessResult.return_obj_hash(k2_components)
|
571
609
|
|
572
610
|
|
573
611
|
- Array:
|
574
612
|
|
575
613
|
|
576
|
-
k2_array_components = K2ProcessResult.return_obj_array(k2_components)
|
614
|
+
k2_array_components = K2ConnectRuby::K2Utilities::K2ProcessResult.return_obj_array(k2_components)
|
577
615
|
|
578
616
|
|
579
617
|
Sample Web Application examples written in Rails and Sinatra frameworks that utilize this library are available in the example_app folder or in the following GitHub hyperlinks:
|
data/k2-connect-ruby.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = 'Ruby SDK for the Kopo Kopo K2 Connect API, with webhook subscriptions, STK Push, Pay and Settlement Transfer capabilities. Allows decomposition and break down of results and webhooks returned from the K2 Connect APIx``.'
|
13
13
|
spec.homepage = 'https://github.com/kopokopo/k2-connect-ruby.git'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '~>
|
15
|
+
spec.required_ruby_version = '~> 3.3.5'
|
16
16
|
|
17
17
|
|
18
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -38,16 +38,17 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.require_paths = ['lib']
|
39
39
|
|
40
40
|
|
41
|
-
spec.add_dependency 'activesupport', '~>
|
42
|
-
spec.add_dependency 'activemodel', '~>
|
43
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
44
|
-
spec.add_development_dependency "guard", '~> 2.16.2'
|
45
|
-
spec.add_development_dependency "guard-rspec", '~> 4.7.3'
|
41
|
+
spec.add_dependency 'activesupport', '~> 7.2.2'
|
42
|
+
spec.add_dependency 'activemodel', '~> 7.2.2'
|
46
43
|
spec.add_dependency 'rest-client', '~> 2.1.0'
|
47
|
-
spec.
|
48
|
-
spec.add_development_dependency '
|
44
|
+
spec.add_dependency 'json', '~> 2.8.2'
|
45
|
+
spec.add_development_dependency 'bundler', '~> 2.5.16'
|
46
|
+
spec.add_development_dependency "guard", '~> 2.19'
|
47
|
+
spec.add_development_dependency "guard-rspec", '~> 4.7.3'
|
48
|
+
spec.add_development_dependency 'rake', '~> 13.2.1'
|
49
|
+
spec.add_development_dependency 'rspec', '~> 3.13.0'
|
49
50
|
spec.add_development_dependency "rspec-nc", '~> 0.3.0'
|
50
|
-
spec.add_development_dependency 'vcr', '~> 6.
|
51
|
-
spec.add_development_dependency 'webmock', '~> 3.
|
52
|
-
spec.
|
51
|
+
spec.add_development_dependency 'vcr', '~> 6.3.1'
|
52
|
+
spec.add_development_dependency 'webmock', '~> 3.24'
|
53
|
+
spec.add_development_dependency 'faker', '~> 3.5.1'
|
53
54
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'k2-connect-ruby/k2_entity/k2_entity'
|
1
2
|
require 'k2-connect-ruby/k2_entity/k2_token'
|
2
3
|
require 'k2-connect-ruby/k2_entity/k2_polling'
|
3
4
|
require 'k2-connect-ruby/k2_entity/k2_subscribe'
|
@@ -6,3 +7,7 @@ require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk'
|
|
6
7
|
require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay'
|
7
8
|
require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer'
|
8
9
|
require 'k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement'
|
10
|
+
|
11
|
+
module K2ConnectRuby
|
12
|
+
module Entity; end
|
13
|
+
end
|
@@ -1,34 +1,32 @@
|
|
1
1
|
# Common Class Behaviours for stk, pay and transfers
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module K2ConnectRuby
|
3
|
+
module K2Entity
|
4
|
+
class K2Entity
|
5
|
+
attr_accessor :access_token, :the_array
|
6
|
+
attr_reader :k2_response_body, :query_hash, :location_url
|
7
|
+
include K2ConnectRuby::K2Utilities::K2Validation, K2ConnectRuby::K2Utilities
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
9
|
+
# Initialize with access token from Subscriber Class
|
10
|
+
def initialize(access_token)
|
11
|
+
@access_token = access_token
|
12
|
+
@exception_array = %w[authenticity_token]
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# Query/Check the status of a previously initiated request
|
16
|
+
def query_status(class_type, path_url)
|
17
|
+
query(class_type, path_url)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
# Query Location URL
|
21
|
+
def query_resource(class_type, url)
|
22
|
+
query(class_type, url)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
sleep 0.25
|
30
|
-
@k2_response_body = K2Connect.make_request(query_hash)
|
25
|
+
def query(class_type, path_url)
|
26
|
+
path_url = validate_url(path_url)
|
27
|
+
query_hash = make_hash(path_url, 'get', @access_token, class_type, nil)
|
28
|
+
@k2_response_body = K2ConnectRuby::K2Utilities::K2Connection.make_request(query_hash)
|
29
|
+
end
|
31
30
|
end
|
32
|
-
@threads.each(&:join)
|
33
31
|
end
|
34
32
|
end
|