pesapal 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3b26553cb2a95d21e6fd641daaec3809cf30cde
4
+ data.tar.gz: 9a408042e8bcdda57fea54e511361e93506d30c5
5
+ SHA512:
6
+ metadata.gz: 6e2cba8e4386972f74739ff5f65b546e381aeebadf2de31bcbb50170f1fcecbd1a36c92f20472d4ec97afe3182e18fc2667f6c9af03a22e82b67100b74e292f8
7
+ data.tar.gz: ad4568489f4e04edff4ce2e233f773683efdafb199b38cb6a1bcc8d261c191a004243047159f9a98a7dc57543a76b214e53731d4ad3970e101f1fae5139b4cd6
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -1,12 +1,18 @@
1
- # Ignore bundler config #
1
+ # Bundler #
2
2
  /.bundle
3
-
4
- # Ignore bundled gems #
5
3
  /vendor/bundle
6
4
 
7
- # Ignore all logfiles and tempfiles #
5
+ # Coveralls #
6
+ /coverage/
7
+
8
+ # Jekyll #
9
+ _site
10
+
11
+ # Yard #
12
+ .yardoc/*
13
+
14
+ # Gem #
8
15
  /log/*
9
16
  /tmp/*
10
-
11
- # Other Files #
17
+ Gemfile.lock
12
18
  *.gem
data/.yardopts ADDED
@@ -0,0 +1,12 @@
1
+ 'lib/pesapal/**/*.rb'
2
+
3
+ --title 'Pesapal Ruby Gem'
4
+ --markup=markdown
5
+ --markup-provider=redcarpet
6
+ --protected
7
+ --no-private
8
+
9
+ -
10
+ CHANGELOG.md
11
+ LICENSE.md
12
+ README.md
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v1.5.5
5
+ ------
6
+
7
+ * Improve code formatting
8
+ * Add comprehensive inline documentation (Yard)
9
+ * Move documentation from gem to it's own homepage, separate content from it's
10
+ own code e.g. we shouldn't have to update the gem each time we update the
11
+ README. This is also good because the only documentation that should go to
12
+ RubyDoc.info is inline (generated by Yard) which sticks with the version that it
13
+ was written for making it easy for someone to refer to documentation for old
14
+ versions.
15
+ * Write tests, coverage now at 98%
16
+ * Fix query_payment_details call "can't split nil String" error due to calling wrong endpoint
17
+
4
18
  v1.5.4
5
19
  ------
6
20
 
@@ -1,4 +1,7 @@
1
- Copyright (c) 2013 King'ori Maina
1
+ License
2
+ =======
3
+
4
+ Copyright (c) 2013-2014 King'ori Maina
2
5
 
3
6
  MIT License
4
7
 
@@ -6,7 +9,7 @@ Permission is hereby granted, free of charge, to any person obtaining
6
9
  a copy of this software and associated documentation files (the
7
10
  "Software"), to deal in the Software without restriction, including
8
11
  without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
12
+ distribute, sub-license, and/or sell copies of the Software, and to
10
13
  permit persons to whom the Software is furnished to do so, subject to
11
14
  the following conditions:
12
15
 
