vaulted_billing 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ module VaultedBilling
3
3
  module Response
4
4
  attr_accessor :raw_response
5
5
  attr_accessor :response_message
6
+ attr_accessor :error_code
6
7
  attr_writer :success
7
8
  def success?; @success; end
8
9
  end
@@ -56,6 +57,8 @@ module VaultedBilling
56
57
  o.extend(VaultedBilling::Gateway::Response)
57
58
  o.success = options.has_key?(:success) ? options[:success] : true
58
59
  o.raw_response = options[:raw_response] || ''
60
+ o.response_message = options[:response_message]
61
+ o.error_code = options[:error_code]
59
62
  yield(o) if block_given?
60
63
  end
61
64
  end
@@ -28,7 +28,9 @@ module VaultedBilling
28
28
  end
29
29
  end
30
30
  result = post_data(data)
31
- respond_with(customer, :success => result.success?, :raw_response => result.raw_response.try(:body)) { |c| c.vault_id = (result.body['createCustomerProfileResponse'] || {})['customerProfileId'] }
31
+ respond_with(customer, result, :success => result.success?) do |c|
32
+ c.vault_id = result.body['createCustomerProfileResponse']['customerProfileId'] if c.success?
33
+ end
32
34
  end
33
35
 
34
36
  def update_customer(customer)
@@ -39,7 +41,7 @@ module VaultedBilling
39
41
  xml.customerProfileId customer.vault_id
40
42
  }
41
43
  })
42
- respond_with(customer, :success => result.success?, :raw_response => result.raw_response.try(:body))
44
+ respond_with(customer, result, :success => result.success?)
43
45
  end
44
46
 
45
47
  def remove_customer(customer)
@@ -47,7 +49,8 @@ module VaultedBilling
47
49
  result = post_data(build_request('deleteCustomerProfileRequest') { |xml|
48
50
  xml.customerProfileId customer.vault_id
49
51
  })
50
- respond_with(customer, :success => result.success?)
52
+
53
+ respond_with(customer, result, :success => result.success?)
51
54
  end
52
55
 
53
56
  def add_customer_credit_card(customer, credit_card)
@@ -60,7 +63,9 @@ module VaultedBilling
60
63
  credit_card_info!(xml, customer, credit_card)
61
64
  end
62
65
  })
63
- respond_with(credit_card, :success => result.success?, :raw_response => result.raw_response.try(:body)) { |c| c.vault_id = (result.body['createCustomerPaymentProfileResponse'] || {})['customerPaymentProfileId'] }
66
+ respond_with(credit_card, result, :success => result.success?) do |c|
67
+ c.vault_id = result.body['createCustomerPaymentProfileResponse']['customerPaymentProfileId'] if c.success?
68
+ end
64
69
  end
65
70
 
66
71
  def update_customer_credit_card(customer, credit_card)
@@ -74,7 +79,7 @@ module VaultedBilling
74
79
  xml.customerPaymentProfileId credit_card.vault_id
75
80
  end
76
81
  })
77
- respond_with(credit_card, :success => result.success?)
82
+ respond_with(credit_card, result, :success => result.success?)
78
83
  end
79
84
 
80
85
  def remove_customer_credit_card(customer, credit_card)
@@ -84,7 +89,7 @@ module VaultedBilling
84
89
  xml.customerProfileId customer.vault_id
85
90
  xml.customerPaymentProfileId credit_card.vault_id
86
91
  })
87
- respond_with(credit_card, :success => result.success?, :raw_response => result.raw_response.try(:body))
92
+ respond_with(credit_card, result, :success => result.success?)
88
93
  end
89
94
 
90
95
  def authorize(customer, credit_card, amount)
@@ -100,7 +105,7 @@ module VaultedBilling
100
105
  end
101
106
  xml.extraOptions 'x_duplicate_window=0'
102
107
  })
103
- respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response.try(:body))
108
+ respond_with(new_transaction_from_response(result.body), result, :success => result.success?)
104
109
  end
105
110
 
106
111
  def capture(transaction_id, amount)
@@ -113,7 +118,7 @@ module VaultedBilling
113
118
  end
114
119
  xml.extraOptions 'x_duplicate_window=0'
115
120
  })
116
- respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response.try(:body))
121
+ respond_with(new_transaction_from_response(result.body), result, :success => result.success?)
117
122
  end
118
123
 
119
124
  def refund(transaction_id, amount)
@@ -126,7 +131,7 @@ module VaultedBilling
126
131
  end
127
132
  xml.extraOptions 'x_duplicate_window=0'
128
133
  })
129
- respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response.try(:body))
134
+ respond_with(new_transaction_from_response(result.body), result, :success => result.success?)
130
135
  end
