vizjerai-google-checkout 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ .rspec
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vizjerai-google-checkout.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,37 +1,2 @@
1
- require 'rake'
2
- require 'rake/rdoctask'
3
- require 'spec/rake/spectask'
4
-
5
- desc 'Run the specs'
6
- Spec::Rake::SpecTask.new(:spec) do |t|
7
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
8
- t.spec_files = FileList['spec/**/*_spec.rb']
9
- end
10
-
11
- Rake::RDocTask.new do |t|
12
- t.rdoc_dir = 'doc'
13
- t.rdoc_files.include('README')
14
- t.rdoc_files.include('lib/**/*.rb')
15
- t.options << '--inline-source'
16
- t.options << '--all'
17
- t.options << '--line-numbers'
18
- end
19
-
20
- begin
21
- require 'jeweler'
22
- Jeweler::Tasks.new do |s|
23
- s.name = "vizjerai-google-checkout"
24
- s.summary = "An experimental library for sending payment requests to Google Checkout."
25
- s.email = "assarata@gmail.com"
26
- s.homepage = "http://github.com/vizjerai/google-checkout/"
27
- s.description = "An experimental library for sending payment requests to Google Checkout."
28
- s.authors = ["Peter Elmore", "Geoffrey Grosenbach", "Matt Lins", "Steel Fu", "Andrew Assarattanakul"]
29
- s.files = FileList["[A-Z]*", "{lib,spec,support,examples}/**/*"]
30
- s.add_dependency(%q<activesupport>, [">= 2.3.0"])
31
- s.add_dependency(%q<money>, [">= 2.3.0"])
32
- s.add_dependency(%q<nokogiri>, [">=0"])
33
- s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
34
- end
35
- rescue LoadError
36
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
37
- end
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -7,7 +7,8 @@
7
7
  $: << File.dirname(__FILE__)
8
8
  $: << File.dirname(__FILE__) + "/vendor/ruby-hmac/lib"
9
9
 
10
- require 'rubygems'
10
+ require 'google-checkout/version'
11
+
11
12
  require 'active_support'
12
13
 
13
14
  require 'openssl'
@@ -17,7 +18,7 @@ require 'nokogiri'
17
18
  require 'money'
18
19
  require 'net/https'
19
20
 
20
- require 'duck_punches/hpricot'
21
+ require 'duck_punches/nokogiri'
21
22
  require 'duck_punches/inflector'
22
23
  require 'google-checkout/notification'
23
24
  require 'google-checkout/merchant_calculation'
@@ -35,8 +36,6 @@ require 'google-checkout/geography'
35
36
 
36
37
  module GoogleCheckout
37
38
 
38
- #VERSION = '0.2.0'
39
-
40
39
  @@live_system = true
41
40
 
42
41
  ##
@@ -61,6 +60,4 @@ module GoogleCheckout
61
60
  @@live_system
62
61
  end
63
62
 
64
- class APIError < Exception; end
65
-
66
63
  end
@@ -268,7 +268,7 @@ module GoogleCheckout
268
268
  }
269
269
  }
270
270
  }
271
- unless @merchant_private_data.blank?
271
+ unless @merchant_private_data.nil? || @merchant_private_data.empty?
272
272
  xml.tag!("merchant-private-data") {
273
273
  xml << @merchant_private_data
274
274
  }
@@ -290,7 +290,8 @@ module GoogleCheckout
290
290
  xml.tag!('parameterized-urls') {
291
291
  @parameterized_urls.each do |param_url|
292
292
  xml.tag!('parameterized-url', :url => param_url[:url]) {
293
- next if param_url[:parameters].blank?
293
+ next if param_url[:parameters].nil?
294
+ next if param_url[:parameters].empty?
294
295
  xml.tag!('parameters') {
295
296
  param_url[:parameters].each do |parameter|
296
297
  xml.tag!('url-parameter', :name => parameter[:name], :type => parameter[:type]) {}
@@ -298,7 +299,7 @@ module GoogleCheckout
298
299
  }
299
300
  }
300
301
  end
301
- } unless @parameterized_urls.blank?
302
+ } unless @parameterized_urls.nil? || @parameterized_urls.empty?
302
303
 