data/README.md CHANGED
@@ -1,29 +1,23 @@
1
- Pesapal RubyGem
1
+ [Pesapal RubyGem][2]
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
5
  [![Build Status](https://travis-ci.org/itsmrwave/pesapal-gem.png?branch=master)](https://travis-ci.org/itsmrwave/pesapal-gem)
6
6
  [![Code Climate](https://codeclimate.com/github/itsmrwave/pesapal-gem.png)](https://codeclimate.com/github/itsmrwave/pesapal-gem)
7
+ [![Coverage Status](https://coveralls.io/repos/itsmrwave/pesapal-gem/badge.png)](https://coveralls.io/r/itsmrwave/pesapal-gem)
7
8
  [![Dependency Status](https://gemnasium.com/itsmrwave/pesapal-gem.png)](https://gemnasium.com/itsmrwave/pesapal-gem)
8
9
 
9
10
 
10
- Make authenticated Pesapal API calls without the fuss! Handles all the [oAuth
11
- stuff][1] abstracting any direct interaction with the API endpoints so that you
12
- can focus on what matters. _Building awesome_.
11
+ Basically it's a gem that makes it easy to integrate your app with
12
+ [Pesapal][1]'s payment gateway. It Handles all the [oAuth stuff][3] abstracting
13
+ any direct interaction with the API endpoints so that you can focus on what
14
+ matters. _Building awesome_.
13
15
 
14
- This gem, in a nutshell, allows you to easily post an order, query payment
15
- status and fetch payment details.
16
+ The gem should be [up on RubyGems.org][4], it's [accompanying RubyDoc reference
17
+ here][9], the [CHANGELOG here][5] and [all the releases here][6].
16
18
 
17
- In case you are having any issues using this gem please **_do not_** email me
18
- directly, I'd rather you submit [issues (and even requests) here][6]. This way,
19
- other people get to share in the conversation that would have been private and
20
- out of their reach.
21
-
22
- The gem should be [up on RubyGems.org][7], it's [accompanying RubyDoc reference
23
- here][13], the [CHANGELOG here][21] and [all the releases here][12].
24
-
25
- If you are [feeling generous and want to contribute, feel free][9]. See [current
26
- contributors][19].
19
+ [Check out the homepage for details][2] i.e. on usage, support, issues,
20
+ contributing, testing etc.
27
21
 
28
22
  _Ps: No 3rd party oAuth library dependencies, it handles all the oAuth flows on
29
23
  it's own so your app is one dependency less._
@@ -49,247 +43,29 @@ For Rails, you need to run the generator to create sample pesapal.yml file:
49
43
  rails generate pesapal:install
50
44
 
51
45
 
52
- Usage
53
- -----
54
-
55
-
56
- ### Initialization ###
57
-
58
- There are 2 ways to initialize the Pesapal object:
59
-
60
- 1. YAML config at `/config/pesapal.yml`
61
- 2. Config hash
62
-
63
- Initialize Pesapal object and choose the environment, there are two environments;
64
- `:development` and `:production`. They determine if the code will interact
65
- with the testing or the live Pesapal API.
66
-
67
- ```ruby
68
- # Sets environment intelligently to 'Rails.env' (if Rails) or :development (if non-Rails)
69
- pesapal = Pesapal::Merchant.new
70
-
71
- # Sets environment to :development
72
- pesapal = Pesapal::Merchant.new(:development)
73
-
74
- # Sets environment to :production
75
- pesapal = Pesapal::Merchant.new(:production)
76
- ```
77
-
78
- ####Option 1####
79
-
80
- In the above case, the configuration has already been loaded (at application
81
- start by initializer) from a YAML file located at `"/config/pesapal.yml"`. The
82
- appropriate credentials are picked depending on set environment.
83
-
84
- This is the recommended method if using Rails.
85
-
86
-
87
- ####Option 2####
88
-
89
- If you do not wish to use the YAML config method then the object is set up with
90
- some bogus credentials which would not work anyway and therefore, the other
91
- option is that you set them yourself. Which, you can do using a hash as shown
92
- below (please note that Pesapal provides different keys for different
93
- environments and since this is like an override, there's the assumption that you
94
- chose the right one).
95
-
96
- Recommended if not using Rails.
97
-
98
- ```ruby
99
- # set pesapal api configuration manually (override YAML & bogus credentials)
100
- pesapal.config = { :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
101
- :consumer_key => '<YOUR_CONSUMER_KEY>',
102
- :consumer_secret => '<YOUR_CONSUMER_SECRET>'
103
- }
104
- ```
105
-
106
- _Ps: You can change the environment using `pesapal.set_env(:development)`
107
- (example) if for some reason you want to override what was set in the
108
- constructor. This method also changes the API endpoints appropriately._
109
-
110
-
111
- ###YAML Configuration###
112
-
113
- The YAML file should look something like this. If you ran the generator you
114
- should have it already in place with some default values. Feel free to change
115
- them appropriately.
116
-
117
- ```yaml
118
- development:
119
- callback_url: 'http://0.0.0.0:3000/pesapal/callback'
120
- consumer_key: '<YOUR_DEV_CONSUMER_KEY>'
121
- consumer_secret: '<YOUR_DEV_CONSUMER_SECRET>'
122
-
123
- production:
124
- callback_url: 'http://1.2.3.4:3000/pesapal/callback'
125
- consumer_key: '<YOUR_PROD_CONSUMER_KEY>'
126
- consumer_secret: '<YOUR_PROD_CONSUMER_SECRET>'
127
- ```
128
-
129
-
130
- ### Posting An Order ###
131
-
132
- Once you've finalized the configuration, set up the order details in a hash as
133
- shown in the example below ... all keys **MUST** be present. If there's one that
134
- you wish to ignore just leave it with a blank string but make sure it's included
135
- e.g. the phonenumber.
136
-
137
- ```ruby
138
- #set order details
139
- pesapal.order_details = { :amount => 1000,
140
- :description => 'this is the transaction description',
141
- :type => 'MERCHANT',
142
- :reference => '808-707-606',
143
- :first_name => 'Swaleh',
144
- :last_name => 'Mdoe',
145
- :email => 'user@example.com',
146
- :phonenumber => '+254722222222',
147
- :currency => 'KES'
148
- }
149
- ```
150
-
151
- Then generate the transaction url as below. In the example, the value is
152
- assigned to the variable `order_url` which you can pass on to the templating
153
- system of your choice to generate an iframe. Please note that this method
154
- utilizes all that information set in the previous steps in generating the url so
155
- it's important that it's the last step in the post order process.
156
-
157
- ```ruby
158
- # generate transaction url
159
- order_url = pesapal.generate_order_url
160
-
161
- # order_url will a string with the url example;
162
- # http://demo.pesapal.com/API/PostPesapalDirectOrderV4?oauth_callback=http%3A%2F%2F1.2.3.4%3A3000%2Fpesapal%2Fcallback&oauth_consumer_key=A9MXocJiHK1P4w0M%2F%2FYzxgIVMX557Jt4&oauth_nonce=13804335543pDXs4q3djsy&oauth_signature=BMmLR0AVInfoBI9D4C38YDA9eSM%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1380433554&oauth_version=1.0&pesapal_request_data=%26lt%3B%3Fxml%20version%3D%26quot%3B1.0%26quot%3B%20encoding%3D%26quot%3Butf-8%26quot%3B%3F%26gt%3B%26lt%3BPesapalDirectOrderInfo%20xmlns%3Axsi%3D%26quot%3Bhttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%26quot%3B%20xmlns%3Axsd%3D%26quot%3Bhttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%26quot%3B%20Amount%3D%26quot%3B1000%26quot%3B%20Description%3D%26quot%3Bthis%20is%20the%20transaction%20description%26quot%3B%20Type%3D%26quot%3BMERCHANT%26quot%3B%20Reference%3D%26quot%3B808%26quot%3B%20FirstName%3D%26quot%3BSwaleh%26quot%3B%20LastName%3D%26quot%3BMdoe%26quot%3B%20Email%3D%26quot%3Bj%40kingori.co%26quot%3B%20PhoneNumber%3D%26quot%3B%2B254722222222%26quot%3B%20xmlns%3D%26quot%3Bhttp%3A%2F%2Fwww.pesapal.com%26quot%3B%20%2F%26gt%3B
163
- ```
164
-
165
- _Ps: Please note the `:callback_url` value in the `pesapal.config` hash ...
166
- after the user successfully posts the order, the response will be sent to this
167
- url. Refer to [official Pesapal Step-By-Step integration guide][18] for more
168
- details._
169
-
170
-
171
- ### Querying Payment Status ###
172
-
173
- Use this to query the status of the transaction. When a transaction is posted to
174
- Pesapal, it may be in a PENDING, COMPLETED, FAILED or INVALID state. If the
175
- transaction is PENDING, the payment may complete or fail at a later stage.
176
-
177
- Both the unique merchant reference generated by your system (compulsory) and the
178
- pesapal transaction tracking id (optional) are input parameters to this method
179
- but if you don't ensure that the merchant reference is unique for each order on
180
- your system, you may get INVALID as the response. Because of this, it is
181
- recommended that you provide both the merchant reference and transaction
182
- tracking id as parameters to guarantee uniqueness.
183
-
184
- ```ruby
185
- # option 1: using merchant reference only
186
- payment_status = pesapal.query_payment_status("<MERCHANT_REFERENCE>")
187
-
188
- # option 2: using merchant reference and transaction id (recommended)
189
- payment_status = pesapal.query_payment_status("<MERCHANT_REFERENCE>","<TRANSACTION_ID>")
190
- ```
191
-
192
-
193
- ### Querying Payment Details ###
194
-
195
- Same as querying payment status above, but the return value contains more
196
- information (and is a hash as opposed to a string).
197
-
198
- ```ruby
199
- # pass in merchant reference and transaction id
200
- payment_details = pesapal.query_payment_details("<MERCHANT_REFERENCE>","<TRANSACTION_ID>")
201
- ```
202
-
203
- The result is a hash that looks something like this ...
204
-
205
- ```
206
- {
207
- :method => "<PAYMENT_METHOD>",
208
- :status => "<PAYMENT_STATUS>",
209
- :merchant_reference => "<MERCHANT_REFERENCE>",
210
- :transaction_tracking_id => "<TRANSACTION_ID>"
211
- }
212
- ```
213
-
214
-
215
- ### IPN Listening ###
216
-
217
- Use the `ipn_listener` method to listen to Pesapal IPN calls to easily create an
218
- appropriate response, example below.
219
-
220
- ```ruby
221
- # pass in the notification type, merchant reference and transaction id
222
- response_to_ipn = pesapal.ipn_listener("<NOTIFICATION_TYPE>", "<MERCHANT_REFERENCE>","<TRANSACTION_ID>")
223
- ```
224
-
225
- The variable, `response_to_ipn`, now holds a response as the one shown below.
226
- Using the status you can customise any actions (e.g. database inserts and
227
- updates) and finally, it's upto you to send the `:response` back to pesapal. The
228
- hard part is done for you.
229
-
230
- ```
231
- {
232
- :status => "<PAYMENT_STATUS>",
233
- :response => "<IPN_RESPONSE>"
234
- }
235
- ```
236
-
237
- _Ps: Refer to Pesapal official documentation to make sure you understand what
238
- data Pesapal sends to IPN and what result they expect back._
239
-
240
-
241
- Contributing & Testing
242
- ----------------------
243
-
244
- 1. Make sure you've read the [M.O. ★][14] ([blog article here][16])
245
- 2. Especially [the part about my conventions when writing and merging new features][15]
246
- 3. [Fork it][8]
247
- 4. Create your feature branch (`git checkout -b BRANCH_NAME`)
248
- 5. Make your changes, write tests for them if necessary & run `bundle exec rspec spec`
249
- 6. Commit your changes (`git commit -am 'AWESOME COMMIT MESSAGE'`)
250
- 7. Push to the branch (`git push origin BRANCH_NAME`)
251
- 8. Create new pull request and we can [have the conversations here][17]
252
-
253
- _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._
254
-
46
+ Contributors
47
+ ------------
255
48
 
256
- References
257
- ----------
49
+ Special thanks to:
258
50
 
259
- * [oAuth 1.0 Spec][1]
260
- * [Developing a RubyGem using Bundler][2]
261
- * [RailsGuides][20]
262
- * [Make your own gem][3]
263
- * [Pesapal API Reference (Official)][4]
264
- * [Pesapal Step-By-Step Reference (Official)][18]
265
- * [Pesapal PHP API Reference (Unofficial)][5]
51
+ * [Isaac Mogetutu][10] ([@mogetutu][11])
266
52
 
267
53
 
268
54
  License
269
55
  -------
270
56
 
271
- [King'ori J. Maina][10] © 2013. The [MIT License bundled therein][11] is a
57
+ [King'ori J. Maina][7] © 2013-2014. The [MIT License bundled therein][8] is a
272
58
  permissive license that is short and to the point. It lets people do anything
273
59
  they want as long as they provide attribution and waive liability.
274
60
 
275
- [1]: http://oauth.net/core/1.0/
276
- [2]: https://github.com/radar/guides/blob/master/gem-development.md
277
- [3]: http://guides.rubygems.org/make-your-own-gem/
278
- [4]: http://developer.pesapal.com/how-to-integrate/api-reference
279
- [5]: https://github.com/itsmrwave/pesapal-php#pesapal-php-api-reference-unofficial
280
- [6]: https://github.com/itsmrwave/pesapal-gem/issues
281
- [7]: http://rubygems.org/gems/pesapal
282
- [8]: https://github.com/itsmrwave/pesapal-gem/fork
283
- [9]: https://github.com/itsmrwave/pesapal-gem#contributing
284
- [10]: http://kingori.co/
285
- [11]: https://github.com/itsmrwave/pesapal-gem/blob/master/LICENSE.txt
286
- [12]: https://github.com/itsmrwave/pesapal-gem/releases/
287
- [13]: http://rubydoc.info/gems/pesapal/
288
- [14]: https://github.com/itsmrwave/mo
289
- [15]: https://github.com/itsmrwave/mo/tree/master/convention#-convention
290
- [16]: http://kingori.co/articles/2013/09/modus-operandi/
291
- [17]: https://github.com/itsmrwave/pesapal-gem/pulls
292
- [18]: http://developer.pesapal.com/how-to-integrate/step-by-step
293
- [19]: https://github.com/itsmrwave/pesapal-gem/graphs/contributors
294
- [20]: http://guides.rubyonrails.org/
295
- [21]: https://github.com/itsmrwave/pesapal-gem/blob/master/CHANGELOG.md#changelog
61
+ [1]: https://www.pesapal.com/
62
+ [2]: http://itsmrwave.github.io/pesapal-gem
63
+ [3]: http://oauth.net/core/1.0/
64
+ [4]: http://rubygems.org/gems/pesapal
65
+ [5]: https://raw.githubusercontent.com/itsmrwave/pesapal-gem/master/CHANGELOG.md
66
+ [6]: https://github.com/itsmrwave/pesapal-gem/releases/
67
+ [7]: http://kingori.co/
68
+ [8]: https://raw.githubusercontent.com/itsmrwave/pesapal-gem/master/LICENSE.md
69
+ [9]: http://rubydoc.info/gems/pesapal/
70
+ [10]: http://mogetutu.com/
71
+ [11]: https://github.com/mogetutu
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
@@ -1,4 +1,7 @@
1
1
  module Pesapal
2
+ # Since generators are not specific to this project, it's preferable you refer
3
+ # to the official documentation on the Rails site here;
4
+ # http://guides.rubyonrails.org/generators.html
2
5
  module Generators
3
6
  class InstallGenerator < Rails::Generators::Base
4
7
  source_root File.expand_path("../../templates", __FILE__)
data/lib/pesapal.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'htmlentities'
2
2
  require 'net/http'
3
3
 
4
+ require 'pesapal/helper/details'
5
+ require 'pesapal/helper/post'
6
+ require 'pesapal/helper/status'
4
7
  require 'pesapal/merchant'
5
- require 'pesapal/merchant/details'
6
- require 'pesapal/merchant/post'
7
- require 'pesapal/merchant/status'
8
8
  require 'pesapal/oauth'
9
9
  require 'pesapal/version'
10
10
 
@@ -0,0 +1,53 @@
1
+ module Pesapal
2
+ # Pesapal helper modules.
3
+ module Helper
4
+ # Contains helper methods relating to any queries for payment details. See
5
+ # {Pesapal::Merchant#query_payment_details} source.
6
+ module Details
7
+ # Prepares parameters to be used during the QueryPaymentDetails oAuth 1.0 call.
8
+ #
9
+ # The QueryPaymentDetails oAuth 1.0 call requires the following parameters;
10
+ #
11
+ # 1. `oauth_consumer_key` - your Pesapal consumer key sent to you via email or obtained from the dashboard
12
+ # 2. `oauth_nonce` - a random string, uniquely generated for each request. See [section 8 of the oAuth 1.0 spec][3]
13
+ # 3. `oauth_signature` - the signature as defined in the oAuth 1.0 spec under [section 9 of the oAuth 1.0 spec][2]
14
+ # 4. `oauth_signature_method` - `HMAC-SHA1` (do not change). See [section 9.2 of the oAuth 1.0 spec][1]
15
+ # 5. `oauth_timestamp` - number of seconds since January 1, 1970 00:00:00 GMT, also known as Unix Time. See [section 8 of the oAuth 1.0 spec][3]
16
+ # 6. `oauth_version` - `1.0` (do not change)
17
+ # 7. `pesapal_merchant_reference` - the transaction merchant reference (same as `merchant_reference` defined below)
18
+ # 8. `pesapal_transaction_tracking_id` - the transaction tracking id (same as `transaction_tracking_id` defined below)
19
+ #
20
+ # This method generates all the above **except** the `oauth_signature` which
21
+ # is generated later by {Pesapal::Oauth.generate_oauth_signature} since
22
+ # generation of this `oauth_signature` requires these parameters as inputs
23
+ # anyway. See [section 9.2.1 of the oAuth 1.0 spec][1] for more details.
24
+ #
25
+ # [1]: http://oauth.net/core/1.0/#anchor16
26
+ # [2]: http://oauth.net/core/1.0/#signing_process
27
+ # [3]: http://oauth.net/core/1.0/#nonce
28
+ # [4]: http://oauth.net/core/1.0/
29
+ #
30
+ # @param consumer_key [String] your Pesapal consumer key sent to you via
31
+ # email or obtained from the dashboard
32
+ #
33
+ # @param merchant_reference [String] the unique id generated for the
34
+ # transaction by your application before posting the order
35
+ #
36
+ # @param transaction_tracking_id [String] the unique id assigned by Pesapal
37
+ # to the transaction after it's posted
38
+ #
39
+ # @return [Hash] parameters to be used in generating the oAuth 1.0 URL query parameters and the `oauth_signature` itself.
40
+ def self.set_parameters(consumer_key, merchant_reference, transaction_tracking_id)
41
+ timestamp = Time.now.to_i.to_s
42
+ { :oauth_consumer_key => consumer_key,
43
+ :oauth_nonce => "#{timestamp}" + Pesapal::Oauth.generate_nonce(12),
44
+ :oauth_signature_method => 'HMAC-SHA1',
45
+ :oauth_timestamp => "#{timestamp}",
46
+ :oauth_version => '1.0',
47
+ :pesapal_merchant_reference => merchant_reference,
48
+ :pesapal_transaction_tracking_id => transaction_tracking_id
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end