131
136
 
132
137
  def void(transaction_id)
@@ -138,7 +143,7 @@ module VaultedBilling
138
143
  end
139
144
  xml.extraOptions 'x_duplicate_window=0'
140
145
  })
141
- respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response.try(:body))
146
+ respond_with(new_transaction_from_response(result.body), result, :success => result.success?)
142
147
  end
143
148
 
144
149
 
@@ -155,8 +160,10 @@ module VaultedBilling
155
160
  'directResponse' => ',,,There was a problem communicating with the card processor.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,',
156
161
  'messages' => {
157
162
  'resultCode' => 'Error',
158
- 'text' => 'A communication problem has occurred.',
159
- 'code' => 'E00000'
163
+ 'message' => {
164
+ 'text' => 'A communication problem has occurred.',
165
+ 'code' => 'E00000'
166
+ }
160
167
  }
161
168
  }
162
169
  }
@@ -232,6 +239,17 @@ module VaultedBilling
232
239
  }
233
240
  end
234
241
 
242
+ def respond_with(object, result, options = {}, &block)
243
+ super(object, options, &block).tap do |o|
244
+ o.raw_response = result.raw_response.try(:body)
245
+ o.response_message = result.body[result.body.keys.first]['messages']['message']['text']
246
+
247
+ unless result.success?
248
+ o.error_code = result.body[result.body.keys.first]['messages']['message']['code']
249
+ end
250
+ end
251
+ end
252
+
235
253
  end
236
254
 
237
255
  end
@@ -54,14 +54,14 @@ module VaultedBilling
54
54
 
55
55
  def add_customer_credit_card(customer, credit_card)
56
56
  response = post_data(storage_data('add_customer', customer.to_vaulted_billing, credit_card.to_vaulted_billing))
57
- respond_with(credit_card, :success => response.success?, :raw_response => response.raw_response.try(:body)) do |c|
57
+ respond_with(credit_card, response, :success => response.success?) do |c|
58
58
  c.vault_id = response.body['customer_vault_id']
59
59
  end
60
60
  end
61
61
 
62
62
  def update_customer_credit_card(customer, credit_card)
63
63
  response = post_data(storage_data('update_customer', customer.to_vaulted_billing, credit_card.to_vaulted_billing))
64
- respond_with(credit_card, :success => response.success?, :raw_response => response.raw_response.try(:body))
64
+ respond_with(credit_card, response, :success => response.success?)
65
65
  end
66
66
 
67
67
  def remove_customer_credit_card(customer, credit_card)
@@ -69,7 +69,7 @@ module VaultedBilling
69
69
  :customer_vault => 'delete_customer',
70
70
  :customer_vault_id => credit_card.to_vaulted_billing.vault_id
71
71
  }).to_querystring)
72
- respond_with(credit_card, :success => response.success?, :raw_response => response.raw_response.try(:body))
72
+ respond_with(credit_card, response, :success => response.success?)
73
73
  end
74
74
 
75
75
  def authorize(customer, credit_card, amount)
@@ -78,7 +78,8 @@ module VaultedBilling
78
78
  :amount => amount
79
79
  }))
80
80
  respond_with(new_transaction_from_response(response.body),
81
- :success => response.success?, :raw_response => response.raw_response.try(:body))
81
+ response,
82
+ :success => response.success?)
82
83
  end
83
84
 
84
85
  def capture(transaction_id, amount)
@@ -87,7 +88,8 @@ module VaultedBilling
87
88
  :amount => amount
88
89
  }))
89
90
  respond_with(new_transaction_from_response(response.body),
90
- :success => response.success?, :raw_response => response.raw_response.try(:body))
91
+ response,
92
+ :success => response.success?)
91
93
  end
92
94
 
93
95
  def refund(transaction_id, amount)
@@ -96,7 +98,8 @@ module VaultedBilling
96
98
  :amount => amount
97
99
  }))
98
100
  respond_with(new_transaction_from_response(response.body),
99
- :success => response.success?, :raw_response => response.raw_response.try(:body))
101
+ response,
102
+ :success => response.success?)
100
103
  end
101
104
 
102
105
  def void(transaction_id)
@@ -104,13 +107,23 @@ module VaultedBilling
104
107
  :transactionid => transaction_id
105
108
  }))
106
109
  respond_with(new_transaction_from_response(response.body),
107
- :success => response.success?, :raw_response => response.raw_response.try(:body))
110
+ response,
111
+ :success => response.success?)
108
112
  end
109
113
 
110
114
 
111
115
  protected
112
116
 
113
117
 
