pesapal 1.2.0 → 1.2.1
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/CHANGELOG.md +7 -0
- data/README.md +16 -7
- data/lib/generators/templates/pesapal.rb +2 -7
- data/lib/pesapal.rb +1 -0
- data/lib/pesapal/configuration.rb +15 -0
- data/lib/pesapal/merchant.rb +23 -11
- data/lib/pesapal/merchant/details.rb +2 -2
- data/lib/pesapal/merchant/post.rb +3 -3
- data/lib/pesapal/merchant/status.rb +2 -2
- data/lib/pesapal/oauth.rb +3 -3
- data/lib/pesapal/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b3d98d9279b31f66a9996b6045d19a0ae01c2c7
|
4
|
+
data.tar.gz: e132dc33bd5a88e3c2980e4c5eff9f8bfe438e33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ff6e09c9b02066fe9b78120cc2f60594eea9fc3d23c5c010b2eb9eccce2ef3d5bd0d4d4de20b360f380a171278a18794e472dec65ff69f572e721a1797d61e
|
7
|
+
data.tar.gz: 510c5cadf3d39ed31c86d266c5023c9b79bd087329818401e801a2e3a1075f9bb858f7fd891f89966005b4ca3ce20a44d7571be948069dac60fd4640dc5f0fbb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ other people get to share in the conversation that would have been private and
|
|
16
16
|
out of their reach.
|
17
17
|
|
18
18
|
The gem should be [up on RubyGems.org][7], it's [accompanying RubyDoc reference
|
19
|
-
here][13] and [all the releases here][12].
|
19
|
+
here][13], the [CHANGELOG here][21] and [all the releases here][12].
|
20
20
|
|
21
21
|
If you are [feeling generous and want to contribute, feel free][9].
|
22
22
|
|
@@ -68,9 +68,11 @@ pesapal = Pesapal::Merchant.new(:development)
|
|
68
68
|
|
69
69
|
####Option 1####
|
70
70
|
|
71
|
-
In the case, the configuration has already been loaded (at application
|
72
|
-
initializer) from a YAML file located at
|
73
|
-
|
71
|
+
In the above case, the configuration has already been loaded (at application
|
72
|
+
start by initializer) from a YAML file located at
|
73
|
+
`"#{Rails.root}/config/pesapal.yml"` by default.
|
74
|
+
|
75
|
+
This is the recommended method.
|
74
76
|
|
75
77
|
####Option 2####
|
76
78
|
|
@@ -124,6 +126,12 @@ production:
|
|
124
126
|
consumer_secret: '<YOUR_CONSUMER_SECRET>'
|
125
127
|
```
|
126
128
|
|
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
|
+
|
127
135
|
|
128
136
|
### Posting An Order ###
|
129
137
|
|
@@ -133,7 +141,7 @@ you wish to ignore just leave it with a blank string but make sure it's included
|
|
133
141
|
e.g. the phonenumber.
|
134
142
|
|
135
143
|
```ruby
|
136
|
-
#set order details
|
144
|
+
#set order details
|
137
145
|
pesapal.order_details = { :amount => 1000,
|
138
146
|
:description => 'this is the transaction description',
|
139
147
|
:type => 'MERCHANT',
|
@@ -201,7 +209,7 @@ payment_details = pesapal.query_payment_details("<MERCHANT_REFERENCE>","<TRANSAC
|
|
201
209
|
The result is a hash that looks something like this ...
|
202
210
|
|
203
211
|
```
|
204
|
-
{
|
212
|
+
{
|
205
213
|
:method => "<PAYMENT_METHOD>",
|
206
214
|
:status => "<PAYMENT_STATUS>",
|
207
215
|
:merchant_reference => "<MERCHANT_REFERENCE>",
|
@@ -226,7 +234,7 @@ updates) and finally, it's upto you to send the `:response` back to pesapal. The
|
|
226
234
|
hard part is done for you.
|
227
235
|
|
228
236
|
```
|
229
|
-
{
|
237
|
+
{
|
230
238
|
:status => "<PAYMENT_STATUS>",
|
231
239
|
:response => "<IPN_RESPONSE>"
|
232
240
|
}
|
@@ -289,3 +297,4 @@ they want as long as they provide attribution and waive liability.
|
|
289
297
|
[18]: http://developer.pesapal.com/how-to-integrate/step-by-step
|
290
298
|
[19]: https://github.com/itsmrwave/pesapal-rubygem/graphs/contributors
|
291
299
|
[20]: http://guides.rubyonrails.org/
|
300
|
+
[21]: https://github.com/itsmrwave/pesapal-rubygem/blob/master/CHANGELOG.md#changelog
|
@@ -1,7 +1,2 @@
|
|
1
|
-
# Load Pesapal config file when applicatin is loaded
|
2
|
-
|
3
|
-
module PesapalRails
|
4
|
-
class Application < Rails::Application
|
5
|
-
config.yaml = YAML::load(IO.read("#{Rails.root}/config/pesapal.yml"))
|
6
|
-
end
|
7
|
-
end
|
1
|
+
# Load Pesapal config file from YAML file when applicatin is loaded
|
2
|
+
Pesapal.config = YAML::load(IO.read("#{Rails.root}/config/pesapal.yml"))
|
data/lib/pesapal.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
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
|
data/lib/pesapal/merchant.rb
CHANGED
@@ -5,11 +5,11 @@ module Pesapal
|
|
5
5
|
attr_accessor :config, :order_details
|
6
6
|
|
7
7
|
def config
|
8
|
-
@config
|
8
|
+
@config ||= {}
|
9
9
|
end
|
10
10
|
|
11
11
|
def order_details
|
12
|
-
@order_details
|
12
|
+
@order_details ||= {}
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -50,12 +50,9 @@ module Pesapal
|
|
50
50
|
|
51
51
|
set_mode mode
|
52
52
|
|
53
|
-
# set the credentials if we have
|
54
|
-
|
55
|
-
|
56
|
-
set_configuration PesapalRails::Application.config.yaml[@mode]
|
57
|
-
else
|
58
|
-
# we have custom path so we load from file
|
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?
|
59
56
|
set_configuration_from_yaml path_to_file
|
60
57
|
end
|
61
58
|
|
@@ -64,6 +61,11 @@ module Pesapal
|
|
64
61
|
# generate pesapal order url (often iframed)
|
65
62
|
def generate_order_url
|
66
63
|
|
64
|
+
# check if the config is empty, if yes, we try load what was set by the initializer into Pesapal.config
|
65
|
+
if config.empty?
|
66
|
+
set_configuration Pesapal.config[@mode]
|
67
|
+
end
|
68
|
+
|
67
69
|
# build xml with input data, the format is standard so no editing is
|
68
70
|
# required
|
69
71
|
@post_xml = Pesapal::Post::generate_post_xml @order_details
|
@@ -83,6 +85,11 @@ module Pesapal
|
|
83
85
|
# query the details of the transaction
|
84
86
|
def query_payment_details(merchant_reference, transaction_tracking_id)
|
85
87
|
|
88
|
+
# check if the config is empty, if yes, we try load what was set by the initializer into Pesapal.config
|
89
|
+
if config.empty?
|
90
|
+
set_configuration Pesapal.config[@mode]
|
91
|
+
end
|
92
|
+
|
86
93
|
# initialize setting of @params (oauth_signature left empty)
|
87
94
|
@params = Pesapal::Details::set_parameters(@config[:consumer_key], merchant_reference, transaction_tracking_id)
|
88
95
|
|
@@ -105,7 +112,12 @@ module Pesapal
|
|
105
112
|
|
106
113
|
# query the status of the transaction
|
107
114
|
def query_payment_status(merchant_reference, transaction_tracking_id = nil)
|
108
|
-
|
115
|
+
|
116
|
+
# check if the config is empty, if yes, we try load what was set by the initializer into Pesapal.config
|
117
|
+
if config.empty?
|
118
|
+
set_configuration Pesapal.config[@mode]
|
119
|
+
end
|
120
|
+
|
109
121
|
# initialize setting of @params (oauth_signature left empty)
|
110
122
|
@params = Pesapal::Status::set_parameters(@config[:consumer_key], merchant_reference, transaction_tracking_id)
|
111
123
|
|
@@ -125,7 +137,7 @@ module Pesapal
|
|
125
137
|
|
126
138
|
# set mode when called
|
127
139
|
def set_mode(mode = :development)
|
128
|
-
|
140
|
+
|
129
141
|
# convert symbol to string and downcase
|
130
142
|
@mode = "#{mode.to_s.downcase}"
|
131
143
|
|
@@ -135,7 +147,7 @@ module Pesapal
|
|
135
147
|
|
136
148
|
# listen to ipn response
|
137
149
|
def ipn_listener(notification_type, merchant_reference, transaction_tracking_id)
|
138
|
-
|
150
|
+
|
139
151
|
status = query_payment_status(merchant_reference, transaction_tracking_id)
|
140
152
|
|
141
153
|
output = { :status => status }
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Pesapal
|
2
2
|
|
3
3
|
module Details
|
4
|
-
|
4
|
+
|
5
5
|
# set parameters required by the QueryPaymentDetails call
|
6
6
|
def Details.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
|
10
10
|
# http://developer.pesapal.com/how-to-integrate/api-reference#QueryPaymentDetails)
|
11
|
-
|
11
|
+
|
12
12
|
timestamp = Time.now.to_i.to_s
|
13
13
|
|
14
14
|
params = { :oauth_consumer_key => consumer_key,
|
@@ -4,7 +4,7 @@ module Pesapal
|
|
4
4
|
|
5
5
|
# build html encoded xml string for PostPesapalDirectOrderV4
|
6
6
|
def Post.generate_post_xml(details)
|
7
|
-
|
7
|
+
|
8
8
|
# build xml with input data, the format is standard so no editing is
|
9
9
|
# required
|
10
10
|
post_xml = ''
|
@@ -28,14 +28,14 @@ module Pesapal
|
|
28
28
|
|
29
29
|
"#{post_xml}"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# set parameters required by the PostPesapalDirectOrderV4 call
|
33
33
|
def Post.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
|
37
37
|
# http://developer.pesapal.com/how-to-integrate/api-reference#PostPesapalDirectOrderV4)
|
38
|
-
|
38
|
+
|
39
39
|
timestamp = Time.now.to_i.to_s
|
40
40
|
|
41
41
|
params = { :oauth_callback => callback_url,
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Pesapal
|
2
2
|
|
3
3
|
module Status
|
4
|
-
|
4
|
+
|
5
5
|
# set parameters required by the QueryPaymentStatus & QueryPaymentStatusByMerchantRef calls
|
6
6
|
def Status.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
|
10
10
|
# http://developer.pesapal.com/how-to-integrate/api-reference)
|
11
|
-
|
11
|
+
|
12
12
|
timestamp = Time.now.to_i.to_s
|
13
13
|
|
14
14
|
params = { :oauth_consumer_key => consumer_key,
|
data/lib/pesapal/oauth.rb
CHANGED
@@ -25,7 +25,7 @@ module Pesapal
|
|
25
25
|
# parameters are sorted by name, using lexicographical byte value
|
26
26
|
# ordering
|
27
27
|
queries.sort!
|
28
|
-
|
28
|
+
|
29
29
|
queries.join('&')
|
30
30
|
end
|
31
31
|
|
@@ -57,7 +57,7 @@ module Pesapal
|
|
57
57
|
# for pesapal flow we don't have a token secret to we will set as
|
58
58
|
# nil and the appropriate action will be taken as per the oauth
|
59
59
|
# spec. see notes in the method that creates signing keys
|
60
|
-
|
60
|
+
|
61
61
|
# prepare the values we need
|
62
62
|
digest = OpenSSL::Digest::Digest.new('sha1')
|
63
63
|
signature_base_string = self.generate_signature_base_string(http_method, absolute_url, params)
|
@@ -144,7 +144,7 @@ module Pesapal
|
|
144
144
|
# unless specified, url scheme and authority must be lowercase and
|
145
145
|
# include the port number; http default port 80 and https default
|
146
146
|
# port 443 must be excluded.
|
147
|
-
|
147
|
+
|
148
148
|
u = URI.parse(absolute_url)
|
149
149
|
|
150
150
|
scheme = u.scheme.downcase
|
data/lib/pesapal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pesapal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Job King'ori Maina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/generators/templates/pesapal.rb
|
71
71
|
- lib/generators/templates/pesapal.yml
|
72
72
|
- lib/pesapal.rb
|
73
|
+
- lib/pesapal/configuration.rb
|
73
74
|
- lib/pesapal/merchant.rb
|
74
75
|
- lib/pesapal/merchant/details.rb
|
75
76
|
- lib/pesapal/merchant/post.rb
|