sermepa 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2UyMDkyYTFiNGU1MDM3MGVkOTliYTgyNzY1NTA5NDFkYjA2NGY2Mw==
5
+ data.tar.gz: !binary |-
6
+ ZDhiNzQ5Yzc0ZmI4OGJjZDM0NTFmNjE4NjU2NTQyMWMwYWE3YmRhNQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZjA1Y2FmNTUzMDIzNjc4ZmRkODRjNDYzYTdiY2Q5NDUyYTkwMjk0NDRlYTcz
10
+ YTRjODg5M2M4NDc1NWM3YWEwYTE5NTkzZWYwZTczNjkzN2Y4MGYzMDNmMGEy
11
+ YTQ1MjIwZDExYzE4OGY2MjNiM2MzZTM0YTI4NjBlZGIyZTcwYWE=
12
+ data.tar.gz: !binary |-
13
+ ODdjMDc0YWY5ZmVlODgwMTZjNmE0NmIwZjBmZTY2NWE2NmZiZjk2ZDc0MGIy
14
+ M2E5MWRmNTM0NGU2OTU1YTM0MDAxYmRkYWE4MzdmMzVmYjQzYjdjMzU2Mzcw
15
+ ZmEyYmE3YzY2OWJkNGNhZjBjZDU5NGI2ZmE1OTZhYTZmZTU5ZWI=
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  Sermepa Gem for Rails
2
2
  =====================
3
3
 
4
- How to use
5
- ----------
4
+ How to use (SOAP WebServices)
5
+ -----------------------------
6
6
 
7
7
  ### Configure
8
8
 
9
- Add initalizer for sermepa configuration:
9
+ Add initalizer for sermepa configuration (config/initializers/sermepa.rb):
10
10
 
11
11
  ```ruby
12
12
  Sermepa.configure do |config|
@@ -20,7 +20,7 @@ Sermepa.configure do |config|
20
20
  config.terminal = '1' # Terminal code
21
21
  config.currency = :EUR # Currency (:EUR, :USD, :GBP, :JPY)
22
22
  config.raise_errors = true # If true will raise exceptions when error ocurrs
23
- config.callback_url = "Here goes callback URL"
23
+ config.merchant_url = "Here goes callback URL"
24
24
  end
25
25
  ```
26
26
 
