pesapal 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/CHANGELOG.md +6 -0
- data/README.md +15 -19
- data/lib/pesapal/merchant.rb +25 -21
- data/lib/pesapal/version.rb +1 -1
- data/pesapal.gemspec +1 -1
- data/spec/pesapal_merchant_spec.rb +17 -0
- metadata +2 -2
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,8 @@ out of their reach.
|
|
21
21
|
The gem should be [up on RubyGems.org][7], it's [accompanying RubyDoc reference
|
22
22
|
here][13], the [CHANGELOG here][21] and [all the releases here][12].
|
23
23
|
|
24
|
-
If you are [feeling generous and want to contribute, feel free][9].
|
24
|
+
If you are [feeling generous and want to contribute, feel free][9]. See [current
|
25
|
+
contributors][19].
|
25
26
|
|
26
27
|
_Ps: No 3rd party oAuth library dependencies, it handles all the oAuth flows on
|
27
28
|
it's own so your app is one dependency less._
|
@@ -63,20 +64,14 @@ Initialize Pesapal object and choose the environment, there are two environments
|
|
63
64
|
with the testing or the live Pesapal API.
|
64
65
|
|
65
66
|
```ruby
|
66
|
-
#
|
67
|
+
# Sets environment intelligently to 'Rails.env' (if Rails) or :development (if non-Rails)
|
67
68
|
pesapal = Pesapal::Merchant.new
|
68
69
|
|
69
|
-
#
|
70
|
+
# Sets environment to :development
|
70
71
|
pesapal = Pesapal::Merchant.new(:development)
|
71
72
|
|
72
|
-
#
|
73
|
+
# Sets environment to :production
|
73
74
|
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)
|
80
75
|
```
|
81
76
|
|
82
77
|
####Option 1####
|
@@ -242,18 +237,19 @@ _Ps: Refer to Pesapal official documentation to make sure you understand what
|
|
242
237
|
data Pesapal sends to IPN and what result they expect back._
|
243
238
|
|
244
239
|
|
245
|
-
Contributing
|
246
|
-
|
240
|
+
Contributing & Testing
|
241
|
+
----------------------
|
247
242
|
|
248
243
|
1. Make sure you've read the [M.O. ★][14] ([blog article here][16])
|
249
244
|
2. Especially [the part about my conventions when writing and merging new features][15]
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
245
|
+
3. [Fork it][8]
|
246
|
+
4. Create your feature branch (`git checkout -b BRANCH_NAME`)
|
247
|
+
5. Make your changes, write tests for them if necessary & run `bundle exec rspec spec`
|
248
|
+
6. Commit your changes (`git commit -am 'AWESOME COMMIT MESSAGE'`)
|
249
|
+
7. Push to the branch (`git push origin BRANCH_NAME`)
|
250
|
+
8. Create new pull request and we can [have the conversations here][17]
|
251
|
+
|
252
|
+
_Ps: By the time we have a conversation your [pull request tests should pass on Travis-CI][22] or if they aren't at least you know why._
|
257
253
|
|
258
254
|
|
259
255
|
References
|
data/lib/pesapal/merchant.rb
CHANGED
@@ -41,7 +41,7 @@ module Pesapal
|
|
41
41
|
public
|
42
42
|
|
43
43
|
# constructor
|
44
|
-
def initialize(env =
|
44
|
+
def initialize(env = false)
|
45
45
|
set_env env
|
46
46
|
if defined?(Rails)
|
47
47
|
set_configuration Rails.application.config.pesapal_credentials
|
@@ -82,9 +82,15 @@ module Pesapal
|
|
82
82
|
query_string = Pesapal::Oauth::generate_encoded_params_query_string @params
|
83
83
|
|
84
84
|
# get status response
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
uri = URI.parse "#{@api_endpoints[:querypaymentstatus]}?#{query_string}"
|
86
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
87
|
+
if @env == 'production'
|
88
|
+
http.use_ssl = true
|
89
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
90
|
+
end
|
91
|
+
response = http.request(Net::HTTP::Get.new(uri.request_uri))
|
92
|
+
response = CGI::parse response.body
|
93
|
+
response = response['pesapal_response_data'][0].split(',')
|
88
94
|
|
89
95
|
details = { :method => response[1],
|
90
96
|
:status => response[2],
|
@@ -105,19 +111,21 @@ module Pesapal
|
|
105
111
|
query_string = Pesapal::Oauth::generate_encoded_params_query_string @params
|
106
112
|
|
107
113
|
# get status response
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
114
|
+
uri = URI.parse "#{@api_endpoints[:querypaymentstatus]}?#{query_string}"
|
115
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
116
|
+
if @env == 'production'
|
117
|
+
http.use_ssl = true
|
118
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
119
|
+
end
|
120
|
+
response = http.request(Net::HTTP::Get.new(uri.request_uri))
|
121
|
+
response = CGI::parse response.body
|
122
|
+
response['pesapal_response_data'][0]
|
113
123
|
end
|
114
124
|
|
115
125
|
# set env when called
|
116
|
-
def set_env(env =
|
126
|
+
def set_env(env = false)
|
117
127
|
env = env.to_s.downcase
|
118
|
-
if env == '
|
119
|
-
@env = 'development'
|
120
|
-
elsif env == 'production'
|
128
|
+
if env == 'production'
|
121
129
|
@env = 'production'
|
122
130
|
else
|
123
131
|
@env = 'development'
|
@@ -130,15 +138,11 @@ module Pesapal
|
|
130
138
|
def ipn_listener(notification_type, merchant_reference, transaction_tracking_id)
|
131
139
|
|
132
140
|
status = query_payment_status(merchant_reference, transaction_tracking_id)
|
141
|
+
output = { :status => status, :response => nil }
|
133
142
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
output[:response] = "pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=#{transaction_tracking_id}&pesapal_merchant_reference=#{merchant_reference}"
|
138
|
-
elsif status == "FAILED"
|
139
|
-
output[:response] = "pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=#{transaction_tracking_id}&pesapal_merchant_reference=#{merchant_reference}"
|
140
|
-
else
|
141
|
-
output[:response] = ""
|
143
|
+
case status
|
144
|
+
when 'COMPLETED' then output[:response] = "pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=#{transaction_tracking_id}&pesapal_merchant_reference=#{merchant_reference}"
|
145
|
+
when 'FAILED' then output[:response] = "pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=#{transaction_tracking_id}&pesapal_merchant_reference=#{merchant_reference}"
|
142
146
|
end
|
143
147
|
|
144
148
|
output
|
data/lib/pesapal/version.rb
CHANGED
data/pesapal.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'pesapal/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'pesapal'
|
7
7
|
spec.version = Pesapal::VERSION
|
8
|
-
spec.date = Time.new.
|
8
|
+
spec.date = Time.new.getutc.strftime('%Y-%m-%d')
|
9
9
|
spec.authors = ['Job King\'ori Maina']
|
10
10
|
spec.email = ['j@kingori.co']
|
11
11
|
spec.description = 'Make authenticated Pesapal API calls without the fuss!'
|
@@ -4,10 +4,27 @@ describe Pesapal::Merchant do
|
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
@pesapal = Pesapal::Merchant.new
|
7
|
+
@pesapal_dev = Pesapal::Merchant.new(:development)
|
8
|
+
@pesapal_prod = Pesapal::Merchant.new(:production)
|
7
9
|
end
|
8
10
|
|
9
11
|
describe '#new' do
|
10
12
|
|
13
|
+
it 'sets default environment variable' do
|
14
|
+
@pesapal.send(:env).should == 'development'
|
15
|
+
@pesapal.send(:env).should_not == 'production'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets development environment variable' do
|
19
|
+
@pesapal_dev.send(:env).should == 'development'
|
20
|
+
@pesapal_dev.send(:env).should_not == 'production'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets production environment variable' do
|
24
|
+
@pesapal_prod.send(:env).should == 'production'
|
25
|
+
@pesapal_prod.send(:env).should_not == 'development'
|
26
|
+
end
|
27
|
+
|
11
28
|
# Check if the initializer successfully sets a Pesapal::Merchant object
|
12
29
|
it 'returns a new instance of a pesapal object' do
|
13
30
|
@pesapal.should be_an_instance_of Pesapal::Merchant
|
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.5.
|
4
|
+
version: 1.5.3
|
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-
|
12
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|