303
304
  xml.tag!('shipping-methods') {
304
305
  @shipping_methods.each do |shipping_method|
@@ -59,15 +59,11 @@ module GoogleCheckout
59
59
  # is from the server.
60
60
  case response
61
61
  when Net::HTTPSuccess, Net::HTTPClientError
62
- notification = Notification.parse(response.body)
63
- if notification.error? && !notification.message.eql?('You cannot charge an order that is already completely charged')
64
- raise APIError, "#{notification.message} [in #{GoogleCheckout.production? ? 'production' : 'sandbox' }]"
65
- end
66
- return notification
62
+ Notification.parse(response.body)
67
63
  when Net::HTTPRedirection, Net::HTTPServerError, Net::HTTPInformation
68
- raise "Unexpected response code (#{response.class}): #{response.code} - #{response.message}"
64
+ Error.new(nil, :message => "Unexpected response code (#{response.class}): #{response.code} - #{response.message}")
69
65
  else
70
- raise "Unknown response code: #{response.code} - #{response.message}"
66
+ Error.new(nil, :message => "Unknown response code: #{response.code} - #{response.message}")
71
67
  end
72
68
  end
73
69
 
@@ -222,7 +218,7 @@ module GoogleCheckout
222
218
  }) do
223
219
  xml.tag!("amount", @amount, {:currency => @currency})
224
220
  xml.tag!("reason", @reason)
225
- xml.tag!("comment", @comment) unless @comment.blank?
221
+ xml.tag!("comment", @comment) unless @comment.nil? || @comment.empty?
226
222
  end
227
223
  @xml
228
224
  end
@@ -1,7 +1,9 @@
1
1
  module GoogleCheckout
2
2
  class MerchantCalculation
3
3
 
4
- attr_accessor :doc
4
+ def doc
5
+ @doc ||= Nokogiri::XML::Builder.new
6
+ end
5
7
 
6
8
  def self.parse(raw_xml)
7
9
  doc = Nokogiri::XML(raw_xml)
@@ -13,12 +15,12 @@ module GoogleCheckout
13
15
  end
14
16
 
15
17
  def address_id
16
- (@doc/"anonymous-address").attr('id').value
18
+ (doc/"anonymous-address").attr('id').value
17
19
  end
18
20
 
19
21
  def method_missing(method_name, *args)
20
22
  element_name = method_name.to_s.gsub(/_/, '-')
21
- if element = (@doc.at element_name)
23
+ if element = (doc.at element_name)
22
24
  if element.respond_to?(:inner_html)
23
25
  return element.inner_html
24
26
  end
@@ -20,7 +20,9 @@ module GoogleCheckout
20
20
  class Notification
21
21
 
22
22
  # The Nokogiri XML document received from Google.
23
- attr_accessor :doc
23
+ def doc
24
+ @doc ||= Nokogiri::XML::Builder.new
25
+ end
24
26
 
25
27
  ##
26
28
  # The entry point for notifications.
@@ -78,10 +80,10 @@ module GoogleCheckout
78
80
  # Please see the Order States section for more information about these states.
79
81
 
80
82
  def state
81
- if (@doc.at 'financial-order-state')
82
- return (@doc/'financial-order-state').inner_html
83
- elsif (@doc.at 'new-financial-order-state')
84
- return (@doc/'new-financial-order-state').inner_html
83
+ if (doc.at 'financial-order-state')
84
+ return (doc/'financial-order-state').inner_html
85
+ elsif (doc.at 'new-financial-order-state')
86
+ return (doc/'new-financial-order-state').inner_html
85
87
  end
86
88
  end
87
89
 
@@ -129,7 +131,7 @@ module GoogleCheckout
129
131
 
130
132
  def method_missing(method_name, *args)
131
133
  element_name = method_name.to_s.gsub(/_/, '-')
132
- if element = (@doc.at element_name)
134
+ if element = (doc.at element_name)
133
135
  if element.respond_to?(:inner_html)
134
136
  return element.inner_html
135
137
  end
@@ -144,11 +146,11 @@ module GoogleCheckout
144
146
  class ChargeAmountNotification < Notification
145
147
 
146
148
  def latest_charge_amount
147
- (@doc/"latest-charge-amount").to_money
149
+ (doc/"latest-charge-amount").to_money
148
150
  end
149
151
 
150
152
  def total_charge_amount
151
- (@doc/"total-charge-amount").to_money
153
+ (doc/"total-charge-amount").to_money
152
154
  end
153
155
 
154
156
  end
@@ -156,11 +158,11 @@ module GoogleCheckout
156
158
  class ChargebackAmountNotification < Notification
157
159
 