@@ -59,4 +59,53 @@ Timeout::timeout(20) {
59
59
  * Sermepa::SermepaRemoteError
60
60
  * Sermepa::SermepaPaymentError
61
61
 
62
+ How to use (with Form)
63
+ -----------------------------
62
64
 
65
+ ### Configure
66
+
67
+ Add initalizer for sermepa configuration (config/initializers/sermepa.rb):
68
+
69
+ ```ruby
70
+ Sermepa.configure do |config|
71
+ # For testing
72
+ config.post_url = 'https://sis-t.sermepa.es:25443/sis/realizarPago'
73
+ # For production
74
+ # config.post_url = 'https://sis.sermepa.es/sis/realizarPago'
75
+
76
+ config.merchant_code = 'Here goes merchant code'
77
+ config.secret = 'Here goes secret'
78
+ config.terminal = '1' # Terminal code
79
+ config.currency = :EUR # Currency (:EUR, :USD, :GBP, :JPY)
80
+ config.merchant_url = "Here goes callback URL" # optional
81
+ config.url_ok = "Success url" # optional
82
+ config.url_ko = "Fail url" # optional
83
+ end
84
+ ```
85
+
86
+ ### Adding payment form
87
+
88
+ Include form in view
89
+ ```ruby
90
+ <%= sermepa_payment_form amount, {options map} do %>
91
+ <%= submit_tag 'Send' %>
92
+ <% end %>
93
+ ```
94
+
95
+ Or just:
96
+ ```ruby
97
+ <%= sermepa_payment_form amount, {options map} %>
98
+ ```
99
+
100
+ Allowed options are:
101
+ * currency (optional)
102
+ * description (optional)
103
+ * titular (optional)
104
+ * order (defaults to current timestamp)
105
+ * transaction_type
106
+ * merchant_url (defaults to config)
107
+ * url_ok (defaults to config)
108
+ * url_ko (defaults to config)
109
+ * consumer_language (default spanish)
110
+ * merchant_code (defaults to config)
111
+ * terminal (defaults to config)
@@ -1,20 +1,23 @@
1
1
  module Sermepa
2
-
2
+
3
3
  CURRENCIES = {
4
4
  :EUR => '978',
5
5
  :USD => '840',
6
6
  :GBP => '826',
7
7
  :JPY => '392'
8
8
  }
9
-
9
+
10
10
  TRANSACTION_TYPES = {
11
11
  # Payment Requests
12
12
  :traditional_payment => 'A',
13
13
  :preauthorization => '1',
14
14
  :deferred_authorization => 'O',
15
+ :authorization => '0',
16
+
15
17
  # Recurrent payments
16
18
  :recurrent_transaction => '5',
17
19
  :deferred_initial_recurrent_authorization => 'R',
20
+
18
21
  # Confirmation/Refund requests
19
22
  :confirmation => '2',
20
23
  :automatic_refund => '3',
@@ -24,5 +27,5 @@ module Sermepa
24
27
  :deferred_authorization_cancel => 'Q',
25
28
  :deferred_successive_transaction_authorization => 'S'
26
29
  }
27
-
30
+
28
31
  end
@@ -3,25 +3,24 @@ module Sermepa
3
3
  def sermepa_payment_form(amount, params = {}, &block)
4
4
  values = {
5
5
  DS_MERCHANT_AMOUNT: (amount.to_f * 100).to_i,
6
- DS_MERCHANT_CURRENCY: CURRENCIES[params[:currency] || config.currency],
6
+ DS_MERCHANT_CURRENCY: CURRENCIES[params[:currency] || Sermepa.config.currency],
7
7
  DS_MERCHANT_PRODUCTDESCRIPTION: params[:description],
8
8
  DS_MERCHANT_TITULAR: params[:titular],
9
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,
10
+ DS_MERCHANT_MERCHANTCODE: params[:merchant_code] || Sermepa.config.merchant_code,
11
+ DS_MERCHANT_TERMINAL: params[:terminal] || Sermepa.config.terminal,
12
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
13
+ DS_MERCHANT_MERCHANTURL: params[:merchant_url] || Sermepa.config.merchant_url,
14
+ DS_MERCHANT_URLOK: params[:url_ok] || Sermepa.config.url_ok,
15
+ DS_MERCHANT_URLKO: params[:url_ko] || Sermepa.config.url_ko,
16
+ DS_MERCHANT_CONSUMERLANGUAGE: params[:consumer_language] || Sermepa.config.consumer_language
17
17
  }
18
- values[:DS_MERCHANT_MERCHANTSIGNATURE] = signature(values)
19
-
18
+ values[:DS_MERCHANT_MERCHANTSIGNATURE] = Sermepa::signature(values)
19
+
20
20
  output = ActiveSupport::SafeBuffer.new
21
-
22
- form_tag config.post_url do
21
+ form_tag Sermepa.config.post_url do
23
22
  output = ActiveSupport::SafeBuffer.new
24
- values.each_pair do |k,v|
23
+ values.each_pair do |k,v|
25
24
  output << hidden_field_tag(k, v) if v
26
25
  end
27
26
  if block_given?
@@ -30,7 +29,7 @@ module Sermepa
30
29
  output << submit_tag(t 'send')
31
30
  end
32
31
  end
33
-
32
+
34
33
  end
35
34
  end
36
35
  end
@@ -4,7 +4,7 @@ require 'sermepa/errors'
4
4
  require 'sermepa/signature'
5
5
 
6
6
  module Sermepa
7
-
7
+
8
8
  def build_values(params, transaction_type)
9
9
  values = {
10
10
  DS_MERCHANT_MERCHANTCODE: params[:merchant_code] || Sermepa.config.merchant_code,
@@ -15,49 +15,49 @@ module Sermepa
15
15
  DS_MERCHANT_TRANSACTIONTYPE: TRANSACTION_TYPES[transaction_type]
16
16
  }
17
17
  values[:DS_MERCHANT_MERCHANTURL] = Sermepa.config.merchant_url if Sermepa.config.merchant_url
18
-
18
+
19
19
  values
20
20
  end
21
-
21
+
22
22
  def pay_request(params)
23
23
  values = build_values(params, :traditional_payment)
24
24
  values[:DS_MERCHANT_PAN] = params[:pan]
25
25
  values[:DS_MERCHANT_CVV2] = params[:cvv2]
26
26
  values[:DS_MERCHANT_EXPIRYDATE] = params[:expiration]
27
-
27
+
28
28
  values[:DS_MERCHANT_MERCHANTSIGNATURE] = signature(values)
29
29
  call(values)
30
30
  end
31
-
31
+
32
32
  def confirmation_request(params)
33
33
  values = build_values(params, :confirmation)
34
34
 
35
35
  values[:DS_MERCHANT_MERCHANTSIGNATURE] = signature(values)
36
36
  call(values)
37
37
  end
38
-
38
+
39
39
  def refund_request(params)
40
40
  values = build_values(params, :automatic_refund)
41
41
 
42
42
  values[:DS_MERCHANT_MERCHANTSIGNATURE] = signature(values)
43
43
  call(values)
44
44
  end
45
-
45
+
46
46
  def call(values = {})
47
47
  client = Savon.client(config.service_url)
48
-
48
+
49
49
  response = client.request :trata_peticion do
50
50
  soap.body do |xml|
51
51
  request_xml = values.to_xml(root: :DATOSENTRADA, dasherize: false, skip_instruct: true)
52
52
  xml.DATOSENTRADA(request_xml)
53
-
53
+
54
54
  end
55
55
  end
56
-
56
+
57
57
  result = Hash.from_xml response.to_hash[:trata_peticion_response][:trata_peticion_return]
58
58
  error_code = result['RETORNOXML']['CODIGO'].to_sym
59
59
  remote_error = error_code != :'0'
60
-
60
+
61
61
  if remote_error
62
62
  config._logger.warn("[Sermepa] Remote Error (#{error_code}): #{ERRORS[error_code]}")
63
63
  if config.raise_errors
@@ -66,17 +66,17 @@ module Sermepa
66
66
  return error_code
67
67
  end
68
68
  end
69
-
69
+
70
70
  response_code = result['RETORNOXML']['OPERACION']['Ds_Response']
71
-
72
- unless (0..99).include?(response_code.to_i) || response_code.to_i == 900
71
+
72
+ unless (0..99).include?(response_code.to_i) || response_code.to_i == 900
73
73
  if config.raise_errors
74
74
  raise SermepaPaymentError.new(response_code.to_sym)
75
75
  else
76
76
  return response_code.to_sym
77
77
  end
78
78
  end
79
-
79
+
80
80
  return false # No errors
81
81
  end
82
82
  end
@@ -1,3 +1,3 @@
1
1
  module Sermepa
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/sermepa.rb CHANGED
@@ -14,5 +14,5 @@ module Sermepa
14
14
  def config
15
15
  @config ||= Config.default
16
16
  end
17
-
17
+
18
18
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sermepa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Endika Gutiérrez
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
11
+ date: 2013-07-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: savon
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: sqlite3
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -111,27 +104,26 @@ files:
111
104
  - test/test_helper.rb
112
105
  homepage: https://github.com/endSly/sermepa-rails
113
106
  licenses: []
107
+ metadata: {}
114
108
  post_install_message:
115
109
  rdoc_options: []
116
110
  require_paths:
117
111
  - lib
118
112
  required_ruby_version: !ruby/object:Gem::Requirement
119
- none: false
120
113
  requirements:
121
114
  - - ! '>='
122
115
  - !ruby/object:Gem::Version
123
116
  version: '0'
124
117
  required_rubygems_version: !ruby/object:Gem::Requirement
125
- none: false
126
118
  requirements:
127
119
  - - ! '>='
128
120
  - !ruby/object:Gem::Version
129
121
  version: '0'
130
122
  requirements: []
131
123
  rubyforge_project:
132
- rubygems_version: 1.8.24
124
+ rubygems_version: 2.0.5
133
125
  signing_key:
134
- specification_version: 3
126
+ specification_version: 4
135
127
  summary: Sermepa SOAP gateway for rails.
136
128
  test_files:
137
129
  - test/dummy/app/assets/javascripts/application.js