sermepa 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,13 @@
1
1
  module Sermepa
2
2
 
3
- Config = Struct.new(:_logger, :service_url, :merchant_code, :secret, :terminal, :currency, :raise_errors, :callback_url) do
3
+ Config = Struct.new(:_logger, :service_url, :merchant_code, :secret, :terminal, :currency, :raise_errors, :merchant_url,
4
+ :url_ok, :url_ko, :consumer_language, :post_url) do
4
5
 
5
6
  def self.default
6
7
  config = new
7
8
  config._logger = Logger.new STDOUT
8
9
  config.raise_errors = true
10
+ config.consumer_language = '001' # ES
9
11
  config
10
12
  end
11
13
 
@@ -0,0 +1,36 @@
1
+ module Sermepa
2
+ module FormHelper
3
+ def sermepa_payment_form(amount, params = {}, &block)
4
+ values = {
5
+ DS_MERCHANT_AMOUNT: (amount.to_f * 100).to_i,
6
+ DS_MERCHANT_CURRENCY: CURRENCIES[params[:currency] || config.currency],
7
+ DS_MERCHANT_PRODUCTDESCRIPTION: params[:description],
8
+ DS_MERCHANT_TITULAR: params[:titular],
9
+ DS_MERCHANT_ORDER: params[:order] || Time.now.to_i,
10
+ DS_MERCHANT_MERCHANTCODE: params[:merchant_code] || config.merchant_code,
11
+ DS_MERCHANT_TERMINAL: params[:terminal] || config.terminal,
12
+ DS_MERCHANT_TRANSACTIONTYPE: TRANSACTION_TYPES[params[:transaction_type]],
13
+ DS_MERCHANT_MERCHANTURL: params[:merchant_url] || config.merchant_url,
14
+ DS_MERCHANT_URLOK: params[:url_ok] || config.url_ok,
15
+ DS_MERCHANT_URLKO: params[:url_ko] || config.url_ko,
16
+ DS_MERCHANT_CONSUMERLANGUAGE: params[:consumer_language] || config.consumer_language
17
+ }
18
+ values[:DS_MERCHANT_MERCHANTSIGNATURE] = signature(values)
19
+
20
+ output = ActiveSupport::SafeBuffer.new
21
+
22
+ form_tag config.post_url do
23
+ output = ActiveSupport::SafeBuffer.new
24
+ values.each_pair do |k,v|
25
+ output << hidden_field_tag(k, v) if v
26
+ end
27
+ if block_given?
28
+ output << capture(&block)
29
+ else
30
+ output << submit_tag(t 'send')
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ require 'sermepa/form_helper'
2
+
3
+ module Sermepa
4
+ class Railtie < Rails::Railtie
5
+ initializer "sermepa.form_helper" do
6
+ ActionView::Base.send :include, FormHelper
7
+ end
8
+ end
9
+ end
@@ -14,8 +14,7 @@ module Sermepa
14
14
  DS_MERCHANT_ORDER: params[:order].to_s,
15
15
  DS_MERCHANT_TRANSACTIONTYPE: TRANSACTION_TYPES[transaction_type]
16
16
  }
17
-
18
- #values[:DS_MERCHANT_MERCHANTURL] = Sermepa.config.callback_url if Sermepa.config.callback_url
17
+ values[:DS_MERCHANT_MERCHANTURL] = Sermepa.config.merchant_url if Sermepa.config.merchant_url
19
18
 
20
19
  values
21
20
  end
@@ -10,7 +10,7 @@ module Sermepa
10
10
  token += values[:DS_MERCHANT_PAN].to_s
11
11
  token += values[:DS_MERCHANT_CVV2].to_s
12
12
  token += values[:DS_MERCHANT_TRANSACTIONTYPE].to_s
13
- #token += values[:DS_MERCHANT_MERCHANTURL].to_s
13
+ token += values[:DS_MERCHANT_MERCHANTURL].to_s if config.merchant_url
14
14
  token += secret || config.secret
15
15
 
16
16
  Digest::SHA1.hexdigest(token)
@@ -1,3 +1,3 @@
1
1
  module Sermepa
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/sermepa.rb CHANGED
@@ -2,6 +2,7 @@ require "sermepa/sermepa"
2
2
  require "sermepa/config"
3
3
  require "sermepa/signature"
4
4
  require "sermepa/version"
5
+ require "sermepa/railtie" if defined?(Rails)
5
6
 
6
7
  module Sermepa
7
8
  extend self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sermepa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
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: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- description: Sermepa gateway for rails
62
+ description: Sermepa is a spanish payments gateway
63
63
  email:
64
64
  - me@endika.net
65
65
  executables: []
@@ -69,6 +69,8 @@ files:
69
69
  - lib/sermepa/config.rb
70
70
  - lib/sermepa/constants.rb
71
71
  - lib/sermepa/errors.rb
72
+ - lib/sermepa/form_helper.rb
73
+ - lib/sermepa/railtie.rb
72
74
  - lib/sermepa/sermepa.rb
73
75
  - lib/sermepa/signature.rb
74
76
  - lib/sermepa/version.rb
@@ -130,7 +132,7 @@ rubyforge_project:
130
132
  rubygems_version: 1.8.24
131
133
  signing_key:
132
134
  specification_version: 3
133
- summary: Sermepa gateway for rails
135
+ summary: Sermepa SOAP gateway for rails.
134
136
  test_files:
135
137
  - test/dummy/app/assets/javascripts/application.js
136
138
  - test/dummy/app/assets/stylesheets/application.css