158
160
  def latest_chargeback_amount
159
- (@doc/"latest-chargeback-amount").to_money
161
+ (doc/"latest-chargeback-amount").to_money
160
162
  end
161
163
 
162
164
  def total_chargeback_amount
163
- (@doc/"total-chargeback-amount").to_money
165
+ (doc/"total-chargeback-amount").to_money
164
166
  end
165
167
 
166
168
  end
@@ -171,161 +173,161 @@ module GoogleCheckout
171
173
  # Returns a Money object representing the total price of the order.
172
174
 
173
175
  def order_total
174
- (@doc/"order-total").to_money
176
+ (doc/"order-total").to_money
175
177
  end
176
178
 
177
179
  ##
178
180
  # Returns a Money object representing the total tax added.
179
181
 
180
182
  def total_tax
181
- (@doc/"total-tax").to_money
183
+ (doc/"total-tax").to_money
182
184
  end
183
185
 
184
186
  ##
185
187
  # Returns true if the buyer wants to received marketing emails.
186
188
 
187
189
  def email_allowed
188
- (@doc/"buyer-marketing-preferences"/"email-allowed").to_boolean
190
+ (doc/"buyer-marketing-preferences"/"email-allowed").to_boolean
189
191
  end
190
192
 
191
193
  ##
192
194
  # Returns billing name.
193
195
 
194
196
  def billing_name
195
- (@doc/"buyer-billing-address"/"contact-name").inner_html
197
+ (doc/"buyer-billing-address"/"contact-name").inner_html
196
198
  end
197
199
 
198
200
  ##
199
201
  # Returns billing email
200
202
 
201
203
  def billing_email
202
- (@doc/"buyer-billing-address"/"email").inner_html
204
+ (doc/"buyer-billing-address"/"email").inner_html
203
205
  end
204
206
 
205
207
  ##
206
208
  # Returns billing address1
207
209
 
208
210
  def billing_address1
209
- (@doc/"buyer-billing-address"/"address1").inner_html
211
+ (doc/"buyer-billing-address"/"address1").inner_html
210
212
  end
211
213
 
212
214
  ##
213
215
  # Returns billing city
214
216
 
215
217
  def billing_city
216
- (@doc/"buyer-billing-address"/"city").inner_html
218
+ (doc/"buyer-billing-address"/"city").inner_html
217
219
  end
218
220
 
219
221
  ##
220
222
  # Returns billing region
221
223
 
222
224
  def billing_region
223
- (@doc/"buyer-billing-address"/"region").inner_html
225
+ (doc/"buyer-billing-address"/"region").inner_html
224
226
  end
225
227
 
226
228
  ##
227
229
  # Returns billing postal code
228
230
 
229
231
  def billing_postal_code
230
- (@doc/"buyer-billing-address"/"postal-code").inner_html
232
+ (doc/"buyer-billing-address"/"postal-code").inner_html
231
233
  end
232
234
 
233
235
  ##
234
236
  # Returns billing country code
235
237
 
236
238
  def billing_country_code
237
- (@doc/"buyer-billing-address"/"country-code").inner_html
239
+ (doc/"buyer-billing-address"/"country-code").inner_html
238
240
  end
239
241
 
240
242
  ##
241
243
  # Returns billing phone
242
244
 
243
245
  def billing_phone
244
- (@doc/"buyer-billing-address"/"phone").inner_html
246
+ (doc/"buyer-billing-address"/"phone").inner_html
245
247
  end
246
248
 
247
249
  ##
248
250
  # Returns billing first name
249
251
 
250
252
  def billing_first_name
251
- (@doc/"buyer-billing-address"/"structured-name"/"first-name").inner_html
253
+ (doc/"buyer-billing-address"/"structured-name"/"first-name").inner_html
252
254
  end
253
255
 
254
256
  ##
255
257
  # Returns billing last name
256
258
 
257
259
  def billing_last_name
258
- (@doc/"buyer-billing-address"/"structured-name"/"last-name").inner_html
260
+ (doc/"buyer-billing-address"/"structured-name"/"last-name").inner_html
259
261
  end
260
262
 
261
263
  ##
262
264
  # Returns shipping contact name
263
265
 
264
266
  def shipping_name
265
- (@doc/"buyer-shipping-address"/"contact-name").inner_html
267
+ (doc/"buyer-shipping-address"/"contact-name").inner_html
266
268
  end
267
269
 
268
270
  ##
