rbraspag 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbraspag (0.0.5)
4
+ rbraspag (0.0.6)
5
5
  cs-httpi (>= 0.9.5.2)
6
6
  json
7
7
  nokogiri
@@ -1,6 +1,35 @@
1
1
  module Braspag
2
2
  class CreditCard
3
3
 
4
+ PAYMENT_METHODS = {
5
+ # BRASIL
6
+ :amex_2p => 18, # American Express 2 Party
7
+ :cielo_noauth_visa => 71, # Cielo webservice captura automática sem autenticação - Visa
8
+ :cielo_preauth_visa => 73, # Cielo webservice preauth sem autenticação - Visa
9
+ :cielo_noauth_mastercard => 120, # Cielo webservice captura automática sem autenticação - Mastercard
10
+ :cielo_preauth_mastercard => 122, # Cielo webservice preauth sem autenticação - Mastercard
11
+ :redecard => 20, # Redecard Mastercard/Diners/Visa
12
+ :redecard_preauth => 42, # Redecard preauth Mastercard/Diners/Visa
13
+ :cielo_sitef => 57, # Cielo SITEF
14
+ :hipercard_sitef => 62, # Hipercard SITEF
15
+ :hipercard_moip => 90, # Hipercard MOIP
16
+ :oi_paggo => 55, # OiPaggo
17
+ :amex_sitef => 58, # Amex SITEF
18
+ :aura_dtef => 37, # Aura DTEF
19
+ :redecard_sitef => 44, # Redecard SITEF - Mastercard/Diners
20
+ # MÉXICO
21
+ :mex_amex_2p => 45, # American Express 2 Party
22
+ :mex_banorte_visa => 50, # Banorte Visa
23
+ :mex_banorte_diners => 52, # Banorte Diners
24
+ :mex_banorte_mastercard => 53, # Banorte Mastercard
25
+ # COLÔMBIA
26
+ :col_visa => 63, # Visa
27
+ :col_amex => 65, # Amex
28
+ :col_diners => 66, # Diners
29
+ # INTERNACIONAL
30
+ :paypal_express => 35 # PayPal Express Checkout
31
+ }
32
+
4
33
  MAPPING = {
5
34
  :merchant_id => "merchantId",
6
35
  :order_id => "orderId",
@@ -21,7 +50,6 @@ module Braspag
21
50
  @merchant_id = connection.merchant_id
22
51
  end
23
52
 
24
-
25
53
  def uri_authorize
26
54
  "#{@connection.base_url}/webservices/pagador/Pagador.asmx/Authorize"
27
55
  end
@@ -30,24 +58,22 @@ module Braspag
30
58
  "#{@connection.base_url}/webservices/pagador/Pagador.asmx/Capture"
31
59
  end
32
60
 
33
-
34
-
35
61
  def authorize params
62
+ [:order_id, :customer_name, :amount, :payment_method, :holder,
63
+ :card_number, :expiration, :security_code, :number_payments, :type].each do |param|
64
+ raise IncompleteParams unless params.include?(param)
65
+ end
36
66
 
37
- [:order_id, :customer_name, :amount, :payment_method, :holder,
38
- :card_number, :expiration, :security_code, :number_payments, :type].each do |param|
39
- raise IncompleteParams unless params.include?(param)
40
- end
41
-
42
- raise InvalidOrderId unless (1..20).include?(params[:order_id].to_s.size)
43
- raise InvalidCustomerName unless (1..100).include?(params[:customer_name].to_s.size)
44
- raise InvalidAmount unless (1..10).include?(params[:amount].to_s.size)
45
- raise InvalidHolder unless (1..100).include?(params[:holder].to_s.size)
46
- raise InvalidExpirationDate unless (1..7).include?(params[:expiration].to_s.size)
47
- raise InvalidSecurityCode unless (1..4).include?(params[:security_code].to_s.size)
48
- raise InvalidNumberPayments unless (1..2).include?(params[:number_payments].to_s.size)
49
- raise InvalidType unless (1..2).include?(params[:type].to_s.size)
67
+ raise InvalidOrderId unless (1..20).include?(params[:order_id].to_s.size)
68
+ raise InvalidCustomerName unless (1..100).include?(params[:customer_name].to_s.size)
69
+ raise InvalidAmount unless (1..10).include?(params[:amount].to_s.size)
70
+ raise InvalidHolder unless (1..100).include?(params[:holder].to_s.size)
71
+ raise InvalidExpirationDate unless (1..7).include?(params[:expiration].to_s.size)
72
+ raise InvalidSecurityCode unless (1..4).include?(params[:security_code].to_s.size)
73
+ raise InvalidNumberPayments unless (1..2).include?(params[:number_payments].to_s.size)
74
+ raise InvalidType unless (1..2).include?(params[:type].to_s.size)
50
75
 
76
+ params[:payment_method] = PAYMENT_METHODS[params[:payment_method]] if params[:payment_method].is_a?(Symbol)
51
77
 
52
78
  data = MAPPING.inject({}) do |memo, k|
53
79
  if k[0] == :amount
@@ -55,34 +81,26 @@ module Braspag
55
81
  else
56
82
  memo[k[1]] = params[k[0]] || "";
57
83
  end
58
-
59
84
  memo
60
85
  end
61
-
86
+
62
87
  request = ::HTTPI::Request.new uri_authorize
63
88
  request.body = data
64
89
  response = ::HTTPI.post request
65
90
  response = convert_to_map response.body
66
-
67
91
  end
68
92
 
69
- def capture order_id
93
+ def capture(order_id)
70
94
  raise InvalidOrderId unless (1..20).include?(order_id.to_s.size)
71
-
95
+
72
96
  data = {MAPPING[:order_id] => order_id, "merchantId" => @merchant_id }
73
97
  request = ::HTTPI::Request.new uri_capture
74
98
 
75
99
  request.body = data
76
- response = ::HTTPI.post request
77
-
78
- # require "ruby-debug"
79
- # debugger
80
-
81
- response = convert_to_map response.body
82
-
100
+ response = ::HTTPI.post(request)
101
+ convert_to_map(response.body)
83
102
  end
84
103
 
85
-
86
104
  def convert_to_map(document)
87
105
  document = Nokogiri::XML(document)
88
106
 
@@ -114,6 +132,6 @@ module Braspag
114
132
 
115
133
  map
116
134
  end
117
-
118
135
  end
119
136
  end
137
+
@@ -1,3 +1,3 @@
1
1
  module Braspag
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -23,7 +23,7 @@ describe Braspag::CreditCard do
23
23
  Braspag::CreditCard.new(connection).authorize({
24
24
  :customer_name => "W" * 21,
25
25
  :amount => "100.00",
26
- :payment_method => 20,
26
+ :payment_method => :redecard,
27
27
  :holder => "Joao Maria Souza",
28
28
  :card_number => "9" * 10,
29
29
  :expiration => "10/12",
@@ -39,7 +39,7 @@ describe Braspag::CreditCard do
39
39
  Braspag::CreditCard.new(connection).authorize({
40
40
  :order_id => "1" * 5,
41
41
  :amount => "100.00",
42
- :payment_method => 20,
42
+ :payment_method => :redecard,
43
43
  :holder => "Joao Maria Souza",
44
44
  :card_number => "9" * 10,
45
45
  :expiration => "10/12",
@@ -55,7 +55,7 @@ describe Braspag::CreditCard do
55
55
  Braspag::CreditCard.new(connection).authorize({
56
56
  :order_id => "1" * 5,
57
57
  :customer_name => "",
58
- :payment_method => 20,
58
+ :payment_method => :redecard,
59
59
  :holder => "Joao Maria Souza",
60
60
  :card_number => "9" * 10,
61
61
  :expiration => "10/12",
@@ -87,7 +87,7 @@ describe Braspag::CreditCard do
87
87
  Braspag::CreditCard.new(connection).authorize({
88
88
  :order_id => "1" * 5,
89
89
  :customer_name => "",
90
- :payment_method => 20,
90
+ :payment_method => :redecard,
91
91
  :amount => "100.00",
92
92
  :card_number => "9" * 10,
93
93
  :expiration => "10/12",
@@ -103,7 +103,7 @@ describe Braspag::CreditCard do
103
103
  Braspag::CreditCard.new(connection).authorize({
104
104
  :order_id => "1" * 5,
105
105
  :customer_name => "",
106
- :payment_method => 20,
106
+ :payment_method => :redecard,
107
107
  :amount => "100.00",
108
108
  :holder => "Joao Maria Souza",
109
109
  :expiration => "10/12",
@@ -119,7 +119,7 @@ describe Braspag::CreditCard do
119
119
  Braspag::CreditCard.new(connection).authorize({
120
120
  :order_id => "1" * 5,
121
121
  :customer_name => "",
122
- :payment_method => 20,
122
+ :payment_method => :redecard,
123
123
  :amount => "100.00",
124
124
  :holder => "Joao Maria Souza",
125
125
  :card_number => "9" * 10,
@@ -135,7 +135,7 @@ describe Braspag::CreditCard do
135
135
  Braspag::CreditCard.new(connection).authorize({
136
136
  :order_id => "1" * 5,
137
137
  :customer_name => "AAAAAAAA",
138
- :payment_method => 20,
138
+ :payment_method => :redecard,
139
139
  :amount => "100.00",
140
140
  :holder => "Joao Maria Souza",
141
141
  :expiration => "10/12",
@@ -151,7 +151,7 @@ describe Braspag::CreditCard do
151
151
  Braspag::CreditCard.new(connection).authorize({
152
152
  :order_id => "1" * 5,
153
153
  :customer_name => "AAAAAAAA",
154
- :payment_method => 20,
154
+ :payment_method => :redecard,
155
155
  :amount => "100.00",
156
156
  :holder => "Joao Maria Souza",
157
157
  :expiration => "10/12",
@@ -166,7 +166,7 @@ describe Braspag::CreditCard do
166
166
  Braspag::CreditCard.new(connection).authorize({
167
167
  :order_id => "1" * 5,
168
168
  :customer_name => "AAAAAAAA",
169
- :payment_method => 20,
169
+ :payment_method => :redecard,
170
170
  :amount => "100.00",
171
171
  :holder => "Joao Maria Souza",
172
172
  :expiration => "10/12",
@@ -180,7 +180,7 @@ describe Braspag::CreditCard do
180
180
  {
181
181
  :order_id => "1" * 5,
182
182
  :customer_name => "AAAAAAAA",
183
- :payment_method => 20,
183
+ :payment_method => :amex_2p,
184
184
  :amount => "100.00",
185
185
  :holder => "Joao Maria Souza",
186
186
  :expiration => "10/12",
@@ -259,7 +259,7 @@ describe Braspag::CreditCard do
259
259
  {
260
260
  :order_id => "123456",
261
261
  :customer_name => "Teste",
262
- :payment_method => 18,
262
+ :payment_method => :amex_2p,
263
263
  :amount => 1.3,
264
264
  :holder => "teste",
265
265
  :expiration => "05/13",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbraspag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,12 +14,12 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2011-07-11 00:00:00.000000000 -03:00
17
+ date: 2011-07-12 00:00:00.000000000 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cs-httpi
22
- requirement: &70094060 !ruby/object:Gem::Requirement
22
+ requirement: &81637610 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ! '>='
@@ -27,10 +27,10 @@ dependencies:
27
27
  version: 0.9.5.2
28
28
  type: :runtime
29
29
  prerelease: false
30
- version_requirements: *70094060
30
+ version_requirements: *81637610
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: json
33
- requirement: &70093160 !ruby/object:Gem::Requirement
33
+ requirement: &81637340 !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
36
36
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '0'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *70093160
41
+ version_requirements: *81637340
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: nokogiri
44
- requirement: &70092550 !ruby/object:Gem::Requirement
44
+ requirement: &81637080 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ! '>='
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: '0'
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *70092550
52
+ version_requirements: *81637080
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rspec
55
- requirement: &70091530 !ruby/object:Gem::Requirement
55
+ requirement: &81636860 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '0'
61
61
  type: :development
62
62
  prerelease: false
63
- version_requirements: *70091530
63
+ version_requirements: *81636860
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: fakeweb
66
- requirement: &70049170 !ruby/object:Gem::Requirement
66
+ requirement: &81636580 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ! '>='
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: '0'
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *70049170
74
+ version_requirements: *81636580
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: shoulda-matchers
77
- requirement: &70047820 !ruby/object:Gem::Requirement
77
+ requirement: &81636350 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ! '>='
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: '0'
83
83
  type: :development
84
84
  prerelease: false
85
- version_requirements: *70047820
85
+ version_requirements: *81636350
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: guard-rspec
88
- requirement: &70046940 !ruby/object:Gem::Requirement
88
+ requirement: &81636120 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ! '>='
@@ -93,10 +93,10 @@ dependencies:
93
93
  version: '0'
94
94
  type: :development
95
95
  prerelease: false
96
- version_requirements: *70046940
96
+ version_requirements: *81636120
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-bundler
99
- requirement: &70045930 !ruby/object:Gem::Requirement
99
+ requirement: &81635890 !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
102
102
  - - ! '>='
@@ -104,10 +104,10 @@ dependencies:
104
104
  version: '0'
105
105
  type: :development
106
106
  prerelease: false
107
- version_requirements: *70045930
107
+ version_requirements: *81635890
108
108
  - !ruby/object:Gem::Dependency
109
109
  name: ruby-debug19
110
- requirement: &70045000 !ruby/object:Gem::Requirement
110
+ requirement: &81635650 !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
113
113
  - - ! '>='
@@ -115,7 +115,7 @@ dependencies:
115
115
  version: '0'
116
116
  type: :development
117
117
  prerelease: false
118
- version_requirements: *70045000
118
+ version_requirements: *81635650
119
119
  description: rbraspag gem to use Braspag gateway
120
120
  email:
121
121
  - tinorj@gmail.com