khipu-rails 0.0.1 → 1.3.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: afe86cd2381326f7498e3e3d18705bd590601c65
4
+ data.tar.gz: 9e15f6290e3c8ab8d6da845d7a120576dca1b029
5
+ SHA512:
6
+ metadata.gz: 31339a0a406d849fef4be7669f9f5207f00f4597848def1c786e3ce5de483104bed8593453be89e5de3f005db3409f9c001621d862147560d6536df7db972e6e
7
+ data.tar.gz: eba94c9ac2b82464460ae4052f4cfa650fbb8433ddc5f3841513343d05746f20d38470da3a946a88c65968d79d332930c9477c1b0f0ecae5faf64f8122d24628
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # KhipuRails
2
2
 
3
- [Khipu](https://khipu.com/home) is a service that facilitates web billing and collection in Chile.
3
+ [Khipu](https://khipu.com/home) is a service that facilitates web billing and collection in **Chile**.
4
+
4
5
  It handles very elegantly bank transfers and allows to generate bills in batches.
5
6
  It offers an API for developers to create via POST new charges.
6
7
 
@@ -11,13 +12,38 @@ Add to your Gemfile and run the `bundle` command to install it.
11
12
  gem 'khipu-rails'
12
13
  ```
13
14
 
14
- Create an initializer with the following code.
15
+ If you want to work with the gem in development, you can allways use the git repository.
15
16
  ```ruby
16
- KhipuRails::Config.user_id = ID
17
- KhipuRails::Config.api_key = API KEY
17
+ gem 'khipu-rails', :git => "http://github.com/Janther/khipu-rails"
18
18
  ```
19
19
 
20
- *ID and API KEY can be found [here](https://khipu.com/merchant/profile#instant-notification-data)*
20
+ ## Configuration v0.0.2
21
+ Version 0.0.2 will have a configure method much more flexible and powerfull
22
+ ```ruby
23
+ KhipuRails.configure do |config|
24
+ ##
25
+ # Use receivers to set one or more receivers to the gem.
26
+ # #add_receiver has 3 parameters, receiver_id, receiver_key, and receiver_mode(:dev|:pro)
27
+ ##
28
+ config.add_receiver "receiver1_id", "receiver1_key", :dev
29
+ config.add_receiver "receiver2_id", "receiver2_key", :pro
30
+ ...
31
+
32
+ ##
33
+ # Use button_images to set one or more urls for the custom button images you might have.
34
+ # Khipu's images are already registered.
35
+ # Each button image is key/value pair
36
+ # The same as with the receivers registration, use this method as a shortcut for long urls on your view.
37
+ ##
38
+ config.button_images.merge! :shortcut => "url"
39
+
40
+ ##
41
+ # The hash defaults can also be modified, giving you control of the default values the helper khipu_button uses.
42
+ ##
43
+ config.button_defaults.merge! :variable_name => variable_value
44
+ end
45
+ ```
46
+ *receiver_id and receiver_key can be found [here](https://khipu.com/merchant/profile#instant-notification-data)*
21
47
 
22
48
  # Features
23
49
 
@@ -64,18 +90,38 @@ Options:
64
90
 
65
91
  **200x75**: ![200x75 Button](https://s3.amazonaws.com/static.khipu.com/buttons/200x75.png)
66
92
 
67
- # TODO:
68
-
69
- ## Validation of payment notifications
93
+ ## Validation of payment notifications *(Waiting for Khipu to release developer accounts.)*
70
94
 
71
95
  If you provide an URL for Khipu to deliver [notifications](https://khipu.com/page/api#notification-instantanea) on succesfull payments, this gem provides a validation method to prevent forgery of notifications.
72
96
 
73
97
  ### khipu_validation
74
98
 
75
- **khipu_validation params, local_validation = false**
99
+ **KhipuRails::NotificationValidator.is_valid? notification, mode = :local**
100
+
101
+ * **notification**: The POST params delivered by Khipu.
102
+ * **mode**: Whether the validation should be done at the **[:local](https://khipu.com/page/api#validacion-local)** or by **[:webservice](https://khipu.com/page/api#validacion-web-service)**.
103
+
104
+ # TODO:
105
+
106
+ ## New Features
107
+
108
+ ### khipu_button v2
109
+ **khipu_button subject, amount, options = {}, &block**
110
+
111
+ Options:
112
+ * **:hash_url**: if provided the hash won't be generated by default and upon submit, it will be requested.
113
+ * **:form_options**: html options for the form.
114
+ * **:button_options**: html options for the button.
115
+
116
+ Block
117
+ &block: If a block is given the helper will render it within the form. This can be usefull for further customization of the form.
118
+
119
+ **If the block contains a submit input, a button or an image input, it won't render the image input provided by the helper.**
120
+
121
+ ### khipu_hash
122
+ **khipu_hash options = {}**
76
123
 
77
- * **params**: The POST params delivered by Khipu.
78
- * **local_validation**: Wether the validation should be done at the [local machine](https://khipu.com/page/api#validacion-local) or by [Khipu's API](https://khipu.com/page/api#validacion-web-service).
124
+ Generator of the Khipu hash made public so you can include it in an action when **:hash_url** is given to the form.
79
125
 
80
126
  ## Contributing
81
127
 
@@ -0,0 +1,5 @@
1
+ module KhipuRails
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ module KhipuRails
2
+ class KhipuController < KhipuRails::ApplicationController
3
+ def notification
4
+ @notification = {
5
+ api_version: params[:api_version],
6
+ receiver_id: params[:receiver_id],
7
+ notification_id: params[:notification_id],
8
+ subject: params[:subject],
9
+ amount: params[:amount],
10
+ currency: params[:currency],
11
+ transaction_id: params[:transaction_id],
12
+ payer_email: params[:payer_email],
13
+ custom: params[:custom],
14
+ notification_signature: params[:notification_signature]
15
+ }
16
+
17
+ valid = KhipuRails::NotificationValidator.is_valid?(@notification, :webservice)
18
+ # if valid
19
+ # else
20
+ # end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Gracias khipu.</h1>
2
+ <small>Powered by khipu-rails</small>
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Khipu-Rails</title>
6
+ </head>
7
+ <body>
8
+ <%= yield %>
9
+ </body>
10
+ </html>
@@ -0,0 +1,81 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFuDCCBSGgAwIBAgIQHCWU8WfzVpZq9iYPMgYpVzANBgkqhkiG9w0BAQUFADCB
3
+ 0DEUMBIGA1UEChMLRS1TaWduIFMuQS4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0
4
+ IE5ldHdvcmsxODA2BgNVBAsTL1Rlcm1zIG9mIHVzZSBhdCBodHRwczovL3d3dy5l
5
+ LXNpZ24uY2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Wm7bmaDvZVJ
22
+ -----END CERTIFICATE-----
@@ -0,0 +1,3 @@
1
+ KhipuRails::Engine.routes.draw do
2
+ post '/khipu_notification' => 'khipu#notification'
3
+ end
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = KhipuRails::VERSION
9
9
  gem.authors = ["Klaus Hott Vidal"]
10
10
  gem.email = ["klahott@gmail.com"]
11
- gem.description = %q{This gem provides a rails wrapper for the khipu api.}
12
- gem.summary = %q{This gem provides a rails wrapper for the khipu api.}
11
+ gem.description = %q{This gem provides an ActionView helper that creates a form following Khipu's documentation.}
12
+ gem.summary = %q{Wrapper for the Khipu api.}
13
13
  gem.homepage = %q{https://github.com/janther/khipu-rails}
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
@@ -17,9 +17,11 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "rails", "~> 3.1.10"
20
+ gem.add_dependency "rails", ">= 3.1"
21
+ gem.add_dependency "jquery-rails"
22
+ gem.add_dependency "nokogiri"
23
+ gem.add_dependency "httpclient"
21
24
 
22
25
  gem.add_development_dependency "rspec-rails"
23
- gem.add_development_dependency "nokogiri"
24
26
  gem.add_development_dependency "capybara", "~> 1.1.2"
25
27
  end
@@ -1,7 +1,9 @@
1
1
  # encoding: utf-8
2
2
  require "khipu_rails"
3
3
  require "khipu_rails/version"
4
+ require "khipu_rails/receiver"
4
5
  require "khipu_rails/config"
5
6
  require "khipu_rails/button_helper"
7
+ require "khipu_rails/notification_validator"
6
8
 
7
9
  ActionView::Base.send :include, KhipuRails::ButtonHelper
@@ -1,2 +1,61 @@
1
+ # encoding: utf-8
1
2
  module KhipuRails
2
- end
3
+ extend self
4
+
5
+ def configure
6
+ yield config
7
+ end
8
+
9
+ def config
10
+ @config ||= Config.default
11
+ end
12
+
13
+ attr_writer :config
14
+
15
+ def khipu_hash options = {}
16
+ options.reverse_merge! KhipuRails.config.button_defaults
17
+
18
+ receiver = load_receiver options
19
+ OpenSSL::HMAC.hexdigest('sha256', receiver.key, raw_hash(options, receiver))
20
+ end
21
+
22
+ def raw_hash options = {}, receiver = load_receiver(options)
23
+ options.reverse_merge! KhipuRails.config.button_defaults
24
+
25
+ raw = [
26
+ "receiver_id=#{receiver.id}",
27
+ "subject=#{options[:subject]}",
28
+ "body=#{options[:body]}",
29
+ "amount=#{options[:amount]}",
30
+ "payer_email=#{options[:payer_email]}",
31
+ "bank_id=#{options[:bank_id]}",
32
+ "expires_date=#{options[:expires_date]}",
33
+ "transaction_id=#{options[:transaction_id]}",
34
+ "custom=#{options[:custom]}",
35
+ "notify_url=#{options[:notify_url]}",
36
+ "return_url=#{options[:return_url]}",
37
+ "cancel_url=#{options[:cancel_url]}",
38
+ "picture_url=#{options[:picture_url]}"
39
+ ].join('&')
40
+
41
+ raw
42
+ end
43
+
44
+ def root
45
+ File.expand_path '../..', __FILE__
46
+ end
47
+
48
+ private
49
+
50
+ def load_receiver options
51
+ if options[:receiver_id].present?
52
+ if options[:secret].present?
53
+ KhipuRails::Receiver.new options[:receiver_id], options[:secret]
54
+ else
55
+ KhipuRails.config.receivers.find{|r| r.id == options[:receiver_id]}
56
+ end
57
+ else
58
+ KhipuRails.config.receivers.first
59
+ end
60
+ end
61
+ end
@@ -3,55 +3,66 @@ module KhipuRails
3
3
  module ButtonHelper
4
4
  def khipu_button subject, amount, options = {}
5
5
  options.reverse_merge! body: '',
6
+ payer_email: '',
7
+ bank_id: '',
8
+ expires_date: '',
9
+ notify_url: '',
6
10
  return_url: '',
7
11
  cancel_url: '',
8
12
  transaction_id: '',
9
- payer_email: '',
10
13
  picture_url: '',
11
14
  custom: '',
12
- button_image: '50x25', #Default Button Image
13
- receiver_id: KhipuRails::Config.user_id, #Loads user id from configuration
14
- secret: KhipuRails::Config.api_key #Loads api key from configuration
15
+ button_image: '50x25', #Default Button Image
16
+ receiver_id: KhipuRails.config.receivers.first.id #Loads first receiver from configuration by default
15
17
 
16
- options[:subject] = subject #Adds the subject param to the options for khipu_hash
17
- options[:amount] = amount #Adds the amount param to the options for khipu_hash
18
+ button_image = KhipuRails.config.button_images()[options[:button_image]] || options[:button_image]
18
19
 
19
- button_image = KhipuRails::Config.khipu_images()[options[:button_image]] || options[:button_image]
20
-
21
- form_tag 'https://khipu.com/payment/api/createPaymentPage', authenticity_token: false do
22
- [].tap do |i|
23
- i << hidden_field_tag(:receiver_id, options[:receiver_id])
20
+ form_tag 'https://khipu.com/api/1.3/createPaymentPage', authenticity_token: false do
21
+ fields = [].tap do |i|
22
+ i << hidden_field_tag(:receiver_id, options[:receiver_id])
24
23
  i << hidden_field_tag(:subject, subject)
25
- i << hidden_field_tag(:body, options[:body])
26
- i << hidden_field_tag(:amount, amount)
27
- i << hidden_field_tag(:return_url, options[:return_url])
28
- i << hidden_field_tag(:cancel_url, options[:cancel_url])
29
- i << hidden_field_tag(:custom, options[:custom])
24
+ i << hidden_field_tag(:body, options[:body])
25
+ i << hidden_field_tag(:amount, amount)
26
+ i << hidden_field_tag(:payer_email, options[:payer_email])
27
+ i << hidden_field_tag(:bank_id, options[:bank_id])
28
+ i << hidden_field_tag(:expires_date, options[:expires_date])
30
29
  i << hidden_field_tag(:transaction_id, options[:transaction_id])
31
- i << hidden_field_tag(:payer_email, options[:payer_email])
32
- i << hidden_field_tag(:picture_url, options[:picture_url])
33
- i << hidden_field_tag(:hash, khipu_hash(options))
30
+ i << hidden_field_tag(:custom, options[:custom])
31
+ i << hidden_field_tag(:notify_url, options[:notify_url])
32
+ i << hidden_field_tag(:return_url, options[:return_url])
33
+ i << hidden_field_tag(:cancel_url, options[:cancel_url])
34
+ i << hidden_field_tag(:picture_url, options[:picture_url])
35
+ end.join.html_safe
36
+
37
+ ng = Nokogiri::HTML.parse fields
38
+
39
+ hash_fields = {
40
+ receiver_id: get_value(ng, :receiver_id),
41
+ subject: get_value(ng, :subject),
42
+ body: get_value(ng, :body),
43
+ amount: get_value(ng, :amount),
44
+ payer_email: get_value(ng, :payer_email),
45
+ bank_id: get_value(ng, :bank_id),
46
+ expires_date: get_value(ng, :expires_date),
47
+ transaction_id: get_value(ng, :transaction_id),
48
+ custom: get_value(ng, :custom),
49
+ notify_url: get_value(ng, :notify_url),
50
+ return_url: get_value(ng, :return_url),
51
+ cancel_url: get_value(ng, :cancel_url),
52
+ picture_url: get_value(ng, :picture_url),
53
+ secret: options[:secret]
54
+ }
55
+
56
+ [fields].tap do |i|
57
+ i << hidden_field_tag(:hash, KhipuRails.khipu_hash(hash_fields))
34
58
  i << image_submit_tag(button_image, name: :submit)
35
59
  end.join.html_safe
36
60
  end
37
61
  end
38
62
 
39
63
  private
40
- def khipu_hash options = {}
41
- raw = [
42
- "receiver_id=#{options[:receiver_id]}",
43
- "subject=#{options[:subject]}",
44
- "body=#{options[:body]}",
45
- "amount=#{options[:amount]}",
46
- "return_url=#{options[:return_url]}",
47
- "cancel_url=#{options[:cancel_url]}",
48
- "custom=#{options[:custom]}",
49
- "transaction_id=#{options[:transaction_id]}",
50
- "picture_url=#{options[:picture_url]}",
51
- "payer_email=#{options[:payer_email]}",
52
- "secret=#{options[:secret]}"
53
- ].join('&')
54
- Digest::SHA1.hexdigest raw
64
+ def get_value inputs, attribute
65
+ inputs.css("input[name=#{attribute}]").attribute('value').value
55
66
  end
56
67
  end
57
68
  end