pesapal 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb392cdf96d61bb012553fb244ff25d396a3e03e
4
- data.tar.gz: 3580ef2eb4210bb084fdec5d27d7906b9a14acac
3
+ metadata.gz: 44aef97bfcafb5b7ce0a7db59a613eccb7dbacd7
4
+ data.tar.gz: 87b26cead15de174dffe376207ba2c788483b38a
5
5
  SHA512:
6
- metadata.gz: d9d551c448a513f52cd3b77ed1f344ff55039cd5bd84d2fcd2eea00cd1d087d264c7dd13cd41638ba438e182764daf4b84d0f8631be629986a39ab1af5494567
7
- data.tar.gz: 249a9fd1d7aa8cd95d28118f8b96a83df53061ed94e5c5e8bdb770324768c580cc5c4c9a5d1eec1bbe686e8ce8604ce800130cdc06c993dbc3e0f3a8f9a1a45a
6
+ metadata.gz: 47c85fc5ae2a65a9158bda4ec6966ea0ddd3836e8d0e2a3fc9d223e3aef8780a82c8473beb8e7881a85c1eb9dfe99e08304c6c7fa6a403e127129e97465904a9
7
+ data.tar.gz: 59e945655938a5a6def127f44eae00c4c3b75727348e43602605495a98bdbd0fb7cf635e24e0523c5bdbc4abb7505bac7d5b41bd87309a5fff384f319d7bf2e5
data/README.md CHANGED
@@ -14,10 +14,15 @@ been laid. If you are [feeling generous and want to contribute, feel free][9].
14
14
 
15
15
  Submit [issues and requests here][6] and [find all the releases here][12].
16
16
 
17
- The gem should be [up on RubyGems.org][7] and it's [accompanying RubyDoc reference][13] here.
17
+ The gem should be [up on RubyGems.org][7] and it's [accompanying RubyDoc reference here][13].
18
18
 
19
19
  _Ps: No 3rd party oAuth library dependencies, it handles all the oAuth flows on
20
- it's own so it's light on your app._
20
+ it's own so your app is one dependency less._
21
+
22
+ _Ps 2: We are still at pre-release stage ... target is version 1.0.0 for a
23
+ public release (suitable for production deployment with the basic functionality
24
+ in place). As a result always check the documentation carefully on upgrades to
25
+ mitigate breaking changes._
21
26
 
22
27
 
23
28
  Installation
@@ -39,39 +44,69 @@ Or install it yourself as:
39
44
  Usage
40
45
  -----
41
46
 
47
+
42
48
  ### Setup ###
43
49
 
44
50
  Initialize Pesapal object and choose the mode, there are two modes;
45
- `:development` and `:production`. They determine if you the code will interact
46
- with Pesapal for testing or for a live deployment.
51
+ `:development` and `:production`. They determine if the code will interact
52
+ with the testing or the live Pesapal API.
47
53
 
48
54
  ```ruby
49
55
  # initiate pesapal object set to development mode
50
56
  pesapal = Pesapal::Merchant.new(:development)
51
57
  ```
52
58
 
53
- Now set the Pesapal credentials. This assumes that you've chosen the appropriate
54
- credentials as they differ based on the mode chosen above (Pesapal provide the
55
- keys). Replace the placeholders below with your own credentials.
59
+ You can set the configuration details from a YAML file at the location of
60
+ your choice upon initialization as shown in the example below for a Rails app.
61
+ The second parameter is optional and has a default value of
62
+ `"#{Rails.root}/config/pesapal.yml"` if left out as in the example above.
56
63
 
57
64
  ```ruby
58
- # set pesapal api credentials
59
- pesapal.credentials = { :consumer_key => '<YOUR_CONSUMER_KEY>',
60
- :consumer_secret => '<YOUR_CONSUMER_SECRET>'
61
- }
65
+ # initiate pesapal object set to development mode and use the YAML file found at
66
+ # the specified location
67
+ pesapal = Pesapal::Merchant.new(:development, "<PATH_TO_YAML_FILE>")
68
+ ```
69
+
70
+ And the YAML file should look something like this. Feel free to change to the
71
+ appropriate values.
72
+
73
+ ```yaml
74
+ development:
75
+ callback_url: 'http://0.0.0.0:3000/pesapal/callback'
76
+ consumer_key: '<YOUR_CONSUMER_KEY>'
77
+ consumer_secret: '<YOUR_CONSUMER_SECRET>'
78
+
79
+ production:
80
+ callback_url: 'http://1.2.3.4:3000/pesapal/callback'
81
+ consumer_key: '<YOUR_CONSUMER_KEY>'
82
+ consumer_secret: '<YOUR_CONSUMER_SECRET>'
62
83
  ```