118
+ def after_post_on_exception(response, exception)
119
+ response.body = {
120
+ 'response' => '3',
121
+ 'responsetext' => 'A communication problem has occurred.',
122
+ 'response_code' => '420'
123
+ }
124
+ response.success = false
125
+ end
126
+
114
127
  def after_post(response)
115
128
  response.body = Hash.from_querystring(response.body)
116
129
  response.success = response.body['response'] == '1'
@@ -163,6 +176,17 @@ module VaultedBilling
163
176
  :code => response['response_code']
164
177
  })
165
178
  end
179
+
180
+ def respond_with(object, response = nil, options = {}, &block)
181
+ super(object, options, &block).tap do |o|
182
+ o.raw_response = response.raw_response.try(:body) if response
183
+ o.response_message = (response.try(:body) || {})['responsetext']
184
+
185
+ if response && !response.success?
186
+ o.error_code = (response.try(:body) || {})['response_code']
187
+ end
188
+ end
189
+ end
166
190
  end
167
191
  end
168
192
  end
@@ -6,8 +6,11 @@ module VaultedBilling
6
6
 
7
7
  HTTP_ERRORS = [
8
8
  Timeout::Error,
9
+ Errno::ETIMEDOUT,
9
10
  Errno::EINVAL,
10
11
  Errno::ECONNRESET,
12
+ Errno::ECONNREFUSED,
13
+ Errno::EHOSTUNREACH,
11
14
  EOFError,
12
15
  Net::HTTPBadResponse,
13
16
  Net::HTTPHeaderSyntaxError,
@@ -1,3 +1,3 @@
1
1
  module VaultedBilling
2
- Version = '0.0.7'
2
+ Version = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vaulted_billing
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 15
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 7
9
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
10
11
  platform: ruby
11
12
  authors:
12
13
  - Nathaniel Bibler
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-20 00:00:00 -04:00
18
+ date: 2010-10-25 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activesupport
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 5
27
30
  segments:
28
31
  - 2
29
32
  - 3
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: builder
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
44
+ hash: 15
40
45
  segments:
41
46
  - 2
42
47
  - 1
@@ -48,9 +53,11 @@ dependencies:
48
53
  name: rspec
49
54
  prerelease: false
50
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
51
57
  requirements:
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
60
+ hash: 62196421
54
61
  segments:
55
62
  - 2
56
63
  - 0
@@ -64,9 +71,11 @@ dependencies:
64
71
  name: vcr
65
72
  prerelease: false
66
73
  requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
67
75
  requirements:
68
76
  - - ">="
69
77
  - !ruby/object:Gem::Version
78
+ hash: 17
70
79
  segments:
71
80
  - 1
72
81
  - 0
@@ -78,9 +87,11 @@ dependencies:
78
87
  name: webmock
79
88
  prerelease: false
80
89
  requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
81
91
  requirements:
82
92
  - - ">="
83
93
  - !ruby/object:Gem::Version
94
+ hash: 19
84
95
  segments:
85
96
  - 1
86
97
  - 3
@@ -92,9 +103,11 @@ dependencies:
92
103
  name: factory_girl
93
104
  prerelease: false
94
105
  requirement: &id006 !ruby/object:Gem::Requirement
106
+ none: false
95
107
  requirements:
96
108
  - - ">="
97
109
  - !ruby/object:Gem::Version
110
+ hash: 31
98
111
  segments:
99
112
  - 1
100
113
  - 3
@@ -106,9 +119,11 @@ dependencies:
106
119
  name: faker
107
120
  prerelease: false
108
121
  requirement: &id007 !ruby/object:Gem::Requirement
122
+ none: false
109
123
  requirements:
110
124
  - - ">="
111
125
  - !ruby/object:Gem::Version
126
+ hash: 17
112
127
  segments:
113
128
  - 0
114
129
  - 3
@@ -151,16 +166,20 @@ rdoc_options: []
151
166
  require_paths:
152
167
  - lib
153
168
  required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
154
170
  requirements:
155
171
  - - ">="
156
172
  - !ruby/object:Gem::Version
173
+ hash: 3
157
174
  segments:
158
175
  - 0
159
176
  version: "0"
160
177
  required_rubygems_version: !ruby/object:Gem::Requirement
178
+ none: false
161
179
  requirements:
162
180
  - - ">="
163
181
  - !ruby/object:Gem::Version
182
+ hash: 23
164
183
  segments:
165
184
  - 1
166
185
  - 3
@@ -169,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
188
  requirements: []
170
189
 
171
190
  rubyforge_project:
172
- rubygems_version: 1.3.6
191
+ rubygems_version: 1.3.7
173
192
  signing_key:
174
193
  specification_version: 3
175
194
  summary: A library for working with credit card storage gateways