269
271
  # Returns shipping email
270
272
 
271
273
  def shipping_email
272
- (@doc/"buyer-shipping-address"/"email").inner_html
274
+ (doc/"buyer-shipping-address"/"email").inner_html
273
275
  end
274
276
 
275
277
  ##
276
278
  # Returns shipping address1
277
279
 
278
280
  def shipping_address1
279
- (@doc/"buyer-shipping-address"/"address1").inner_html
281
+ (doc/"buyer-shipping-address"/"address1").inner_html
280
282
  end
281
283
 
282
284
  ##
283
285
  # Returns shipping city
284
286
 
285
287
  def shipping_city
286
- (@doc/"buyer-shipping-address"/"city").inner_html
288
+ (doc/"buyer-shipping-address"/"city").inner_html
287
289
  end
288
290
 
289
291
  ##
290
292
  # Returns shipping region
291
293
 
292
294
  def shipping_region
293
- (@doc/"buyer-shipping-address"/"region").inner_html
295
+ (doc/"buyer-shipping-address"/"region").inner_html
294
296
  end
295
297
 
296
298
  ##
297
299
  # Returns shipping postal code
298
300
 
299
301
  def shipping_postal_code
300
- (@doc/"buyer-shipping-address"/"postal-code").inner_html
302
+ (doc/"buyer-shipping-address"/"postal-code").inner_html
301
303
  end
302
304
 
303
305
  ##
304
306
  # Returns shipping country code
305
307
 
306
308
  def shipping_country_code
307
- (@doc/"buyer-shipping-address"/"country-code").inner_html
309
+ (doc/"buyer-shipping-address"/"country-code").inner_html
308
310
  end
309
311
 
310
312
  ##
311
313
  # Returns shipping phone
312
314
 
313
315
  def shipping_phone
314
- (@doc/"buyer-shipping-address"/"phone").inner_html
316
+ (doc/"buyer-shipping-address"/"phone").inner_html
315
317
  end
316
318
 
317
319
  ##
318
320
  # Returns shipping first name
319
321
 
320
322
  def shipping_first_name
321
- (@doc/"buyer-shipping-address"/"structured-name"/"first-name").inner_html
323
+ (doc/"buyer-shipping-address"/"structured-name"/"first-name").inner_html
322
324
  end
323
325
 
324
326
  ##
325
327
  # Returns shipping last name
326
328
 
327
329
  def shipping_last_name
328
- (@doc/"buyer-shipping-address"/"structured-name"/"last-name").inner_html
330
+ (doc/"buyer-shipping-address"/"structured-name"/"last-name").inner_html
329
331
  end
330
332
 
331
333
  end
@@ -344,19 +346,22 @@ module GoogleCheckout
344
346
  # Returns redirect-url with ampersands escaped, as specified by Google API docs.
345
347
 
346
348
  def redirect_url
347
- (@doc/"redirect-url").inner_html.gsub(/&amp;/, '&')
349
+ (doc/"redirect-url").inner_html.gsub(/&amp;/, '&')
348
350
  end
349
351
 
350
352
  end
351
353
 
352
354
  class Error < Notification
353
355
 
354
- ##
355
- # Alias for +error_message+
356
+ def initialize(doc, options={})
357
+ @error_message = options[:message]
358
+ super(doc)
359
+ end
356
360
 
357
- def message
358
- (@doc/'error-message').inner_html
361
+ def error_message
362
+ @error_message || (doc/'error-message').inner_html
359
363
  end
364
+ alias :message :error_message
360
365
 
361
366
  end
362
367
 
@@ -0,0 +1,5 @@
1
+ module GoogleCheckout
2
+ unless defined? GoogleCheckout::VERSION
3
+ VERSION = '0.3.0'
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout, "Cart (generic)" do
4
4
 
@@ -56,7 +56,7 @@ describe GoogleCheckout, "Cart Post" do
56
56
 
57
57
  it "should post request to Google" do
58
58
  # :null_object means eat all other methods and return self
59
- net_http = mock("net_http", { :null_object => true })
59
+ net_http = double("net_http").as_null_object
60
60
  Net::HTTP.should_receive(:new).and_return(net_http)
61
61
 
62
62
  success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