63
84
 
64
- By default the callback is set to `http://0.0.0.0:3000/pesapal/callback` on instantiation but you can easily set it to whatever works for you as shown below.
85
+ If the YAML file does not exist, then the object is set up with some bogus
86
+ credentials which would not work anyway and therefore, the next logical step is
87
+ that you set them yourself. Which, you can do using a hash as shown below
88
+ (please note that Pesapal provides different keys for different modes and since
89
+ this is like an override, there's the assumption that you chose the right one).
65
90
 
66
91
  ```ruby
67
- pesapal.callback_url = 'WHATEVER_URL_YOU_WANT'
92
+ # set pesapal api configuration manually (override YAML & bogus credentials)
93
+ pesapal.config = { :callback_url => 'http://0.0.0.0:3000/pesapal/callback'
94
+ :consumer_key => '<YOUR_CONSUMER_KEY>',
95
+ :consumer_secret => '<YOUR_CONSUMER_SECRET>'
96
+ }
68
97
  ```
69
98
 
99
+ _Ps: Make sure this hash has the appropriate values before running any methods
100
+ that interact with the API as the methods pick from these values. This means
101
+ that you can also override them at runtime for a truly dynamic/complex app that
102
+ might have different values for different scenarios._
103
+
104
+
70
105
  ### Post Order ###
71
106
 
72
- Once you've set up the credentials, set up the order details in a hash as shown
73
- in the example below ... all keys **MUST** be present. If there's one that you
74
- wish to ignore just leave it with a blank string but make sure it's included
107
+ Once you've finalized the configuration, set up the order details in a hash as
108
+ shown in the example below ... all keys **MUST** be present. If there's one that
109
+ you wish to ignore just leave it with a blank string but make sure it's included
75
110
  e.g. the phonenumber.
76
111
 
77
112
  ```ruby
@@ -89,24 +124,34 @@ pesapal.order_details = { :amount => 1000,
89
124
 
90
125
  Then generate the transaction url as below. In the example, the value is
91
126
  assigned to the variable `order_url` which you can pass on to the templating
92
- system of your to generate an iframe.
127
+ system of your choice to generate an iframe. Please note that this method
128
+ utilizes all that information set in the previous steps in generating the url so
129
+ it's important that it's the last step in the post order process.
93
130
 
94
131
  ```ruby
95
132
  # generate transaction url
96
133
  order_url = pesapal.generate_order_url
134
+
135
+ # order_url will a string with the url example;
136
+ # 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
97
137
  ```
98
138
 
139
+ _Ps: Please note the `:callback_url` value in the `pesapal.config` hash ...
140
+ after the user successfully posts the order, the response will be sent to this
141
+ url. Refer to [official Pesapal Step-By-Step integration guide][18] for more
142
+ details._
143
+
99
144
 
100
145
  Contributing
101
146
  ------------
102
147
 
103
- 1. [Fork it][8]
104
- 2. Create your feature branch (`git checkout -b wip-my-new-feature`)
105
- 3. Commit your changes (`git commit -am 'Add some feature with awesome'`)
106
- 4. Push to the branch (`git push origin wip-my-new-feature`)
107
- 5. Create new pull request
108
-
109
- _Ps: Please prefix branch name with 'wip-' ... means 'work in progress'._
148
+ 1. Make sure you've read the [M.O. ][14] ([blog article here][16])
149
+ 2. Especially [the part about my conventions when writing and merging new features][15]
150
+ 2. [Fork it][8]
151
+ 2. Create your feature branch (`git checkout -b BRANCH_NAME`)
152
+ 3. Commit your changes (`git commit -am 'AWESOME COMMIT MESSAGE'`)
153
+ 4. Push to the branch (`git push origin BRANCH_NAME`)
154
+ 5. Create new pull request and we can [have the conversations here][17]
110
155
 
111
156
 
112
157
  References
@@ -116,6 +161,7 @@ References
116
161
  * [Developing a RubyGem using Bundler][2]
117
162
  * [Make your own gem][3]
118
163
  * [Pesapal API Reference (Official)][4]
164
+ * [Pesapal Step-By-Step Reference (Official)][18]
119
165
  * [Pesapal PHP API Reference (Unofficial)][5]
120
166
 
121
167
 
@@ -139,3 +185,8 @@ they want as long as they provide attribution and waive liability.
139
185
  [11]: https://github.com/itsmrwave/pesapal-rubygem/blob/master/LICENSE.txt
140
186
  [12]: https://github.com/itsmrwave/pesapal-rubygem/releases/
141
187
  [13]: http://rubydoc.info/gems/pesapal/
188
+ [14]: https://github.com/itsmrwave/mo
189
+ [15]: https://github.com/itsmrwave/mo/tree/master/convention#-convention
190
+ [16]: http://kingori.co/articles/2013/09/modus-operandi/
191
+ [17]: https://github.com/itsmrwave/pesapal-rubygem/pulls
192
+ [18]: http://developer.pesapal.com/how-to-integrate/step-by-step
@@ -2,7 +2,7 @@ module Pesapal
2
2
 
3
3
  class Merchant
4
4
 
5
- attr_accessor :callback_url, :credentials, :order_details
5
+ attr_accessor :config, :order_details
6
6
  attr_reader :api_domain, :api_endpoints
7
7
 
8
8
  def api_domain
@@ -13,12 +13,8 @@ module Pesapal
13
13
  @api_endpoints
14
14
  end
15
15
 
16
- def callback_url
17
- @callback_url
18
- end
19
-
20
- def credentials
21
- @credentials
16
+ def config
17
+ @config
22
18
  end
23
19
 
24
20
  def order_details
@@ -27,6 +23,10 @@ module Pesapal
27
23
 
28
24
  private
29
25
 
26
+ def mode
27
+ @mode
28
+ end
29
+
30
30
  def params
31
31
  @params
32
32
  end
@@ -42,32 +42,21 @@ module Pesapal
42
42
  public
43
43
 
44
44
  # constructor
45
- def initialize(mode = :development)
46
-
47
- # convert symbol to string and downcase
48
- mode.to_s.downcase!
45
+ def initialize(mode = :development, path_to_file = "#{Rails.root}/config/pesapal.yml")
49
46
 
50
47
  # initialize
51
48
  @params = nil
52
49
  @post_xml = nil
53
50
  @token_secret = nil
54
51
 
55
- # set the credentials from the config (if initializers/pesapal.rb
56
- # exists they should have set these values)
57
- @credentials = nil
52
+ # convert symbol to string and downcase
53
+ @mode = "#{mode.to_s.downcase}"
58
54
 
59
- # set the callback url that the iframe will respond to
60
- @callback_url = 'http://0.0.0.0:3000/pesapal/callback'
55
+ # set the credentials
56
+ set_configuration_from_yaml path_to_file
61
57
 
62
58
  # set api endpoints depending on the mode
63
- @api_endpoints = {}
64
- if mode == 'development'
65
- set_endpoints_development
66
- elseif mode == 'production'
67
- set_endpoints_production
68
- else
69
- set_endpoints_development
70
- end
59
+ set_endpoints
71
60
  end
72
61
 
73
62
  # generate pesapal order url (often iframed)
@@ -78,7 +67,7 @@ module Pesapal
78
67
  @post_xml = Pesapal::Post::generate_post_xml @order_details
79
68
 
80
69
  # initialize setting of @params (oauth_signature left empty) ... this gene
81
- @params = Pesapal::Post::set_parameters(@callback_url, @credentials[:consumer_key], @post_xml)
70
+ @params = Pesapal::Post::set_parameters(@credentials[:callback_url], @credentials[:consumer_key], @post_xml)
82
71
 
83
72
  # generate oauth signature and add signature to the request parameters
84
73
  @params[:oauth_signature] = Pesapal::Oauth::generate_oauth_signature("GET", @api_endpoints[:postpesapaldirectorderv4], @params, @credentials[:consumer_secret], @token_secret)
@@ -91,24 +80,60 @@ module Pesapal
91
80
 
92
81
  private
93
82
 
94
- # set all endpoint for use in development mode
95
- def set_endpoints_development
96
- @api_domain = 'http://demo.pesapal.com'
97
- set_endpoints @api_domain
83
+ # set endpoints
84
+ def set_endpoints
85
+
86
+ if @mode == 'production'
87
+ @api_domain = 'https://www.pesapal.com'
88
+ else
89
+ @api_domain = 'http://demo.pesapal.com'
90
+ end
91
+
92
+ @api_endpoints = {}
93
+ @api_endpoints[:postpesapaldirectorderv4] = "#{@api_domain}/API/PostPesapalDirectOrderV4"
94
+ @api_endpoints[:querypaymentstatus] = "#{@api_domain}/API/QueryPaymentStatus"
95
+ @api_endpoints[:querypaymentstatusbymerchantref] = "#{@api_domain}/API/QueryPaymentStatus"
96
+ @api_endpoints[:querypaymentdetails] = "#{@api_domain}/API/QueryPaymentDetails"
98
97
  end
99
98
 
100
- # set all enpoints for use in production mode
101
- def set_endpoints_production
102
- @api_domain = "https://www.pesapal.com"
103
- set_endpoints @api_domain
99
+ # set credentialts through hash, uses default if nothing is input
100
+ def set_configuration(consumer_details = {})
101
+
102
+ # set the configuration
103
+ @config = { :callback_url => 'http://0.0.0.0:3000/pesapal/callback'
104
+ :consumer_key => '<YOUR_CONSUMER_KEY>',
105
+ :consumer_secret => '<YOUR_CONSUMER_SECRET>'
106
+ }
107
+
108
+ valid_config_keys = @config.keys
109
+
110
+ consumer_details.each { |k,v| @config[k.to_sym] = v if valid_config_keys.include? k.to_sym }
104
111
  end
105
112
 
106
- # set endpoints
107
- def set_endpoints(domain_string)
108
- @api_endpoints[:postpesapaldirectorderv4] = "#{domain_string}/API/PostPesapalDirectOrderV4"
109
- @api_endpoints[:querypaymentstatus] = "#{domain_string}/API/QueryPaymentStatus"
110
- @api_endpoints[:querypaymentstatusbymerchantref] = "#{domain_string}/API/QueryPaymentStatus"
111
- @api_endpoints[:querypaymentdetails] = "#{domain_string}/API/QueryPaymentDetails"
113
+ # set configuration through yaml file
114
+ def set_configuration_from_yaml(path_to_file)
115
+
116
+ if File.exist?(path_to_file)
117
+
118
+ # load file, read it and parse the YAML
119
+ begin
120
+ loaded_config = YAML::load(IO.read(path_to_file))
121
+ rescue Errno::ENOENT
122
+ logger.info("YAML configuration file couldn't be found. Using defaults."); return
123
+ rescue Psych::SyntaxError
124
+ logger.info("YAML configuration file contains invalid syntax. Using defaults."); return
125
+ end
126
+
127
+ # pick the correct settings depending on the the mode and
128
+ # set it appropriately. this file is expected to have the
129
+ # settings for development and production
130
+ set_configuration loaded_config[@mode]
131
+
132
+ else
133
+
134
+ # in this case default values will be set
135
+ set_configuration
136
+ end
112
137
  end
113
138
  end
114
139
  end
@@ -1,3 +1,3 @@
1
1
  module Pesapal
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -5,12 +5,12 @@ require "pesapal/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "pesapal"
7
7
  spec.version = Pesapal::VERSION
8
- spec.date = "2013-09-28"
8
+ spec.date = "2013-10-01"
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!"
12
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 = "https://github.com/itsmrwave/pesapal-rubygem#pesapal-rubygem"
13
+ spec.homepage = "http://rubydoc.info/gems/pesapal/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
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: 0.0.3
4
+ version: 0.1.0
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-09-28 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,7 +70,7 @@ files:
70
70
  - lib/pesapal/oauth.rb
71
71
  - lib/pesapal/version.rb
72
72
  - pesapal.gemspec
73
- homepage: https://github.com/itsmrwave/pesapal-rubygem#pesapal-rubygem
73
+ homepage: http://rubydoc.info/gems/pesapal/
74
74
  licenses:
75
75
  - MIT
76
76
  metadata: {}