mpesarb 0.3.1 → 0.3.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 +4 -4
- data/.github/workflows/mpesa.yml +2 -2
- data/.gitpod.yml +8 -0
- data/CHANGELOG.md +5 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +18 -38
- data/README.md +40 -1
- data/Rakefile +8 -6
- data/bin/console +8 -1
- data/lib/mpesa/client.rb +19 -5
- 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 +11 -0
- data/lib/mpesa/resources/balance.rb +2 -0
- data/lib/mpesa/resources/payout.rb +4 -2
- 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 +13 -7
- data/lib/mpesa/resources/token.rb +2 -0
- data/lib/mpesa/version.rb +3 -1
- data/lib/mpesa.rb +1 -0
- data/mpesa.gemspec +1 -2
- metadata +7 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 468884d21cb1bf62fff53e71c500cda1e315b84dfb84b6db029fb5cefffad542
|
|
4
|
+
data.tar.gz: b83e2ffadf87e97def39ab7bdc0d9ff31c5279ba98b33a42afce0592abf03e29
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ce05d2a42c251d92c6a85e6a1f03a698d7a6f7b83b834709ca56a4f983c2363101cf2712ad466197a74ae23bca4c34d59eda297d47174c3fa7b1bc9bd9ab4ac
|
|
7
|
+
data.tar.gz: e10df0ee91669afb21e04f2f0762dfb4eca1c86587d105cc65af33ba1631a09257571ab1b7e2add8e97e6c7ee426dccdc362de7a57a9f4248985964e0cae7807
|
data/.github/workflows/mpesa.yml
CHANGED
|
@@ -9,10 +9,10 @@ jobs:
|
|
|
9
9
|
|
|
10
10
|
steps:
|
|
11
11
|
- uses: actions/checkout@v1
|
|
12
|
-
- name: Set up Ruby 2.
|
|
12
|
+
- name: Set up Ruby 2.7
|
|
13
13
|
uses: actions/setup-ruby@v1
|
|
14
14
|
with:
|
|
15
|
-
ruby-version: 2.
|
|
15
|
+
ruby-version: 2.7.x
|
|
16
16
|
- name: Build and test with Rake
|
|
17
17
|
run: |
|
|
18
18
|
gem install bundler
|
data/.gitpod.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# This configuration file was automatically generated by Gitpod.
|
|
2
|
+
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
|
|
3
|
+
# and commit this file to your remote git repository to share the goodness with others.
|
|
4
|
+
|
|
5
|
+
tasks:
|
|
6
|
+
- init: bin/setup
|
|
7
|
+
|
|
8
|
+
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
mpesarb (0.3.
|
|
4
|
+
mpesarb (0.3.4)
|
|
5
5
|
activesupport (>= 5.0.0)
|
|
6
|
-
faraday (>=
|
|
7
|
-
faraday_middleware (~> 1.1)
|
|
6
|
+
faraday (>= 2.0.1)
|
|
8
7
|
openssl (>= 2.1)
|
|
9
8
|
|
|
10
9
|
GEM
|
|
11
10
|
remote: https://rubygems.org/
|
|
12
11
|
specs:
|
|
13
|
-
activesupport (
|
|
12
|
+
activesupport (7.0.3)
|
|
14
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
15
14
|
i18n (>= 1.6, < 2)
|
|
16
15
|
minitest (>= 5.1)
|
|
17
16
|
tzinfo (~> 2.0)
|
|
18
|
-
zeitwerk (~> 2.3)
|
|
19
17
|
addressable (2.8.0)
|
|
20
18
|
public_suffix (>= 2.0.2, < 5.0)
|
|
21
19
|
ansi (1.5.0)
|
|
22
20
|
builder (3.2.4)
|
|
23
21
|
byebug (11.1.3)
|
|
24
22
|
coderay (1.1.3)
|
|
25
|
-
concurrent-ruby (1.1.
|
|
23
|
+
concurrent-ruby (1.1.10)
|
|
26
24
|
coveralls (0.8.23)
|
|
27
25
|
json (>= 1.8, < 3)
|
|
28
26
|
simplecov (~> 0.16.1)
|
|
@@ -32,47 +30,29 @@ GEM
|
|
|
32
30
|
crack (0.4.5)
|
|
33
31
|
rexml
|
|
34
32
|
docile (1.4.0)
|
|
35
|
-
faraday (
|
|
36
|
-
faraday-
|
|
37
|
-
faraday-em_synchrony (~> 1.0)
|
|
38
|
-
faraday-excon (~> 1.1)
|
|
39
|
-
faraday-httpclient (~> 1.0.1)
|
|
40
|
-
faraday-net_http (~> 1.0)
|
|
41
|
-
faraday-net_http_persistent (~> 1.1)
|
|
42
|
-
faraday-patron (~> 1.0)
|
|
43
|
-
faraday-rack (~> 1.0)
|
|
44
|
-
multipart-post (>= 1.2, < 3)
|
|
33
|
+
faraday (2.3.0)
|
|
34
|
+
faraday-net_http (~> 2.0)
|
|
45
35
|
ruby2_keywords (>= 0.0.4)
|
|
46
|
-
faraday-
|
|
47
|
-
faraday-em_synchrony (1.0.0)
|
|
48
|
-
faraday-excon (1.1.0)
|
|
49
|
-
faraday-httpclient (1.0.1)
|
|
50
|
-
faraday-net_http (1.0.1)
|
|
51
|
-
faraday-net_http_persistent (1.2.0)
|
|
52
|
-
faraday-patron (1.0.0)
|
|
53
|
-
faraday-rack (1.0.0)
|
|
54
|
-
faraday_middleware (1.1.0)
|
|
55
|
-
faraday (~> 1.0)
|
|
36
|
+
faraday-net_http (2.0.3)
|
|
56
37
|
hashdiff (1.0.1)
|
|
57
|
-
i18n (1.
|
|
38
|
+
i18n (1.10.0)
|
|
58
39
|
concurrent-ruby (~> 1.0)
|
|
59
|
-
json (2.
|
|
40
|
+
json (2.6.2)
|
|
60
41
|
method_source (1.0.0)
|
|
61
|
-
minitest (5.
|
|
62
|
-
minitest-reporters (1.
|
|
42
|
+
minitest (5.15.0)
|
|
43
|
+
minitest-reporters (1.5.0)
|
|
63
44
|
ansi
|
|
64
45
|
builder
|
|
65
46
|
minitest (>= 5.0)
|
|
66
47
|
ruby-progressbar
|
|
67
|
-
|
|
68
|
-
openssl (2.2.0)
|
|
48
|
+
openssl (3.0.0)
|
|
69
49
|
pry (0.13.1)
|
|
70
50
|
coderay (~> 1.1)
|
|
71
51
|
method_source (~> 1.0)
|
|
72
52
|
pry-byebug (3.9.0)
|
|
73
53
|
byebug (~> 11.0)
|
|
74
54
|
pry (~> 0.13.0)
|
|
75
|
-
public_suffix (4.0.
|
|
55
|
+
public_suffix (4.0.7)
|
|
76
56
|
rake (13.0.6)
|
|
77
57
|
rexml (3.2.5)
|
|
78
58
|
ruby-progressbar (1.11.0)
|
|
@@ -85,20 +65,20 @@ GEM
|
|
|
85
65
|
sync (0.5.0)
|
|
86
66
|
term-ansicolor (1.7.1)
|
|
87
67
|
tins (~> 1.0)
|
|
88
|
-
thor (1.1
|
|
89
|
-
tins (1.
|
|
68
|
+
thor (1.2.1)
|
|
69
|
+
tins (1.31.1)
|
|
90
70
|
sync
|
|
91
71
|
tzinfo (2.0.4)
|
|
92
72
|
concurrent-ruby (~> 1.0)
|
|
93
|
-
vcr (6.
|
|
73
|
+
vcr (6.1.0)
|
|
94
74
|
webmock (3.14.0)
|
|
95
75
|
addressable (>= 2.8.0)
|
|
96
76
|
crack (>= 0.3.2)
|
|
97
77
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
98
|
-
zeitwerk (2.4.2)
|
|
99
78
|
|
|
100
79
|
PLATFORMS
|
|
101
80
|
x86_64-darwin-19
|
|
81
|
+
x86_64-darwin-20
|
|
102
82
|
|
|
103
83
|
DEPENDENCIES
|
|
104
84
|
bundler (>= 2.1.4)
|
|
@@ -113,4 +93,4 @@ DEPENDENCIES
|
|
|
113
93
|
webmock (~> 3.7)
|
|
114
94
|
|
|
115
95
|
BUNDLED WITH
|
|
116
|
-
2.2.
|
|
96
|
+
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
|
|
@@ -42,6 +42,7 @@ Optional
|
|
|
42
42
|
- `adapter` - Faraday HTTP adapter. Default `:net_http`
|
|
43
43
|
- `shortcode` - Mpesa shortcode
|
|
44
44
|
- `pass_key` - LPNMO pass Key( used by STK API)
|
|
45
|
+
- `raise_errors` - `Boolean` raise errors if response status code is not 200. Default: `true`
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
### Register Urls
|
|
@@ -100,6 +101,44 @@ respose.ResponseDescription # "Accept the service request successfully."
|
|
|
100
101
|
|
|
101
102
|
```
|
|
102
103
|
|
|
104
|
+
### Transaction Status
|
|
105
|
+
Check Transation Status
|
|
106
|
+
|
|
107
|
+
```rb
|
|
108
|
+
response = client.status(
|
|
109
|
+
shortcode: '600426',
|
|
110
|
+
transaction_id: 'OEI2AK4Q16',
|
|
111
|
+
identifier_type: 1,
|
|
112
|
+
initiator_username: 'testapi',
|
|
113
|
+
initiator_password: 'Safaricom426!',
|
|
114
|
+
timeout_url: 'https://example.com/result',
|
|
115
|
+
result_url: 'https://example.com/result'
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
response.ConversationID
|
|
119
|
+
response.ResponseCode
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Reversal
|
|
123
|
+
Initiate a reversal
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
response = client.reversal(
|
|
127
|
+
initiator_password: 'Safaricom426!',
|
|
128
|
+
initiator_username: 'testapi',
|
|
129
|
+
transaction_id: 'OEI2AK4Q16',
|
|
130
|
+
amount: '100',
|
|
131
|
+
receiver: '600610',
|
|
132
|
+
receiver_type: '4',
|
|
133
|
+
timeout_url: 'https://example.com/result',
|
|
134
|
+
result_url: 'https://example.com/result'
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
response.ConversationID
|
|
138
|
+
response.ResponseCode
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
|
|
103
142
|
|
|
104
143
|
## Development
|
|
105
144
|
|
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,17 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'faraday'
|
|
2
|
-
require 'faraday_middleware'
|
|
3
4
|
|
|
4
5
|
module Mpesa
|
|
5
6
|
class Client
|
|
6
|
-
attr_reader :key, :secret, :env, :adapter, :shortcode, :pass_key
|
|
7
|
+
attr_reader :key, :secret, :env, :adapter, :shortcode, :pass_key, :raise_errors
|
|
7
8
|
|
|
8
|
-
def initialize(key:, secret:, shortcode: nil, pass_key: nil, env: 'production', adapter: Faraday.default_adapter)
|
|
9
|
+
def initialize(key:, secret:, shortcode: nil, pass_key: nil, env: 'production', adapter: Faraday.default_adapter, raise_errors: true)
|
|
9
10
|
@key = key
|
|
10
11
|
@secret = secret
|
|
11
12
|
@env = env
|
|
12
13
|
@adapter = adapter
|
|
13
14
|
@pass_key = pass_key
|
|
14
15
|
@shortcode = shortcode
|
|
16
|
+
@raise_errors = raise_errors
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def auth
|
|
@@ -30,14 +32,26 @@ 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"
|
|
36
50
|
conn.request :json
|
|
37
51
|
conn.response :json, content_type: 'application/json'
|
|
38
52
|
conn.adapter adapter
|
|
39
|
-
conn.request :
|
|
40
|
-
conn.request :authorization,
|
|
53
|
+
conn.request :authorization, :basic, key, secret if basic_auth
|
|
54
|
+
conn.request :authorization, 'Bearer', auth.access_token unless basic_auth
|
|
41
55
|
end
|
|
42
56
|
end
|
|
43
57
|
|
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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mpesa
|
|
2
4
|
class Resource
|
|
3
5
|
attr_reader :client, :args
|
|
@@ -16,6 +18,8 @@ module Mpesa
|
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def handle_response(response)
|
|
21
|
+
return response unless client.raise_errors
|
|
22
|
+
|
|
19
23
|
case response.status
|
|
20
24
|
when 400
|
|
21
25
|
raise Error, "Your request was malformed. #{response.body['errorMessage']}"
|
|
@@ -30,5 +34,12 @@ module Mpesa
|
|
|
30
34
|
end
|
|
31
35
|
response
|
|
32
36
|
end
|
|
37
|
+
|
|
38
|
+
def format_phone(phone)
|
|
39
|
+
phone = phone.to_s
|
|
40
|
+
return phone if phone.match?(/\A254/)
|
|
41
|
+
|
|
42
|
+
phone.sub(/\A[+0]?(254)?(\d+)/, '254\2')
|
|
43
|
+
end
|
|
33
44
|
end
|
|
34
45
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mpesa
|
|
2
4
|
class Payout < Resource
|
|
3
|
-
PATH = 'mpesa/b2c/v1/paymentrequest'
|
|
5
|
+
PATH = 'mpesa/b2c/v1/paymentrequest'
|
|
4
6
|
|
|
5
7
|
def call
|
|
6
8
|
Object.new post_request(url: PATH, body: body).body
|
|
@@ -13,7 +15,7 @@ module Mpesa
|
|
|
13
15
|
'CommandID': args[:command_id],
|
|
14
16
|
'Amount': args[:amount],
|
|
15
17
|
'PartyA': client.shortcode || args[:shortcode],
|
|
16
|
-
'PartyB': args[:phone],
|
|
18
|
+
'PartyB': format_phone(args[:phone]),
|
|
17
19
|
'Remarks': args[:remarks],
|
|
18
20
|
'QueueTimeOutURL': args[:timeout_url],
|
|
19
21
|
'ResultURL': args[:result_url],
|
|
@@ -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,14 +12,14 @@ module Mpesa
|
|
|
10
12
|
|
|
11
13
|
def body
|
|
12
14
|
{
|
|
13
|
-
'BusinessShortCode':
|
|
15
|
+
'BusinessShortCode': shortcode,
|
|
14
16
|
'Password': password,
|
|
15
|
-
'Timestamp': timestamp
|
|
17
|
+
'Timestamp': timestamp,
|
|
16
18
|
'TransactionType': 'CustomerPayBillOnline',
|
|
17
19
|
'Amount': args[:amount],
|
|
18
|
-
'PartyA': args[:phone],
|
|
19
|
-
'PartyB':
|
|
20
|
-
'PhoneNumber': args[:phone],
|
|
20
|
+
'PartyA': format_phone(args[:phone]),
|
|
21
|
+
'PartyB': shortcode,
|
|
22
|
+
'PhoneNumber': format_phone(args[:phone]),
|
|
21
23
|
'CallBackURL': args[:callback_url],
|
|
22
24
|
'AccountReference': args[:reference],
|
|
23
25
|
'TransactionDesc': args[:trans_desc]
|
|
@@ -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
|
-
Time.now.strftime('%Y%m%d%H%M%S')
|
|
34
|
+
Time.now.strftime('%Y%m%d%H%M%S')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def shortcode
|
|
38
|
+
args[:shortcode] || client.shortcode
|
|
33
39
|
end
|
|
34
40
|
end
|
|
35
41
|
end
|
data/lib/mpesa/version.rb
CHANGED
data/lib/mpesa.rb
CHANGED
data/mpesa.gemspec
CHANGED
|
@@ -31,8 +31,7 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
spec.add_development_dependency 'rake', '>= 12.3'
|
|
32
32
|
# dependancies
|
|
33
33
|
spec.add_runtime_dependency 'activesupport', '>= 5.0.0'
|
|
34
|
-
spec.add_runtime_dependency 'faraday', '>=
|
|
35
|
-
spec.add_runtime_dependency 'faraday_middleware', '~> 1.1'
|
|
34
|
+
spec.add_runtime_dependency 'faraday', '>= 2.0.1'
|
|
36
35
|
spec.add_runtime_dependency 'openssl', '>= 2.1'
|
|
37
36
|
# request
|
|
38
37
|
spec.add_development_dependency 'minitest'
|
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.4
|
|
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-06-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -58,28 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: 2.0.1
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: faraday_middleware
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '1.1'
|
|
76
|
-
type: :runtime
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '1.1'
|
|
68
|
+
version: 2.0.1
|
|
83
69
|
- !ruby/object:Gem::Dependency
|
|
84
70
|
name: openssl
|
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -201,6 +187,7 @@ extra_rdoc_files: []
|
|
|
201
187
|
files:
|
|
202
188
|
- ".github/workflows/mpesa.yml"
|
|
203
189
|
- ".gitignore"
|
|
190
|
+
- ".gitpod.yml"
|
|
204
191
|
- ".travis.yml"
|
|
205
192
|
- CHANGELOG.md
|
|
206
193
|
- CODE_OF_CONDUCT.md
|
|
@@ -224,6 +211,7 @@ files:
|
|
|
224
211
|
- lib/mpesa/resources/balance.rb
|
|
225
212
|
- lib/mpesa/resources/payout.rb
|
|
226
213
|
- lib/mpesa/resources/register.rb
|
|
214
|
+
- lib/mpesa/resources/reversal.rb
|
|
227
215
|
- lib/mpesa/resources/status.rb
|
|
228
216
|
- lib/mpesa/resources/stk.rb
|
|
229
217
|
- lib/mpesa/resources/token.rb
|
|
@@ -252,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
252
240
|
- !ruby/object:Gem::Version
|
|
253
241
|
version: '0'
|
|
254
242
|
requirements: []
|
|
255
|
-
rubygems_version: 3.
|
|
243
|
+
rubygems_version: 3.3.7
|
|
256
244
|
signing_key:
|
|
257
245
|
specification_version: 4
|
|
258
246
|
summary: a simple gem to integrate ruby with mpesa Apis
|