mpesa_connect 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -6
- data/_config.yml +1 -0
- data/lib/{access_token.rb → mpesa_connect/access_token.rb} +3 -0
- data/lib/mpesa_connect/security_credentials.rb +22 -0
- data/lib/mpesa_connect/version.rb +1 -1
- data/lib/mpesa_connect.rb +2 -7
- data/lib/security_credentials.rb +1 -0
- data/mpesa_connect.gemspec +6 -6
- metadata +41 -23
- data/lib/cert.cer +0 -38
- data/lib/pubkey.pem +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a4a20dc87bdebda47d40c9d6a5b39841c9f585e
|
4
|
+
data.tar.gz: bed0265698be8b6c7daab87024d942910e5921a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e2bb0c34147dad9123649f220b97d6db15df974cee8bfed09bf651c87d60d66660636b83615ce3632bb2248add3cb0989839cf52b0ede3c10f6129b110a1661
|
7
|
+
data.tar.gz: 28942b47292806c5736ec2617370e7f568d13b2eba03cd7593c84a653a50e2ee9980927b8289896a7bc165086ac1ac2f1ce7054d23a6a621d9f0b65abd5d57d9
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# MpesaConnect
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Gem built as ruby wrapper to handle transactions with with the [Safaricom M-Pesa APIs](https://developer.safaricom.co.ke/docs).
|
4
|
+
You will need to have a developer Account on [Safaricom Developer](https://developer.safaricom.co.ke/docs). Portal to run in sandbox environments.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,7 +21,60 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
```ruby
|
25
|
+
require 'mpesa_connect'
|
26
|
+
```
|
27
|
+
|
28
|
+
Values you need from your Safaricom app
|
29
|
+
|
30
|
+
- `key` and `secret`: Credentials for an approved app.
|
31
|
+
- `security_password`: Generated Encryption Security Credential from the sandbox tool (Shortcode 1).
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = MpesaConnect::Client.new(key, secret, security_password)
|
35
|
+
```
|
36
|
+
|
37
|
+
Set the urls that will be used to send response back to your app
|
38
|
+
|
39
|
+
- `timeout_url` : The callback URL that handles information of timed out transactions
|
40
|
+
- `transaction_url`: The callback URL that handles a successful request and handles responses.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
client.set_urls(timeout_url, transaction_url)
|
44
|
+
```
|
45
|
+
|
46
|
+
For each of the functions you will need data from Test Credentials:
|
47
|
+
|
48
|
+
- `Initiator` : This is the credential/username used to authenticate the transaction request.
|
49
|
+
- `PartyA` : Short code for party initiating the transaction.
|
50
|
+
- `PartyB` : Organization/MSISDN(phone number) sending the transaction.
|
51
|
+
- `Receiver_party`: Identifier types - receiver - identify an M-Pesa transaction’s receiving party as either a shortcode, a till number or a MSISDN (phone number).
|
52
|
+
|
53
|
+
### Account Balance
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
client.account_balance(initiator, party_a)
|
57
|
+
```
|
58
|
+
|
59
|
+
### Reversal
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
client.reversal(initiator, transaction_id, amount, receiver_party)
|
63
|
+
```
|
64
|
+
|
65
|
+
### Transaction Status
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
client.transaction_status(initiator, party_a, transaction_id)
|
69
|
+
```
|
70
|
+
|
71
|
+
### B2C Transaction
|
72
|
+
|
73
|
+
Salary Payment
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
client.b2c_transaction(initiator, amount, party_a, party_b)
|
77
|
+
```
|
26
78
|
|
27
79
|
## Development
|
28
80
|
|
@@ -32,7 +84,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
84
|
|
33
85
|
## Contributing
|
34
86
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mboya/mpesa_connect. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
88
|
|
37
89
|
## License
|
38
90
|
|
@@ -40,4 +92,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
40
92
|
|
41
93
|
## Code of Conduct
|
42
94
|
|
43
|
-
Everyone interacting in the MpesaConnect project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
95
|
+
Everyone interacting in the MpesaConnect project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mboya/mpesa_connect/blob/master/CODE_OF_CONDUCT.md).
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'pry-nav'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module MpesaConnect
|
6
|
+
class SecurityCredentials
|
7
|
+
|
8
|
+
def initialize security_cred
|
9
|
+
@security_cred = security_cred
|
10
|
+
end
|
11
|
+
|
12
|
+
def encrypt_security_cred
|
13
|
+
byte_array = @security_cred.bytes.to_a.to_s
|
14
|
+
key_file = "lib/pubkey.pem"
|
15
|
+
public_key = File.read(key_file)
|
16
|
+
ssl = OpenSSL::PKey::RSA.new(public_key)
|
17
|
+
|
18
|
+
encrypted_string = Base64.encode64(ssl.public_encrypt(byte_array)).split("\n").join
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/mpesa_connect.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
require "mpesa_connect/version"
|
2
|
-
require '
|
3
|
-
require 'redis'
|
2
|
+
require 'mpesa_connect/access_token'
|
4
3
|
require 'httparty'
|
5
|
-
require 'openssl'
|
6
|
-
require 'access_token'
|
7
|
-
require 'security_credentials'
|
8
4
|
|
9
5
|
module MpesaConnect
|
10
6
|
class Client
|
11
7
|
BASE_URL = "https://sandbox.safaricom.co.ke"
|
12
|
-
BALANCE_URL = "https://sandbox.safaricom.co.ke/mpesa/accountbalance/v1/query"
|
13
8
|
|
14
9
|
def initialize key, secret, security_credentials
|
15
10
|
@key = key
|
@@ -152,7 +147,7 @@ module MpesaConnect
|
|
152
147
|
|
153
148
|
private
|
154
149
|
def get_token
|
155
|
-
AccessToken.new(@key, @secret).access_token
|
150
|
+
MpesaConnect::AccessToken.new(@key, @secret).access_token
|
156
151
|
end
|
157
152
|
|
158
153
|
def encrypted_security_password
|
data/lib/security_credentials.rb
CHANGED
data/mpesa_connect.gemspec
CHANGED
@@ -30,13 +30,13 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency
|
34
|
-
spec.add_dependency
|
35
|
-
spec.add_dependency
|
33
|
+
spec.add_dependency 'httparty', '~> 0.15.6'
|
34
|
+
spec.add_dependency 'redis-rack', '~> 2.0', '>= 2.0.2'
|
35
|
+
spec.add_dependency 'redis-namespace', '~> 1.5', '>= 1.5.3'
|
36
36
|
spec.add_development_dependency "bundler", "~> 1.15"
|
37
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
38
38
|
spec.add_development_dependency "minitest", "~> 5.0"
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
41
|
-
spec.add_development_dependency
|
39
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
40
|
+
spec.add_development_dependency 'pry-nav', '~> 0.2.4'
|
41
|
+
spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
|
42
42
|
end
|
metadata
CHANGED
@@ -1,57 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpesa_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mboya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.15.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.15.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redis-rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
36
|
+
version: 2.0.2
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.0'
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 2.0.2
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: redis-namespace
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.5'
|
45
54
|
- - ">="
|
46
55
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
56
|
+
version: 1.5.3
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.5'
|
52
64
|
- - ">="
|
53
65
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
66
|
+
version: 1.5.3
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: bundler
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,44 +110,50 @@ dependencies:
|
|
98
110
|
name: pry
|
99
111
|
requirement: !ruby/object:Gem::Requirement
|
100
112
|
requirements:
|
101
|
-
- - "
|
113
|
+
- - "~>"
|
102
114
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
115
|
+
version: 0.10.4
|
104
116
|
type: :development
|
105
117
|
prerelease: false
|
106
118
|
version_requirements: !ruby/object:Gem::Requirement
|
107
119
|
requirements:
|
108
|
-
- - "
|
120
|
+
- - "~>"
|
109
121
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
122
|
+
version: 0.10.4
|
111
123
|
- !ruby/object:Gem::Dependency
|
112
124
|
name: pry-nav
|
113
125
|
requirement: !ruby/object:Gem::Requirement
|
114
126
|
requirements:
|
115
|
-
- - "
|
127
|
+
- - "~>"
|
116
128
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
129
|
+
version: 0.2.4
|
118
130
|
type: :development
|
119
131
|
prerelease: false
|
120
132
|
version_requirements: !ruby/object:Gem::Requirement
|
121
133
|
requirements:
|
122
|
-
- - "
|
134
|
+
- - "~>"
|
123
135
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
136
|
+
version: 0.2.4
|
125
137
|
- !ruby/object:Gem::Dependency
|
126
138
|
name: webmock
|
127
139
|
requirement: !ruby/object:Gem::Requirement
|
128
140
|
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '3.0'
|
129
144
|
- - ">="
|
130
145
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
146
|
+
version: 3.0.1
|
132
147
|
type: :development
|
133
148
|
prerelease: false
|
134
149
|
version_requirements: !ruby/object:Gem::Requirement
|
135
150
|
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '3.0'
|
136
154
|
- - ">="
|
137
155
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
156
|
+
version: 3.0.1
|
139
157
|
description: connect to Mpesa API to perform available transactions
|
140
158
|
email:
|
141
159
|
- mboyaberry@gmail.com
|
@@ -151,13 +169,13 @@ files:
|
|
151
169
|
- LICENSE.txt
|
152
170
|
- README.md
|
153
171
|
- Rakefile
|
172
|
+
- _config.yml
|
154
173
|
- bin/console
|
155
174
|
- bin/setup
|
156
|
-
- lib/access_token.rb
|
157
|
-
- lib/cert.cer
|
158
175
|
- lib/mpesa_connect.rb
|
176
|
+
- lib/mpesa_connect/access_token.rb
|
177
|
+
- lib/mpesa_connect/security_credentials.rb
|
159
178
|
- lib/mpesa_connect/version.rb
|
160
|
-
- lib/pubkey.pem
|
161
179
|
- lib/security_credentials.rb
|
162
180
|
- mpesa_connect.gemspec
|
163
181
|
homepage: https://mboya.github.io/mpesa_connect/
|
data/lib/cert.cer
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
-----BEGIN CERTIFICATE-----
|
2
|
-
MIIGkzCCBXugAwIBAgIKXfBp5gAAAD+hNjANBgkqhkiG9w0BAQsFADBbMRMwEQYK
|
3
|
-
CZImiZPyLGQBGRYDbmV0MRkwFwYKCZImiZPyLGQBGRYJc2FmYXJpY29tMSkwJwYD
|
4
|
-
VQQDEyBTYWZhcmljb20gSW50ZXJuYWwgSXNzdWluZy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