mpesarb 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +10 -7
- data/README.md +39 -1
- data/Rakefile +8 -6
- data/bin/console +8 -1
- data/lib/mpesa/client.rb +14 -0
- data/lib/mpesa/error.rb +2 -0
- data/lib/mpesa/object.rb +8 -0
- data/lib/mpesa/objects/instace.rb +2 -0
- data/lib/mpesa/resource.rb +2 -0
- data/lib/mpesa/resources/balance.rb +2 -0
- data/lib/mpesa/resources/payout.rb +3 -1
- data/lib/mpesa/resources/register.rb +3 -1
- data/lib/mpesa/resources/reversal.rb +31 -0
- data/lib/mpesa/resources/status.rb +16 -1
- data/lib/mpesa/resources/stk.rb +9 -3
- data/lib/mpesa/resources/token.rb +2 -0
- data/lib/mpesa/version.rb +3 -1
- data/lib/mpesa.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f58f3c8c8bb861948c8c2418733a9dea0ab7d51de6be5a8366503c4d778c9949
|
4
|
+
data.tar.gz: 79cdd313fc5da2e6aa4d01cbc399a4756726949d353285991ed6ec7a6a75d33b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c8ca8bbf672b89f9fc73516000e487397f9e5aec26c35e0d12131a5e1e9a28519adc3f4bd4dad5d29304794f2052c765a68009d7ce1e47e2e91a557735629e8
|
7
|
+
data.tar.gz: bff2fd36423ad9d2601a4b5f733c1644dc00cc82ba5a33c5b49e87c3f5916533cf75496d80a72476d4cc4fb7c4bff5468175affd9f5891053f963be96402c77c
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mpesarb (0.3.
|
4
|
+
mpesarb (0.3.1)
|
5
5
|
activesupport (>= 5.0.0)
|
6
6
|
faraday (>= 1.1)
|
7
7
|
faraday_middleware (~> 1.1)
|
@@ -10,7 +10,7 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (6.1.4)
|
13
|
+
activesupport (6.1.4.1)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
16
|
minitest (>= 5.1)
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
crack (0.4.5)
|
33
33
|
rexml
|
34
34
|
docile (1.4.0)
|
35
|
-
faraday (1.
|
35
|
+
faraday (1.8.0)
|
36
36
|
faraday-em_http (~> 1.0)
|
37
37
|
faraday-em_synchrony (~> 1.0)
|
38
38
|
faraday-excon (~> 1.1)
|
@@ -51,11 +51,12 @@ GEM
|
|
51
51
|
faraday-net_http_persistent (1.2.0)
|
52
52
|
faraday-patron (1.0.0)
|
53
53
|
faraday-rack (1.0.0)
|
54
|
-
faraday_middleware (1.
|
54
|
+
faraday_middleware (1.2.0)
|
55
55
|
faraday (~> 1.0)
|
56
56
|
hashdiff (1.0.1)
|
57
57
|
i18n (1.8.10)
|
58
58
|
concurrent-ruby (~> 1.0)
|
59
|
+
ipaddr (1.2.3)
|
59
60
|
json (2.5.1)
|
60
61
|
method_source (1.0.0)
|
61
62
|
minitest (5.14.4)
|
@@ -65,7 +66,8 @@ GEM
|
|
65
66
|
minitest (>= 5.0)
|
66
67
|
ruby-progressbar
|
67
68
|
multipart-post (2.1.1)
|
68
|
-
openssl (2.2.
|
69
|
+
openssl (2.2.1)
|
70
|
+
ipaddr
|
69
71
|
pry (0.13.1)
|
70
72
|
coderay (~> 1.1)
|
71
73
|
method_source (~> 1.0)
|
@@ -95,10 +97,11 @@ GEM
|
|
95
97
|
addressable (>= 2.8.0)
|
96
98
|
crack (>= 0.3.2)
|
97
99
|
hashdiff (>= 0.4.0, < 2.0.0)
|
98
|
-
zeitwerk (2.
|
100
|
+
zeitwerk (2.5.1)
|
99
101
|
|
100
102
|
PLATFORMS
|
101
103
|
x86_64-darwin-19
|
104
|
+
x86_64-darwin-20
|
102
105
|
|
103
106
|
DEPENDENCIES
|
104
107
|
bundler (>= 2.1.4)
|
@@ -113,4 +116,4 @@ DEPENDENCIES
|
|
113
116
|
webmock (~> 3.7)
|
114
117
|
|
115
118
|
BUNDLED WITH
|
116
|
-
2.2.
|
119
|
+
2.2.27
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ This Gem provides an interface that developers can use to convert JSON to `OpenS
|
|
12
12
|
|
13
13
|
Install via `Gemfile`
|
14
14
|
```
|
15
|
-
gem 'mpesarb', '~> 0.3.
|
15
|
+
gem 'mpesarb', '~> 0.3.2'
|
16
16
|
```
|
17
17
|
|
18
18
|
Or
|
@@ -100,6 +100,44 @@ respose.ResponseDescription # "Accept the service request successfully."
|
|
100
100
|
|
101
101
|
```
|
102
102
|
|
103
|
+
### Transaction Status
|
104
|
+
Check Transation Status
|
105
|
+
|
106
|
+
```rb
|
107
|
+
response = client.status(
|
108
|
+
shortcode: '600426',
|
109
|
+
transaction_id: 'OEI2AK4Q16',
|
110
|
+
identifier_type: 1,
|
111
|
+
initiator_username: 'testapi',
|
112
|
+
initiator_password: 'Safaricom426!',
|
113
|
+
timeout_url: 'https://example.com/result',
|
114
|
+
result_url: 'https://example.com/result'
|
115
|
+
)
|
116
|
+
|
117
|
+
response.ConversationID
|
118
|
+
response.ResponseCode
|
119
|
+
```
|
120
|
+
|
121
|
+
### Reversal
|
122
|
+
Initiate a reversal
|
123
|
+
|
124
|
+
```
|
125
|
+
response = client.reversal(
|
126
|
+
initiator_password: 'Safaricom426!',
|
127
|
+
initiator_username: 'testapi',
|
128
|
+
transaction_id: 'OEI2AK4Q16',
|
129
|
+
amount: '100',
|
130
|
+
receiver: '600610',
|
131
|
+
receiver_type: '4',
|
132
|
+
timeout_url: 'https://example.com/result',
|
133
|
+
result_url: 'https://example.com/result'
|
134
|
+
)
|
135
|
+
|
136
|
+
response.ConversationID
|
137
|
+
response.ResponseCode
|
138
|
+
|
139
|
+
```
|
140
|
+
|
103
141
|
|
104
142
|
## Development
|
105
143
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
12
|
+
task default: :test
|
data/bin/console
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'bundler/setup'
|
4
5
|
require 'mpesa'
|
@@ -10,7 +11,13 @@ require 'mpesa'
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
client = Mpesa::Client.new(
|
14
|
+
client = Mpesa::Client.new(
|
15
|
+
key: 'ZtkRW6ATbVtFpNml5w5SfG26Adfyagn9',
|
16
|
+
secret: 'dosFI1yQ8bvHEVFw',
|
17
|
+
env: 'sandbox',
|
18
|
+
shortcode: '174379',
|
19
|
+
pass_key: 'bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919'
|
20
|
+
)
|
14
21
|
|
15
22
|
require 'irb'
|
16
23
|
IRB.start(__FILE__)
|
data/lib/mpesa/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'faraday_middleware'
|
3
5
|
|
@@ -30,6 +32,18 @@ module Mpesa
|
|
30
32
|
Payout.new(self, args).call
|
31
33
|
end
|
32
34
|
|
35
|
+
def status(**args)
|
36
|
+
Status.new(self, args).call
|
37
|
+
end
|
38
|
+
|
39
|
+
def balance(**args)
|
40
|
+
Balance.new(self, args).call
|
41
|
+
end
|
42
|
+
|
43
|
+
def reversal(**args)
|
44
|
+
Reversal.new(self, args).call
|
45
|
+
end
|
46
|
+
|
33
47
|
def connection(basic_auth: false)
|
34
48
|
@connection ||= Faraday.new do |conn|
|
35
49
|
conn.url_prefix = "https://#{subdomain}.safaricom.co.ke"
|
data/lib/mpesa/error.rb
CHANGED
data/lib/mpesa/object.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'ostruct'
|
2
4
|
|
3
5
|
module Mpesa
|
4
6
|
class Object
|
7
|
+
attr_reader :attributes
|
8
|
+
|
5
9
|
def initialize(attributes)
|
6
10
|
@attributes = OpenStruct.new(attributes)
|
7
11
|
end
|
@@ -14,5 +18,9 @@ module Mpesa
|
|
14
18
|
def respond_to_missing?(_method, _include_private = false)
|
15
19
|
true
|
16
20
|
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
attributes.to_h
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
data/lib/mpesa/resource.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mpesa
|
4
|
+
class Reversal < Resource
|
5
|
+
PATH = 'mpesa/reversal/v1/request'
|
6
|
+
|
7
|
+
def call
|
8
|
+
Object.new post_request(url: PATH, body: body).body
|
9
|
+
end
|
10
|
+
|
11
|
+
def body
|
12
|
+
{
|
13
|
+
"Initiator": args[:initiator_username],
|
14
|
+
"SecurityCredential": credentials,
|
15
|
+
"CommandID": 'TransactionReversal',
|
16
|
+
"TransactionID": args[:transaction_id],
|
17
|
+
"Amount": args[:amount],
|
18
|
+
"ReceiverParty": args[:receiver],
|
19
|
+
"RecieverIdentifierType": args[:receiver_type],
|
20
|
+
"Remarks": args[:remarks] || 'check status',
|
21
|
+
"QueueTimeOutURL": args[:timeout_url],
|
22
|
+
"ResultURL": args[:result_url],
|
23
|
+
"Occasion": args[:occasion] || 'check status'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def credentials
|
28
|
+
SecurityCred.new(args[:initiator_password], client.env).password_credential
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mpesa
|
2
4
|
class Status < Resource
|
3
5
|
PATH = 'mpesa/transactionstatus/v1/query'
|
@@ -7,8 +9,21 @@ module Mpesa
|
|
7
9
|
|
8
10
|
def body
|
9
11
|
{
|
10
|
-
|
12
|
+
"CommandID": 'TransactionStatusQuery',
|
13
|
+
"PartyA": args[:shortcode] || client.shortcode,
|
14
|
+
"IdentifierType": args[:identifier_type],
|
15
|
+
"Remarks": args[:remarks] || 'check status',
|
16
|
+
"Initiator": args[:initiator_username],
|
17
|
+
"SecurityCredential": credentials,
|
18
|
+
"QueueTimeOutURL": args[:timeout_url],
|
19
|
+
"ResultURL": args[:result_url],
|
20
|
+
"TransactionID": args[:transaction_id],
|
21
|
+
"Occasion": args[:occasion] || 'check status'
|
11
22
|
}
|
12
23
|
end
|
24
|
+
|
25
|
+
def credentials
|
26
|
+
SecurityCred.new(args[:initiator_password], client.env).password_credential
|
27
|
+
end
|
13
28
|
end
|
14
29
|
end
|
data/lib/mpesa/resources/stk.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'base64'
|
2
4
|
|
3
5
|
module Mpesa
|
@@ -10,13 +12,13 @@ module Mpesa
|
|
10
12
|
|
11
13
|
def body
|
12
14
|
{
|
13
|
-
'BusinessShortCode':
|
15
|
+
'BusinessShortCode': shortcode,
|
14
16
|
'Password': password,
|
15
17
|
'Timestamp': timestamp.to_s,
|
16
18
|
'TransactionType': 'CustomerPayBillOnline',
|
17
19
|
'Amount': args[:amount],
|
18
20
|
'PartyA': args[:phone],
|
19
|
-
'PartyB':
|
21
|
+
'PartyB': shortcode,
|
20
22
|
'PhoneNumber': args[:phone],
|
21
23
|
'CallBackURL': args[:callback_url],
|
22
24
|
'AccountReference': args[:reference],
|
@@ -25,11 +27,15 @@ module Mpesa
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def password
|
28
|
-
Base64.strict_encode64("#{
|
30
|
+
Base64.strict_encode64("#{shortcode}#{args[:pass_key] || client.pass_key}#{timestamp}")
|
29
31
|
end
|
30
32
|
|
31
33
|
def timestamp
|
32
34
|
Time.now.strftime('%Y%m%d%H%M%S').to_i
|
33
35
|
end
|
36
|
+
|
37
|
+
def shortcode
|
38
|
+
args[:shortcode] || client.shortcode
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/mpesa/version.rb
CHANGED
data/lib/mpesa.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpesarb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moses Gathuku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- lib/mpesa/resources/balance.rb
|
225
225
|
- lib/mpesa/resources/payout.rb
|
226
226
|
- lib/mpesa/resources/register.rb
|
227
|
+
- lib/mpesa/resources/reversal.rb
|
227
228
|
- lib/mpesa/resources/status.rb
|
228
229
|
- lib/mpesa/resources/stk.rb
|
229
230
|
- lib/mpesa/resources/token.rb
|