@@ -1,12 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "basic command", :shared => true do
4
-
5
- it "should include XML header" do
6
- @order.to_xml.should match(/^<\?xml version=\"1\.0\" encoding=\"UTF-8\"\?>/)
7
- end
8
-
9
- end
1
+ require "spec_helper"
10
2
 
11
3
  describe GoogleCheckout, "Command class" do
12
4
 
@@ -63,7 +55,7 @@ describe GoogleCheckout, "Charge Order" do
63
55
 
64
56
  it "should post request to Google successfully" do
65
57
  # :null_object means eat all other methods and return self
66
- net_http = mock("net_http", { :null_object => true })
58
+ net_http = double("net_http").as_null_object
67
59
  Net::HTTP.should_receive(:new).and_return(net_http)
68
60
 
69
61
  success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
@@ -78,7 +70,7 @@ describe GoogleCheckout, "Charge Order" do
78
70
 
79
71
  it "should post request to Google and return error" do
80
72
  # :null_object means eat all other methods and return self
81
- net_http = mock("net_http", { :null_object => true })
73
+ net_http = double("net_http").as_null_object
82
74
  Net::HTTP.should_receive(:new).and_return(net_http)
83
75
 
84
76
  # NOTE HTTP response code is irrelevant here.
@@ -86,11 +78,16 @@ describe GoogleCheckout, "Charge Order" do
86
78
  error_response.should_receive(:body).and_return(read_xml_fixture('responses/error'))
87
79
  net_http.should_receive(:request).and_return(error_response)
88
80
 
89
- lambda { @order.post }.should raise_error(GoogleCheckout::APIError)
81
+ response = @order.post
82
+ response.should be_kind_of(GoogleCheckout::Error)
83
+ response.should be_error
84
+ response.serial_number.should == 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614'
85
+ response.error_message.should == 'Bad username and/or password for API Access.'
86
+ response.message.should == 'Bad username and/or password for API Access.'
90
87
  end
91
88
 
92
89
  it "should post request to Google and return error charged already" do
93
- net_http = mock("net_http", { :null_object => true })
90
+ net_http = double("net_http").as_null_object
94
91
  Net::HTTP.should_receive(:new).and_return(net_http)
95
92
 
96
93
  # NOTE HTTP response code is irrelevant here.
@@ -99,9 +96,49 @@ describe GoogleCheckout, "Charge Order" do
99
96
  net_http.should_receive(:request).and_return(error_response)
100
97
 
101
98
  response = @order.post
99
+ response.should be_kind_of(GoogleCheckout::Error)
100
+ response.should be_error
101
+ response.serial_number.should == 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614'
102
+ response.error_message.should == 'You cannot charge an order that is already completely charged'
102
103
  response.message.should == 'You cannot charge an order that is already completely charged'
103
104
  end
104
105
 
106
+ context 'with Net::HTTPRedirection response' do
107
+ before do
108
+ net_http = double('net_http').as_null_object
109
+ Net::HTTP.should_receive(:new).and_return(net_http)
110
+
111
+ response = Net::HTTPRedirection.new(Net::HTTP.version_1_2, 301, "Redirect")
112
+ net_http.should_receive(:request).and_return(response)
113
+ end
114
+
115
+ it "return error" do
116
+ response = @order.post
117
+ response.should be_kind_of(GoogleCheckout::Error)
118
+ response.should be_error
119
+ response.serial_number.should be_nil
120
+ response.message.should == 'Unexpected response code (Net::HTTPRedirection): 301 - Redirect'
121
+ end
122
+ end
123
+
124
+ context 'with HTTPUnknownResponse response' do
125
+ before do
126
+ net_http = double('net_http').as_null_object
127
+ Net::HTTP.should_receive(:new).and_return(net_http)
128
+
129
+ response = Net::HTTPUnknownResponse.new(Net::HTTP.version_1_2, 600, "Unknown Response")
130
+ net_http.should_receive(:request).and_return(response)
131
+ end
132
+
133
+ it "return error" do
134
+ response = @order.post
135
+ response.should be_kind_of(GoogleCheckout::Error)
136
+ response.should be_error
137
+ response.serial_number.should be_nil
138
+ response.message.should == 'Unknown response code: 600 - Unknown Response'
139
+ end
140
+ end
141
+
105
142
  end
106
143
 
107
144
  describe GoogleCheckout, "Add Tracking Data" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Geography::Postal do
4
4
  before(:each) do
@@ -23,4 +23,4 @@ describe GoogleCheckout::Geography::Postal do
23
23
  @area.to_xml.should match(%r{<postal-code-pattern>53\*</postal-code-pattern>})
24
24
  end
25
25
 
26
- end
26
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Geography::UsCountry do
4
4
  before(:each) do
@@ -23,4 +23,4 @@ describe GoogleCheckout::Geography::UsCountry do
23
23
  lambda {GoogleCheckout::Geography::UsCountry.new(:my_house).to_xml}.should raise_error(ArgumentError)
24
24
  end
25
25
 
26
- end
26
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Geography::UsState do
4
4
  before(:each) do
@@ -8,4 +8,4 @@ describe GoogleCheckout::Geography::UsState do
8
8
  it 'should include the state' do
9
9
  @area.to_xml.should match(%r{<us-state-area><state>WI</state></us-state-area>})
10
10
  end
11
- end
11
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Geography::UsZip do
4
4
  before(:each) do
@@ -8,4 +8,4 @@ describe GoogleCheckout::Geography::UsZip do
8
8
  it 'should generate the us zip area tag' do
9
9
  @area.to_xml.should match(%r{<us-zip-area>.*</us-zip-area>})
10
10
  end
11
- end
11
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Geography::World do
4
4
  before(:each) do
@@ -9,4 +9,4 @@ describe GoogleCheckout::Geography::World do
9
9
  @area.to_xml.should eql("<world-area/>")
10
10
  end
11
11
 
12
- end
12
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout, "Merchant Calculation" do
4
4
 
@@ -14,4 +14,4 @@ describe GoogleCheckout, "Merchant Calculation" do
14
14
  @calculation.address_id.should == "739030698069958"
15
15
  end
16
16
 
17
- end
17
+ end
@@ -1,20 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "basic notification", :shared => true do
4
-
5
- it "should get serial number" do
6
- @notification.serial_number.should == 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614'
7
- end
8
-
9
- it "should get google order number" do
10
- @notification.google_order_number.should == '841171949013218'
11
- end
12
-
13
- it "should generate acknowledgment XML" do
14
- @notification.acknowledgment_xml.should match(/notification-acknowledgment/)
15
- end
16
-
17
- end
1
+ require "spec_helper"
18
2
 
19
3
  describe GoogleCheckout, "New Order Notification" do
20
4
 
@@ -270,3 +254,23 @@ describe GoogleCheckout, "Cancelled Order Notification" do
270
254
  end
271
255
 
272
256
  end
257
+
258
+ describe GoogleCheckout, "Error Notification" do
259
+ let(:notification) { GoogleCheckout::Notification.parse(read_xml_fixture('responses/error')) }
260
+ before do
261
+ @notification = notification
262
+ end
263
+
264
+ it "should identify type of notication" do
265
+ notification.should be_kind_of GoogleCheckout::Error
266
+ end
267
+
268
+ it "should have error message" do
269
+ notification.error_message.should == 'Bad username and/or password for API Access.'
270
+ end
271
+
272
+ it "should have message" do
273
+ notification.message.should == 'Bad username and/or password for API Access.'
274
+ end
275
+
276
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  # Responses
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Shipping::FlatRate do
4
4
  before(:each) do
@@ -43,4 +43,4 @@ describe GoogleCheckout::Shipping::FlatRate do
43
43
  @shipping.to_xml.should match(%r{<allow-us-po-box>false</allow-us-po-box>})
44
44
  end
45
45
 
46
- end
46
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Shipping::FlatRate do
4
4
  before(:each) do
@@ -67,4 +67,4 @@ describe GoogleCheckout::Shipping::FlatRate do
67
67
  @shipping.to_xml.should match(%r{<address-filters>.*<allow-us-po-box>false</allow-us-po-box>.*</address-filters>})
68
68
  end
69
69
 
70
- end
70
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleCheckout::Shipping::Pickup do
4
4
  before(:each) do
@@ -19,4 +19,4 @@ describe GoogleCheckout::Shipping::Pickup do
19
19
  @shipping.to_xml.should match(%r{<price currency="CAD">})
20
20
  end
21
21
 
22
- end
22
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe GoogleCheckout do
4
4
 
@@ -1,47 +1,25 @@
1
- require 'rubygems'
2
- require 'spec'
3
- require File.dirname(__FILE__) + "/../lib/google-checkout"
1
+ require File.expand_path('../../lib/google-checkout', __FILE__)
4
2
 
5
- def read_xml_fixture(filename)
6
- File.read(File.dirname(__FILE__) + "/fixtures/google/#{filename}.xml")
7
- end
3
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each {|f| require f}
8
4
 
9
- # A better +be_kind_of+ with more informative error messages.
10
- #
11
- # The default +be_kind_of+ just says
12
- #
13
- # "expected to return true but got false"
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # Require this file using `require "spec_helper"` to ensure that it is only
8
+ # loaded once.
14
9
  #
15
- # This one says
16
- #
17
- # "expected File but got Tempfile"
18
-
19
- class BeKindOf
20
-
21
- def initialize(expected) # + args
22
- @expected = expected
23
- end
24
-
25
- def matches?(target)
26
- @target = target
27
- @target.kind_of?(@expected)
28
- end
29
-
30
- def failure_message
31
- "expected #{@expected} but got #{@target.class}"
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+
22
+ def read_xml_fixture(filename)
23
+ File.read(File.dirname(__FILE__) + "/fixtures/google/#{filename}.xml")
32
24
  end
33
-
34
- def negative_failure_message
35
- "expected #{@expected} to not be #{@target.class}"
36
- end
37
-
38
- def description
39
- "be_kind_of #{@target}"
40
- end
41
-
42
- end
43
-
44
- def be_kind_of(expected) # + args
45
- BeKindOf.new(expected)
46
25
  end
47
-
@@ -0,0 +1,5 @@
1
+ shared_examples_for "basic command" do
2
+ it "should include XML header" do
3
+ @order.to_xml.should match(/^<\?xml version=\"1\.0\" encoding=\"UTF-8\"\?>/)
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ shared_examples_for "basic notification" do
2
+
3
+ it "should get serial number" do
4
+ @notification.serial_number.should == 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614'
5
+ end
6
+
7
+ it "should get google order number" do
8
+ @notification.google_order_number.should == '841171949013218'
9
+ end
10
+
11
+ it "should generate acknowledgment XML" do
12
+ @notification.acknowledgment_xml.should match(/notification-acknowledgment/)
13
+ end
14
+
15
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/google-checkout/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Peter Elmore", "Geoffrey Grosenbach", "Matt Lins", "Steel Fu", "Andrew Assarattanakul"]
6
+ gem.email = ["assarata@gmail.com"]
7
+ gem.description = %q{An experimental library for sending payment requests to Google Checkout.}
8
+ gem.summary = %q{Google Checkout}
9
+ gem.homepage = "https://github.com/vizjerai/google-checkout"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "vizjerai-google-checkout"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = GoogleCheckout::VERSION
17
+
18
+ gem.add_dependency 'activesupport', '>= 2.3.0'
19
+ gem.add_dependency 'money', '>= 2.3.0'
20
+ gem.add_dependency 'nokogiri'
21
+ gem.add_dependency 'builder'
22
+
23
+ gem.add_development_dependency 'bundler'
24
+ gem.add_development_dependency 'rubygems-bundler'
25
+ gem.add_development_dependency 'rspec'
26
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vizjerai-google-checkout
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
4
+ hash: 19
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Elmore
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2011-02-14 00:00:00 -06:00
22
+ date: 2012-07-27 00:00:00 -05:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -69,38 +69,80 @@ dependencies:
69
69
  type: :runtime
70
70
  version_requirements: *id003
71
71
  - !ruby/object:Gem::Dependency
72
- name: rspec
72
+ name: builder
73
73
  prerelease: false
74
74
  requirement: &id004 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
- - - ~>
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
- hash: 27
79
+ hash: 3
80
80
  segments:
81
- - 1
82
- - 3
83
81
  - 0
84
- version: 1.3.0
85
- type: :development
82
+ version: "0"
83
+ type: :runtime
86
84
  version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: bundler
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubygems-bundler
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ type: :development
112
+ version_requirements: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec
115
+ prerelease: false
116
+ requirement: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ type: :development
126
+ version_requirements: *id007
87
127
  description: An experimental library for sending payment requests to Google Checkout.
88
- email: assarata@gmail.com
128
+ email:
129
+ - assarata@gmail.com
89
130
  executables: []
90
131
 
91
132
  extensions: []
92
133
 
93
- extra_rdoc_files:
94
- - README.txt
134
+ extra_rdoc_files: []
135
+
95
136
  files:
137
+ - .gitignore
138
+ - Gemfile
96
139
  - History.txt
97
140
  - MIT-LICENSE.txt
98
141
  - README.txt
99
142
  - Rakefile
100
- - VERSION
101
143
  - examples/google_notifications_controller.rb
102
- - lib/duck_punches/hpricot.rb
103
144
  - lib/duck_punches/inflector.rb
145
+ - lib/duck_punches/nokogiri.rb
104
146
  - lib/google-checkout.rb
105
147
  - lib/google-checkout/cart.rb
106
148
  - lib/google-checkout/command.rb
@@ -120,6 +162,7 @@ files:
120
162
  - lib/google-checkout/shipping/method.rb
121
163
  - lib/google-checkout/shipping/pickup.rb
122
164
  - lib/google-checkout/shipping/restrictions.rb
165
+ - lib/google-checkout/version.rb
123
166
  - spec/fixtures/google/checkout-shopping-cart.xml
124
167
  - spec/fixtures/google/commands/add-merchant-order-number.xml
125
168
  - spec/fixtures/google/commands/add-tracking-data.xml
@@ -161,9 +204,12 @@ files:
161
204
  - spec/google-checkout/shipping/pickup_spec.rb
162
205
  - spec/google-checkout_spec.rb
163
206
  - spec/spec_helper.rb
207
+ - spec/support/shared_example_groups/basic_command.rb
208
+ - spec/support/shared_example_groups/basic_notification.rb
164
209
  - support/cacert.pem
210
+ - vizjerai-google-checkout.gemspec
165
211
  has_rdoc: true
166
- homepage: http://github.com/vizjerai/google-checkout/
212
+ homepage: https://github.com/vizjerai/google-checkout
167
213
  licenses: []
168
214
 
169
215
  post_install_message:
@@ -192,12 +238,37 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
238
  requirements: []
193
239
 
194
240
  rubyforge_project:
195
- rubygems_version: 1.5.2
241
+ rubygems_version: 1.3.7
196
242
  signing_key:
197
243
  specification_version: 3
198
- summary: An experimental library for sending payment requests to Google Checkout.
244
+ summary: Google Checkout
199
245
  test_files:
200
- - examples/google_notifications_controller.rb
246
+ - spec/fixtures/google/checkout-shopping-cart.xml
247
+ - spec/fixtures/google/commands/add-merchant-order-number.xml
248
+ - spec/fixtures/google/commands/add-tracking-data.xml
249
+ - spec/fixtures/google/commands/archive-order.xml
250
+ - spec/fixtures/google/commands/authorize-order.xml
251
+ - spec/fixtures/google/commands/cancel-order.xml
252
+ - spec/fixtures/google/commands/charge-order.xml
253
+ - spec/fixtures/google/commands/deliver-order.xml
254
+ - spec/fixtures/google/commands/process-order.xml
255
+ - spec/fixtures/google/commands/refund-order.xml
256
+ - spec/fixtures/google/commands/send-buyer-message.xml
257
+ - spec/fixtures/google/commands/unarchive-order.xml
258
+ - spec/fixtures/google/merchant_calculations/shipping.xml
259
+ - spec/fixtures/google/notifications/authorization-amount-notification.xml
260
+ - spec/fixtures/google/notifications/cancelled-subscription-notification.xml
261
+ - spec/fixtures/google/notifications/charge-amount-notification.xml
262
+ - spec/fixtures/google/notifications/chargeback-amount-notification.xml
263
+ - spec/fixtures/google/notifications/new-order-notification.xml
264
+ - spec/fixtures/google/notifications/order-state-change-notification-missing.xml
265
+ - spec/fixtures/google/notifications/order-state-change-notification.xml
266
+ - spec/fixtures/google/notifications/refund-amount-notification.xml
267
+ - spec/fixtures/google/notifications/risk-information-notification.xml
268
+ - spec/fixtures/google/responses/checkout-redirect.xml
269
+ - spec/fixtures/google/responses/error-charged.xml
270
+ - spec/fixtures/google/responses/error.xml
271
+ - spec/fixtures/google/responses/request-received.xml
201
272
  - spec/google-checkout/cart_spec.rb
202
273
  - spec/google-checkout/command_spec.rb
203
274
  - spec/google-checkout/geography/postal_spec.rb
@@ -213,3 +284,5 @@ test_files:
213
284
  - spec/google-checkout/shipping/pickup_spec.rb
214
285
  - spec/google-checkout_spec.rb
215
286
  - spec/spec_helper.rb
287
+ - spec/support/shared_example_groups/basic_command.rb
288
+ - spec/support/shared_example_groups/basic_notification.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.3