pesapal 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.travis.yml +4 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +100 -0
- data/README.md +39 -41
- data/lib/generators/pesapal/install_generator.rb +1 -5
- data/lib/generators/templates/pesapal.yml +4 -4
- data/lib/pesapal.rb +10 -9
- data/lib/pesapal/merchant.rb +24 -72
- data/lib/pesapal/merchant/details.rb +1 -1
- data/lib/pesapal/merchant/post.rb +2 -2
- data/lib/pesapal/merchant/status.rb +1 -1
- data/lib/pesapal/railtie.rb +19 -0
- data/lib/pesapal/version.rb +1 -1
- data/pesapal.gemspec +15 -14
- data/spec/pesapal_merchant_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -0
- metadata +28 -7
- data/lib/generators/templates/pesapal.rb +0 -2
- data/lib/pesapal/configuration.rb +0 -15
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
v1.5.0
|
5
|
+
------
|
6
|
+
|
7
|
+
* Remove `path_to_file` second constructor parameter, make constructor simpler
|
8
|
+
* Remove Rails specific code to Railtie, create fallbacks if using in a non-Rails environment
|
9
|
+
* Change and improve how credentials are loaded
|
10
|
+
* Require `net/http`, used by `Net::HTTP` (bug fix)
|
11
|
+
* Added to travis-ci for continuous integrations
|
12
|
+
* Added to gemnasium for dependency checking
|
13
|
+
* Write basic tests
|
14
|
+
|
15
|
+
v1.4.0
|
16
|
+
------
|
17
|
+
|
18
|
+
* Makes more sense if mode,@mode variables were env,@env
|
19
|
+
|
4
20
|
v1.3.0
|
5
21
|
------
|
6
22
|
|
data/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# bundler will include dependencies specified in
|
4
|
-
# practice to specify all the gems that our library depends on
|
5
|
-
gemspec
|
3
|
+
# bundler will include dependencies specified in pesapal.gemspec too. it's best
|
4
|
+
# practice to specify all the gems that our library depends on, there.
|
5
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pesapal (1.5.0)
|
5
|
+
htmlentities
|
6
|
+
rails
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.0.2)
|
12
|
+
actionpack (= 4.0.2)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (4.0.2)
|
15
|
+
activesupport (= 4.0.2)
|
16
|
+
builder (~> 3.1.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
rack (~> 1.5.2)
|
19
|
+
rack-test (~> 0.6.2)
|
20
|
+
activemodel (4.0.2)
|
21
|
+
activesupport (= 4.0.2)
|
22
|
+
builder (~> 3.1.0)
|
23
|
+
activerecord (4.0.2)
|
24
|
+
activemodel (= 4.0.2)
|
25
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
26
|
+
activesupport (= 4.0.2)
|
27
|
+
arel (~> 4.0.0)
|
28
|
+
activerecord-deprecated_finders (1.0.3)
|
29
|
+
activesupport (4.0.2)
|
30
|
+
i18n (~> 0.6, >= 0.6.4)
|
31
|
+
minitest (~> 4.2)
|
32
|
+
multi_json (~> 1.3)
|
33
|
+
thread_safe (~> 0.1)
|
34
|
+
tzinfo (~> 0.3.37)
|
35
|
+
arel (4.0.1)
|
36
|
+
atomic (1.1.14)
|
37
|
+
builder (3.1.4)
|
38
|
+
diff-lcs (1.2.5)
|
39
|
+
erubis (2.7.0)
|
40
|
+
hike (1.2.3)
|
41
|
+
htmlentities (4.3.1)
|
42
|
+
i18n (0.6.9)
|
43
|
+
mail (2.5.4)
|
44
|
+
mime-types (~> 1.16)
|
45
|
+
treetop (~> 1.4.8)
|
46
|
+
mime-types (1.25.1)
|
47
|
+
minitest (4.7.5)
|
48
|
+
multi_json (1.8.2)
|
49
|
+
polyglot (0.3.3)
|
50
|
+
rack (1.5.2)
|
51
|
+
rack-test (0.6.2)
|
52
|
+
rack (>= 1.0)
|
53
|
+
rails (4.0.2)
|
54
|
+
actionmailer (= 4.0.2)
|
55
|
+
actionpack (= 4.0.2)
|
56
|
+
activerecord (= 4.0.2)
|
57
|
+
activesupport (= 4.0.2)
|
58
|
+
bundler (>= 1.3.0, < 2.0)
|
59
|
+
railties (= 4.0.2)
|
60
|
+
sprockets-rails (~> 2.0.0)
|
61
|
+
railties (4.0.2)
|
62
|
+
actionpack (= 4.0.2)
|
63
|
+
activesupport (= 4.0.2)
|
64
|
+
rake (>= 0.8.7)
|
65
|
+
thor (>= 0.18.1, < 2.0)
|
66
|
+
rake (10.1.0)
|
67
|
+
rspec (2.14.1)
|
68
|
+
rspec-core (~> 2.14.0)
|
69
|
+
rspec-expectations (~> 2.14.0)
|
70
|
+
rspec-mocks (~> 2.14.0)
|
71
|
+
rspec-core (2.14.7)
|
72
|
+
rspec-expectations (2.14.4)
|
73
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
74
|
+
rspec-mocks (2.14.4)
|
75
|
+
sprockets (2.10.1)
|
76
|
+
hike (~> 1.2)
|
77
|
+
multi_json (~> 1.0)
|
78
|
+
rack (~> 1.0)
|
79
|
+
tilt (~> 1.1, != 1.3.0)
|
80
|
+
sprockets-rails (2.0.1)
|
81
|
+
actionpack (>= 3.0)
|
82
|
+
activesupport (>= 3.0)
|
83
|
+
sprockets (~> 2.8)
|
84
|
+
thor (0.18.1)
|
85
|
+
thread_safe (0.1.3)
|
86
|
+
atomic
|
87
|
+
tilt (1.4.1)
|
88
|
+
treetop (1.4.15)
|
89
|
+
polyglot
|
90
|
+
polyglot (>= 0.3.1)
|
91
|
+
tzinfo (0.3.38)
|
92
|
+
|
93
|
+
PLATFORMS
|
94
|
+
ruby
|
95
|
+
|
96
|
+
DEPENDENCIES
|
97
|
+
bundler (~> 1.5.2)
|
98
|
+
pesapal!
|
99
|
+
rake
|
100
|
+
rspec (~> 2.14.1)
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@ Pesapal RubyGem
|
|
2
2
|
===============
|
3
3
|
|
4
4
|
<a href="http://badge.fury.io/rb/pesapal"><img src="https://badge.fury.io/rb/pesapal@2x.png" alt="Gem Version" height="18"></a>
|
5
|
+
[![Build Status](https://travis-ci.org/itsmrwave/pesapal-rubygem.png?branch=master)](https://travis-ci.org/itsmrwave/pesapal-rubygem)
|
6
|
+
[![Dependency Status](https://gemnasium.com/itsmrwave/pesapal-rubygem.png)](https://gemnasium.com/itsmrwave/pesapal-rubygem)
|
7
|
+
|
5
8
|
|
6
9
|
Make authenticated Pesapal API calls without the fuss! Handles all the [oAuth
|
7
10
|
stuff][1] abstracting any direct interaction with the API endpoints so that you
|
@@ -39,8 +42,7 @@ Or install it yourself as:
|
|
39
42
|
|
40
43
|
$ gem install pesapal
|
41
44
|
|
42
|
-
For Rails, you need to run the generator to
|
43
|
-
initializer and config.yml file):
|
45
|
+
For Rails, you need to run the generator to create sample pesapal.yml file:
|
44
46
|
|
45
47
|
rails generate pesapal:install
|
46
48
|
|
@@ -51,50 +53,51 @@ Usage
|
|
51
53
|
|
52
54
|
### Initialization ###
|
53
55
|
|
54
|
-
There are
|
56
|
+
There are 2 ways to initialize the Pesapal object:
|
55
57
|
|
56
|
-
1. YAML config at `/config/pesapal.yml`
|
57
|
-
2.
|
58
|
-
3. Config hash
|
58
|
+
1. YAML config at `/config/pesapal.yml`
|
59
|
+
2. Config hash
|
59
60
|
|
60
|
-
Initialize Pesapal object and choose the
|
61
|
+
Initialize Pesapal object and choose the environment, there are two environments;
|
61
62
|
`:development` and `:production`. They determine if the code will interact
|
62
63
|
with the testing or the live Pesapal API.
|
63
64
|
|
64
65
|
```ruby
|
65
|
-
#
|
66
|
+
# defaults to :auto
|
67
|
+
pesapal = Pesapal::Merchant.new
|
68
|
+
|
69
|
+
# Set to :development
|
66
70
|
pesapal = Pesapal::Merchant.new(:development)
|
71
|
+
|
72
|
+
# Set to :production
|
73
|
+
pesapal = Pesapal::Merchant.new(:production)
|
74
|
+
|
75
|
+
# Set to Rails environment in use
|
76
|
+
pesapal = Pesapal::Merchant.new(Rails.env)
|
77
|
+
|
78
|
+
# Set to intelligently to 'Rails.env' (if Rails) or :development (if non-Rails)
|
79
|
+
pesapal = Pesapal::Merchant.new(:auto)
|
67
80
|
```
|
68
81
|
|
69
82
|
####Option 1####
|
70
83
|
|
71
84
|
In the above case, the configuration has already been loaded (at application
|
72
|
-
start by initializer) from a YAML file located at
|
73
|
-
|
85
|
+
start by initializer) from a YAML file located at `"/config/pesapal.yml"`. The
|
86
|
+
appropriate credentials are picked depending on set environment.
|
74
87
|
|
75
|
-
This is the recommended method.
|
88
|
+
This is the recommended method if using Rails.
|
76
89
|
|
77
|
-
####Option 2####
|
78
90
|
|
79
|
-
|
80
|
-
location of your choice upon initialization as shown in the example below. This
|
81
|
-
option overrides the default YAML config (explained above) and will be loaded
|
82
|
-
everytime during initialization (which is not a good idea for production).
|
83
|
-
|
84
|
-
```ruby
|
85
|
-
# initiate pesapal object set to development mode and use the YAML file found at
|
86
|
-
# the specified location ... this overrides and loads the YAML file afresh
|
87
|
-
pesapal = Pesapal::Merchant.new(:development, "<PATH_TO_YAML_FILE>")
|
88
|
-
```
|
91
|
+
####Option 2####
|
89
92
|
|
90
|
-
|
93
|
+
If you do not wish to use the YAML config method then the object is set up with
|
94
|
+
some bogus credentials which would not work anyway and therefore, the other
|
95
|
+
option is that you set them yourself. Which, you can do using a hash as shown
|
96
|
+
below (please note that Pesapal provides different keys for different
|
97
|
+
environments and since this is like an override, there's the assumption that you
|
98
|
+
chose the right one).
|
91
99
|
|
92
|
-
|
93
|
-
does not exist, then the object is set up with some bogus credentials which
|
94
|
-
would not work anyway and therefore, the other option is that you set them
|
95
|
-
yourself. Which, you can do using a hash as shown below (please note that
|
96
|
-
Pesapal provides different keys for different modes and since this is like an
|
97
|
-
override, there's the assumption that you chose the right one).
|
100
|
+
Recommended if not using Rails.
|
98
101
|
|
99
102
|
```ruby
|
100
103
|
# set pesapal api configuration manually (override YAML & bogus credentials)
|
@@ -104,8 +107,9 @@ pesapal.config = { :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
|
|
104
107
|
}
|
105
108
|
```
|
106
109
|
|
107
|
-
_Ps: You can change the
|
108
|
-
for some reason you want to override what was set in the
|
110
|
+
_Ps: You can change the environment using `pesapal.set_env(:development)`
|
111
|
+
(example) if for some reason you want to override what was set in the
|
112
|
+
constructor. This method also changes the API endpoints appropriately._
|
109
113
|
|
110
114
|
|
111
115
|
###YAML Configuration###
|
@@ -117,21 +121,15 @@ them appropriately.
|
|
117
121
|
```yaml
|
118
122
|
development:
|
119
123
|
callback_url: 'http://0.0.0.0:3000/pesapal/callback'
|
120
|
-
consumer_key: '<
|
121
|
-
consumer_secret: '<
|
124
|
+
consumer_key: '<YOUR_DEV_CONSUMER_KEY>'
|
125
|
+
consumer_secret: '<YOUR_DEV_CONSUMER_SECRET>'
|
122
126
|
|
123
127
|
production:
|
124
128
|
callback_url: 'http://1.2.3.4:3000/pesapal/callback'
|
125
|
-
consumer_key: '<
|
126
|
-
consumer_secret: '<
|
129
|
+
consumer_key: '<YOUR_PROD_CONSUMER_KEY>'
|
130
|
+
consumer_secret: '<YOUR_PROD_CONSUMER_SECRET>'
|
127
131
|
```
|
128
132
|
|
129
|
-
_Ps: Immediately after initializing the Pesapal object, some people might find
|
130
|
-
it peculiar that the `pesapal.config` is an empty hash i.e. `{}`. Don't worry.
|
131
|
-
If you have set up the `pesapal.yml` correctly, any attempt to run any of the
|
132
|
-
methods will eventually populate this hash with the values that were loaded by
|
133
|
-
the initializer (see option #1 above, stated as the default)._
|
134
|
-
|
135
133
|
|
136
134
|
### Posting An Order ###
|
137
135
|
|
@@ -9,13 +9,9 @@ module Pesapal
|
|
9
9
|
copy_file "pesapal.yml", "config/pesapal.yml"
|
10
10
|
end
|
11
11
|
|
12
|
-
def copy_initializer
|
13
|
-
copy_file "pesapal.rb", "config/initializers/pesapal.rb"
|
14
|
-
end
|
15
|
-
|
16
12
|
def show_readme
|
17
13
|
readme "README.md" if behavior == :invoke
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
21
|
-
end
|
17
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
development:
|
2
2
|
callback_url: 'http://0.0.0.0:3000/pesapal/callback'
|
3
|
-
consumer_key: '<
|
4
|
-
consumer_secret: '<
|
3
|
+
consumer_key: '<YOUR_DEV_CONSUMER_KEY>'
|
4
|
+
consumer_secret: '<YOUR_DEV_CONSUMER_SECRET>'
|
5
5
|
|
6
6
|
production:
|
7
7
|
callback_url: 'http://1.2.3.4:3000/pesapal/callback'
|
8
|
-
consumer_key: '<
|
9
|
-
consumer_secret: '<
|
8
|
+
consumer_key: '<YOUR_PROD_CONSUMER_KEY>'
|
9
|
+
consumer_secret: '<YOUR_PROD_CONSUMER_SECRET>'
|
data/lib/pesapal.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
require 'pesapal/merchant'
|
4
|
+
require 'pesapal/merchant/details'
|
5
|
+
require 'pesapal/merchant/post'
|
6
|
+
require 'pesapal/merchant/status'
|
7
|
+
require 'pesapal/oauth'
|
8
|
+
require 'pesapal/version'
|
9
|
+
|
10
|
+
require 'pesapal/railtie' if defined?(Rails)
|
10
11
|
|
data/lib/pesapal/merchant.rb
CHANGED
@@ -22,51 +22,37 @@ module Pesapal
|
|
22
22
|
@api_endpoints
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
@
|
25
|
+
def env
|
26
|
+
@env
|
27
27
|
end
|
28
28
|
|
29
29
|
def params
|
30
|
-
@params
|
30
|
+
@params ||= nil
|
31
31
|
end
|
32
32
|
|
33
33
|
def post_xml
|
34
|
-
@post_xml
|
34
|
+
@post_xml ||= nil
|
35
35
|
end
|
36
36
|
|
37
37
|
def token_secret
|
38
|
-
@token_secret
|
38
|
+
@token_secret ||= nil
|
39
39
|
end
|
40
40
|
|
41
41
|
public
|
42
42
|
|
43
43
|
# constructor
|
44
|
-
def initialize(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
set_mode mode
|
52
|
-
|
53
|
-
# set the credentials if we have specified a path from which we
|
54
|
-
# will access a YAML file with the configurations
|
55
|
-
unless path_to_file.nil?
|
56
|
-
set_configuration_from_yaml path_to_file
|
44
|
+
def initialize(env = :auto)
|
45
|
+
set_env env
|
46
|
+
if defined?(Rails)
|
47
|
+
set_configuration Rails.application.config.pesapal_credentials
|
48
|
+
else
|
49
|
+
set_configuration
|
57
50
|
end
|
58
|
-
|
59
51
|
end
|
60
52
|
|
61
53
|
# generate pesapal order url (often iframed)
|
62
54
|
def generate_order_url
|
63
55
|
|
64
|
-
# check if the config is empty, if yes, we try load what was set by the
|
65
|
-
# initializer into Pesapal.config
|
66
|
-
if config.empty?
|
67
|
-
set_configuration Pesapal.config[@mode]
|
68
|
-
end
|
69
|
-
|
70
56
|
# build xml with input data, the format is standard so no editing is
|
71
57
|
# required
|
72
58
|
@post_xml = Pesapal::Post::generate_post_xml @order_details
|
@@ -86,12 +72,6 @@ module Pesapal
|
|
86
72
|
# query the details of the transaction
|
87
73
|
def query_payment_details(merchant_reference, transaction_tracking_id)
|
88
74
|
|
89
|
-
# check if the config is empty, if yes, we try load what was set by the
|
90
|
-
# initializer into Pesapal.config
|
91
|
-
if config.empty?
|
92
|
-
set_configuration Pesapal.config[@mode]
|
93
|
-
end
|
94
|
-
|
95
75
|
# initialize setting of @params (oauth_signature left empty)
|
96
76
|
@params = Pesapal::Details::set_parameters(@config[:consumer_key], merchant_reference, transaction_tracking_id)
|
97
77
|
|
@@ -115,12 +95,6 @@ module Pesapal
|
|
115
95
|
# query the status of the transaction
|
116
96
|
def query_payment_status(merchant_reference, transaction_tracking_id = nil)
|
117
97
|
|
118
|
-
# check if the config is empty, if yes, we try load what was set by the
|
119
|
-
# initializer into Pesapal.config
|
120
|
-
if config.empty?
|
121
|
-
set_configuration Pesapal.config[@mode]
|
122
|
-
end
|
123
|
-
|
124
98
|
# initialize setting of @params (oauth_signature left empty)
|
125
99
|
@params = Pesapal::Status::set_parameters(@config[:consumer_key], merchant_reference, transaction_tracking_id)
|
126
100
|
|
@@ -138,13 +112,17 @@ module Pesapal
|
|
138
112
|
response["pesapal_response_data"][0]
|
139
113
|
end
|
140
114
|
|
141
|
-
# set
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
115
|
+
# set env when called
|
116
|
+
def set_env(env = :auto)
|
117
|
+
env = env.to_s.downcase
|
118
|
+
if env == 'development'
|
119
|
+
@env = 'development'
|
120
|
+
elsif env == 'production'
|
121
|
+
@env = 'production'
|
122
|
+
else
|
123
|
+
@env = 'development'
|
124
|
+
@env = Rails.env if defined?(Rails)
|
125
|
+
end
|
148
126
|
set_endpoints
|
149
127
|
end
|
150
128
|
|
@@ -171,7 +149,7 @@ module Pesapal
|
|
171
149
|
# set endpoints
|
172
150
|
def set_endpoints
|
173
151
|
|
174
|
-
if @
|
152
|
+
if @env == 'production'
|
175
153
|
@api_domain = 'https://www.pesapal.com'
|
176
154
|
else
|
177
155
|
@api_domain = 'http://demo.pesapal.com'
|
@@ -190,37 +168,11 @@ module Pesapal
|
|
190
168
|
@config = { :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
|
191
169
|
:consumer_key => '<YOUR_CONSUMER_KEY>',
|
192
170
|
:consumer_secret => '<YOUR_CONSUMER_SECRET>'
|
193
|
-
|
171
|
+
}
|
194
172
|
|
195
173
|
valid_config_keys = @config.keys
|
196
174
|
|
197
175
|
consumer_details.each { |k,v| @config[k.to_sym] = v if valid_config_keys.include? k.to_sym }
|
198
176
|
end
|
199
|
-
|
200
|
-
# set configuration through yaml file
|
201
|
-
def set_configuration_from_yaml(path_to_file)
|
202
|
-
|
203
|
-
if File.exist?(path_to_file)
|
204
|
-
|
205
|
-
# load file, read it and parse the YAML
|
206
|
-
begin
|
207
|
-
loaded_config = YAML::load(IO.read(path_to_file))
|
208
|
-
rescue Errno::ENOENT
|
209
|
-
logger.info("YAML configuration file couldn't be found. Using defaults."); return
|
210
|
-
rescue Psych::SyntaxError
|
211
|
-
logger.info("YAML configuration file contains invalid syntax. Using defaults."); return
|
212
|
-
end
|
213
|
-
|
214
|
-
# pick the correct settings depending on the the mode and set it
|
215
|
-
# appropriately. this file is expected to have the settings for
|
216
|
-
# development and production
|
217
|
-
set_configuration loaded_config[@mode]
|
218
|
-
|
219
|
-
else
|
220
|
-
|
221
|
-
# in this case default values will be set
|
222
|
-
set_configuration
|
223
|
-
end
|
224
|
-
end
|
225
177
|
end
|
226
178
|
end
|
@@ -3,7 +3,7 @@ module Pesapal
|
|
3
3
|
module Details
|
4
4
|
|
5
5
|
# set parameters required by the QueryPaymentDetails call
|
6
|
-
def
|
6
|
+
def self.set_parameters(consumer_key, merchant_reference, transaction_tracking_id)
|
7
7
|
|
8
8
|
# parameters required by the QueryPaymentDetails call (excludes
|
9
9
|
# oauth_signature parameter as per the instructions here
|
@@ -3,7 +3,7 @@ module Pesapal
|
|
3
3
|
module Post
|
4
4
|
|
5
5
|
# build html encoded xml string for PostPesapalDirectOrderV4
|
6
|
-
def
|
6
|
+
def self.generate_post_xml(details)
|
7
7
|
|
8
8
|
# build xml with input data, the format is standard so no editing is
|
9
9
|
# required
|
@@ -30,7 +30,7 @@ module Pesapal
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# set parameters required by the PostPesapalDirectOrderV4 call
|
33
|
-
def
|
33
|
+
def self.set_parameters(callback_url, consumer_key, post_xml)
|
34
34
|
|
35
35
|
# parameters required by the PostPesapalDirectOrderV4 call (excludes
|
36
36
|
# oauth_signature parameter as per the instructions here
|
@@ -3,7 +3,7 @@ module Pesapal
|
|
3
3
|
module Status
|
4
4
|
|
5
5
|
# set parameters required by the QueryPaymentStatus & QueryPaymentStatusByMerchantRef calls
|
6
|
-
def
|
6
|
+
def self.set_parameters(consumer_key, merchant_reference, transaction_tracking_id = nil)
|
7
7
|
|
8
8
|
# parameters required by the QueryPaymentStatus call (excludes
|
9
9
|
# oauth_signature parameter as per the instructions here
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Pesapal
|
2
|
+
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
|
5
|
+
initializer 'pesapal.load_credentials' do
|
6
|
+
|
7
|
+
path_to_yaml = "#{Rails.root}/config/pesapal.yml"
|
8
|
+
if File.exist?(path_to_yaml)
|
9
|
+
begin
|
10
|
+
config.pesapal_credentials = YAML::load(IO.read(path_to_yaml))[Rails.env]
|
11
|
+
rescue Errno::ENOENT
|
12
|
+
logger.info('YAML configuration file couldn\'t be found. Using defaults.'); return
|
13
|
+
rescue Psych::SyntaxError
|
14
|
+
logger.info('YAML configuration file contains invalid syntax. Will use using defaults.'); return
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/pesapal/version.rb
CHANGED
data/pesapal.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
lib = File.expand_path(
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
3
|
+
require 'pesapal/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
6
|
+
spec.name = 'pesapal'
|
7
7
|
spec.version = Pesapal::VERSION
|
8
|
-
spec.date = Time.new.getlocal(
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
8
|
+
spec.date = Time.new.getlocal('+03:00').strftime('%Y-%m-%d')
|
9
|
+
spec.authors = ['Job King\'ori Maina']
|
10
|
+
spec.email = ['j@kingori.co']
|
11
|
+
spec.description = 'Make authenticated Pesapal API calls without the fuss!'
|
12
|
+
spec.summary = 'Make authenticated Pesapal API calls without the fuss! Handles all the oAuth stuff abstracting any direct interaction with the API endpoints so that you can focus on what matters. Building awesome.'
|
13
|
+
spec.homepage = 'http://rubydoc.info/gems/pesapal/'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5.2'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.14.1'
|
23
24
|
|
24
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency 'htmlentities'
|
25
26
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pesapal::Merchant do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@pesapal = Pesapal::Merchant.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#new' do
|
10
|
+
|
11
|
+
# Check if the initializer successfully sets a Pesapal::Merchant object
|
12
|
+
it 'returns a new instance of a pesapal object' do
|
13
|
+
@pesapal.should be_an_instance_of Pesapal::Merchant
|
14
|
+
end
|
15
|
+
|
16
|
+
# Checks if the initialized object is properly set with default credentials
|
17
|
+
it 'checks if config is set with the default credentials' do
|
18
|
+
@pesapal.config.should == { :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
|
19
|
+
:consumer_key => '<YOUR_CONSUMER_KEY>',
|
20
|
+
:consumer_secret => '<YOUR_CONSUMER_SECRET>'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Checks if the initialized object is properly set with empty order details
|
25
|
+
it 'checks if config is set with the default credentials' do
|
26
|
+
@pesapal.order_details.should == {}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../lib/pesapal'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pesapal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.5.2
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.5.2
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.14.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: htmlentities
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,24 +83,27 @@ extensions: []
|
|
67
83
|
extra_rdoc_files: []
|
68
84
|
files:
|
69
85
|
- .gitignore
|
86
|
+
- .travis.yml
|
70
87
|
- CHANGELOG.md
|
71
88
|
- Gemfile
|
89
|
+
- Gemfile.lock
|
72
90
|
- LICENSE.txt
|
73
91
|
- README.md
|
74
92
|
- Rakefile
|
75
93
|
- lib/generators/pesapal/install_generator.rb
|
76
94
|
- lib/generators/templates/README.md
|
77
|
-
- lib/generators/templates/pesapal.rb
|
78
95
|
- lib/generators/templates/pesapal.yml
|
79
96
|
- lib/pesapal.rb
|
80
|
-
- lib/pesapal/configuration.rb
|
81
97
|
- lib/pesapal/merchant.rb
|
82
98
|
- lib/pesapal/merchant/details.rb
|
83
99
|
- lib/pesapal/merchant/post.rb
|
84
100
|
- lib/pesapal/merchant/status.rb
|
85
101
|
- lib/pesapal/oauth.rb
|
102
|
+
- lib/pesapal/railtie.rb
|
86
103
|
- lib/pesapal/version.rb
|
87
104
|
- pesapal.gemspec
|
105
|
+
- spec/pesapal_merchant_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
88
107
|
homepage: http://rubydoc.info/gems/pesapal/
|
89
108
|
licenses:
|
90
109
|
- MIT
|
@@ -112,4 +131,6 @@ specification_version: 3
|
|
112
131
|
summary: Make authenticated Pesapal API calls without the fuss! Handles all the oAuth
|
113
132
|
stuff abstracting any direct interaction with the API endpoints so that you can
|
114
133
|
focus on what matters. Building awesome.
|
115
|
-
test_files:
|
134
|
+
test_files:
|
135
|
+
- spec/pesapal_merchant_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Pesapal
|
2
|
-
|
3
|
-
# Returns our config hash, or if empty, returns an empty hash
|
4
|
-
def config
|
5
|
-
@@config ||= {}
|
6
|
-
end
|
7
|
-
|
8
|
-
# Sets our config class variable, which we expect to be a hash
|
9
|
-
def config=(hash)
|
10
|
-
@@config = hash
|
11
|
-
end
|
12
|
-
|
13
|
-
# Allows us to use instance methods on a Module e.g. Pesapal.config
|
14
|
-
module_function :config, :config=
|
15
|
-
end
|