sermepa 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2UyMDkyYTFiNGU1MDM3MGVkOTliYTgyNzY1NTA5NDFkYjA2NGY2Mw==
4
+ ZmFiYWU5M2M3ZDI3M2NkNzgzODIzZDgzZDM1YTA5MWY4MmVmOTM3Mw==
5
5
  data.tar.gz: !binary |-
6
- ZDhiNzQ5Yzc0ZmI4OGJjZDM0NTFmNjE4NjU2NTQyMWMwYWE3YmRhNQ==
6
+ NDhjYzA2YzQ2YTg2ODZlZWJmOWFjOGE2ZmVhZDlmZDc1ZjA4ZjA1Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjA1Y2FmNTUzMDIzNjc4ZmRkODRjNDYzYTdiY2Q5NDUyYTkwMjk0NDRlYTcz
10
- YTRjODg5M2M4NDc1NWM3YWEwYTE5NTkzZWYwZTczNjkzN2Y4MGYzMDNmMGEy
11
- YTQ1MjIwZDExYzE4OGY2MjNiM2MzZTM0YTI4NjBlZGIyZTcwYWE=
9
+ MjdiZTgxMDQyYjcxMGM5OTEwZTZlOGZlYzczNWQ2ZGQ1YTA1ZmM4Y2YyZWEw
10
+ NTE5M2MyMzJiMzllNGVlYWRhOWM5YjUwYTIyMmU1ZWJlZTZlOTljZTYzODI2
11
+ MGYyY2Q0OTZlMDFkZTdlMWM5YjIzY2ZjOTQ0OGNjNGE2NWNjYjk=
12
12
  data.tar.gz: !binary |-
13
- ODdjMDc0YWY5ZmVlODgwMTZjNmE0NmIwZjBmZTY2NWE2NmZiZjk2ZDc0MGIy
14
- M2E5MWRmNTM0NGU2OTU1YTM0MDAxYmRkYWE4MzdmMzVmYjQzYjdjMzU2Mzcw
15
- ZmEyYmE3YzY2OWJkNGNhZjBjZDU5NGI2ZmE1OTZhYTZmZTU5ZWI=
13
+ ZGE4YjJlY2E0N2UyZTQ1YzAyNGI0NTFmNjBjZWU3MDc1Y2M2YzUyZWFlZTcy
14
+ YmQyNTIzYzYxMzM5MGQ2YmRkODRjMzEzMjUzYWVmYTU2NjllMTJjY2MxNTEx
15
+ M2I5M2FmY2FiMjA2YjI5ODk0NzgzMGU4MDFlOWNjNWI5YjE4MWU=
data/README.md CHANGED
@@ -58,6 +58,7 @@ Timeout::timeout(20) {
58
58
 
59
59
  * Sermepa::SermepaRemoteError
60
60
  * Sermepa::SermepaPaymentError
61
+ * Sermepa::SermepaInvalidSignature
61
62
 
62
63
  How to use (with Form)
63
64
  -----------------------------
@@ -145,5 +145,12 @@ module Sermepa
145
145
  "#{ @error_code }: #{ message }"
146
146
  end
147
147
  end
148
+
149
+ class SermepaInvalidSignature < StandardError
148
150
 
151
+ def message
152
+ "Invalid signature. Signature does not match with expected signature"
153
+ end
154
+ end
155
+
149
156
  end
@@ -1,8 +1,8 @@
1
1
  module Sermepa
2
2
  module FormHelper
3
- def sermepa_payment_form(amount, params = {}, &block)
3
+ def sermepa_form_fields(amount, params = {})
4
4
  values = {
5
- DS_MERCHANT_AMOUNT: (amount.to_f * 100).to_i,
5
+ DS_MERCHANT_AMOUNT: amount.to_i,
6
6
  DS_MERCHANT_CURRENCY: CURRENCIES[params[:currency] || Sermepa.config.currency],
7
7
  DS_MERCHANT_PRODUCTDESCRIPTION: params[:description],
8
8
  DS_MERCHANT_TITULAR: params[:titular],
@@ -16,6 +16,11 @@ module Sermepa
16
16
  DS_MERCHANT_CONSUMERLANGUAGE: params[:consumer_language] || Sermepa.config.consumer_language
17
17
  }
18
18
  values[:DS_MERCHANT_MERCHANTSIGNATURE] = Sermepa::signature(values)
19
+ values
20
+ end
21
+
22
+ def sermepa_payment_form(amount, params = {}, &block)
23
+ values = sermepa_form_fields(amount, params)
19
24
 
20
25
  output = ActiveSupport::SafeBuffer.new
21
26
  form_tag Sermepa.config.post_url do
@@ -23,13 +28,9 @@ module Sermepa
23
28
  values.each_pair do |k,v|
24
29
  output << hidden_field_tag(k, v) if v
25
30
  end
26
- if block_given?
27
- output << capture(&block)
28
- else
29
- output << submit_tag(t 'send')
30
- end
31
+ output << block_given? ? capture(&block) : submit_tag(t 'sermepa.payment_form.send_action')
31
32
  end
32
-
33
+ output
33
34
  end
34
35
  end
35
36
  end
@@ -0,0 +1,16 @@
1
+ require 'digest/sha1'
2
+
3
+ module Sermepa
4
+ def check_signature(params, secret = nil)
5
+ token = "#{params[:Ds_Amount]}#{params[:Ds_Order]}#{params[:Ds_MerchantCode]}#{params[:Ds_Currency]}#{params[:Ds_Response]}#{secret || config.secret}"
6
+
7
+ check_code = Digest::SHA1.hexdigest(token)
8
+
9
+ return true if check_code.upcase == params[:Ds_Signature].upcase
10
+
11
+ # Invalid signature
12
+ raise SermepaInvalidSignature.new if Sermepa.config.raise_errors
13
+ false
14
+ end
15
+
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Sermepa
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/sermepa.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "sermepa/sermepa"
2
2
  require "sermepa/config"
3
+ require "sermepa/form_helper"
3
4
  require "sermepa/signature"
5
+ require "sermepa/utils"
4
6
  require "sermepa/version"
5
7
  require "sermepa/railtie" if defined?(Rails)
6
8
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sermepa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Endika Gutiérrez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
11
+ date: 2013-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.8
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.8
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: savon
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,7 @@ files:
66
66
  - lib/sermepa/railtie.rb
67
67
  - lib/sermepa/sermepa.rb
68
68
  - lib/sermepa/signature.rb
69
+ - lib/sermepa/utils.rb
69
70
  - lib/sermepa/version.rb
70
71
  - lib/sermepa.rb
71
72
  - lib/tasks/sermepa_tasks.rake
@@ -124,7 +125,7 @@ rubyforge_project:
124
125
  rubygems_version: 2.0.5
125
126
  signing_key:
126
127
  specification_version: 4
127
- summary: Sermepa SOAP gateway for rails.
128
+ summary: Sermepa gateway for rails.
128
129
  test_files:
129
130
  - test/dummy/app/assets/javascripts/application.js
130
131
  - test/dummy/app/assets/stylesheets/application.css