mlins-google-checkout 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/History.txt +14 -0
  2. data/MIT-LICENSE.txt +23 -0
  3. data/README.txt +143 -0
  4. data/Rakefile +34 -0
  5. data/VERSION.yml +4 -0
  6. data/examples/google_notifications_controller.rb +159 -0
  7. data/lib/duck_punches/hpricot.rb +24 -0
  8. data/lib/google-checkout.rb +65 -0
  9. data/lib/google-checkout/cart.rb +302 -0
  10. data/lib/google-checkout/command.rb +191 -0
  11. data/lib/google-checkout/geography.rb +7 -0
  12. data/lib/google-checkout/geography/area.rb +11 -0
  13. data/lib/google-checkout/geography/postal.rb +26 -0
  14. data/lib/google-checkout/geography/us_country.rb +24 -0
  15. data/lib/google-checkout/geography/us_state.rb +22 -0
  16. data/lib/google-checkout/geography/us_zip.rb +22 -0
  17. data/lib/google-checkout/geography/world.rb +12 -0
  18. data/lib/google-checkout/merchant_calculation.rb +30 -0
  19. data/lib/google-checkout/notification.rb +212 -0
  20. data/lib/google-checkout/shipping.rb +8 -0
  21. data/lib/google-checkout/shipping/filters.rb +32 -0
  22. data/lib/google-checkout/shipping/flat_rate.rb +26 -0
  23. data/lib/google-checkout/shipping/merchant_calculated.rb +29 -0
  24. data/lib/google-checkout/shipping/method.rb +11 -0
  25. data/lib/google-checkout/shipping/pickup.rb +22 -0
  26. data/lib/google-checkout/shipping/restrictions.rb +32 -0
  27. data/spec/fixtures/google/checkout-shopping-cart.xml +22 -0
  28. data/spec/fixtures/google/commands/add-merchant-order-number.xml +5 -0
  29. data/spec/fixtures/google/commands/add-tracking-data.xml +8 -0
  30. data/spec/fixtures/google/commands/archive-order.xml +3 -0
  31. data/spec/fixtures/google/commands/authorize-order.xml +2 -0
  32. data/spec/fixtures/google/commands/cancel-order.xml +5 -0
  33. data/spec/fixtures/google/commands/charge-order.xml +4 -0
  34. data/spec/fixtures/google/commands/deliver-order.xml +9 -0
  35. data/spec/fixtures/google/commands/process-order.xml +2 -0
  36. data/spec/fixtures/google/commands/refund-order.xml +6 -0
  37. data/spec/fixtures/google/commands/send-buyer-message.xml +7 -0
  38. data/spec/fixtures/google/commands/unarchive-order.xml +2 -0
  39. data/spec/fixtures/google/merchant_calculations/shipping.xml +40 -0
  40. data/spec/fixtures/google/notifications/authorization-amount-notification.xml +10 -0
  41. data/spec/fixtures/google/notifications/charge-amount-notification.xml +8 -0
  42. data/spec/fixtures/google/notifications/chargeback-amount-notification.xml +8 -0
  43. data/spec/fixtures/google/notifications/new-order-notification.xml +85 -0
  44. data/spec/fixtures/google/notifications/order-state-change-notification.xml +11 -0
  45. data/spec/fixtures/google/notifications/refund-amount-notification.xml +8 -0
  46. data/spec/fixtures/google/notifications/risk-information-notification.xml +23 -0
  47. data/spec/fixtures/google/responses/checkout-redirect.xml +5 -0
  48. data/spec/fixtures/google/responses/error.xml +5 -0
  49. data/spec/fixtures/google/responses/request-received.xml +3 -0
  50. data/spec/google-checkout/cart_spec.rb +110 -0
  51. data/spec/google-checkout/command_spec.rb +131 -0
  52. data/spec/google-checkout/geography/postal_spec.rb +26 -0
  53. data/spec/google-checkout/geography/us_country_spec.rb +26 -0
  54. data/spec/google-checkout/geography/us_state_spec.rb +11 -0
  55. data/spec/google-checkout/geography/us_zip_spec.rb +11 -0
  56. data/spec/google-checkout/geography/world_spec.rb +12 -0
  57. data/spec/google-checkout/merchant_calculation_spec.rb +17 -0
  58. data/spec/google-checkout/notification_spec.rb +175 -0
  59. data/spec/google-checkout/response_spec.rb +49 -0
  60. data/spec/google-checkout/shipping/flat_rate_spec.rb +46 -0
  61. data/spec/google-checkout/shipping/merchant_calculated_spec.rb +70 -0
  62. data/spec/google-checkout/shipping/pickup_spec.rb +22 -0
  63. data/spec/google-checkout_spec.rb +15 -0
  64. data/spec/spec_helper.rb +47 -0
  65. data/support/cacert.pem +7815 -0
  66. metadata +140 -0
@@ -0,0 +1,29 @@
1
+ module GoogleCheckout
2
+ module Shipping
3
+ class MerchantCalculated < Method
4
+
5
+ include Restrictions
6
+ include Filters
7
+
8
+ attr_accessor :name, :price, :currency
9
+
10
+ def initialize(name, price, currency = 'USD')
11
+ @name = name
12
+ @price = price
13
+ @currency = currency
14
+ @shipping_restrictions = {:allowed => [], :excluded => [], :allow_us_po_box => true}
15
+ @address_filters = {:allowed => [], :excluded => [], :allow_us_po_box => true}
16
+ end
17
+
18
+ def to_xml
19
+ xml = Builder::XmlMarkup.new
20
+ xml.tag!('merchant-calculated-shipping', :name => name) do
21
+ xml.tag!('price', price, :currency => currency)
22
+ xml << shipping_restrictions_xml if shipping_restrictions?
23
+ xml << address_filters_xml if address_filters?
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module GoogleCheckout
2
+ module Shipping
3
+ class Method
4
+
5
+ def to_xml
6
+ raise NotImplementedError
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module GoogleCheckout
2
+ module Shipping
3
+ class Pickup < Method
4
+
5
+ attr_accessor :name, :price, :currency
6
+
7
+ def initialize(name, price = '0.00', currency = 'USD')
8
+ @name = name
9
+ @price = price
10
+ @currency = currency
11
+ end
12
+
13
+ def to_xml
14
+ xml = Builder::XmlMarkup.new
15
+ xml.tag!('pickup', :name => name) do
16
+ xml.tag!('price', price, :currency => currency)
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ module GoogleCheckout
2
+ module Shipping
3
+ module Restrictions
4
+
5
+ attr_accessor :shipping_restrictions
6
+
7
+ def shipping_restrictions?
8
+ @shipping_restrictions != {:allowed => [], :excluded => [], :allow_us_po_box => true}
9
+ end
10
+
11
+ def shipping_restrictions_xml
12
+ xml = Builder::XmlMarkup.new
13
+ xml.tag!('shipping-restrictions') do
14
+ xml.tag!('allowed-areas') do
15
+ @shipping_restrictions[:allowed].each do |area|
16
+ xml << area.to_xml
17
+ end
18
+ end unless @shipping_restrictions[:allowed].empty?
19
+ xml.tag!('excluded-areas') do
20
+ @shipping_restrictions[:excluded].each do |area|
21
+ xml << area.to_xml
22
+ end
23
+ end unless @shipping_restrictions[:excluded].empty?
24
+ xml.tag!('allow-us-po-box') do
25
+ xml.text! 'false'
26
+ end unless @shipping_restrictions[:allow_us_po_box]
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
3
+ <shopping-cart>
4
+ <items>
5
+ <item>
6
+ <item-name>HelloWorld 2GB MP3 Player</item-name>
7
+ <item-description>HelloWorld, the simple MP3 player</item-description>
8
+ <unit-price currency="USD">159.99</unit-price>
9
+ <quantity>1</quantity>
10
+ </item>
11
+ </items>
12
+ </shopping-cart>
13
+ <checkout-flow-support>
14
+ <merchant-checkout-flow-support>
15
+ <shipping-methods>
16
+ <flat-rate-shipping name="SuperShip Ground">
17
+ <price currency="USD">9.99</price>
18
+ </flat-rate-shipping>
19
+ </shipping-methods>
20
+ </merchant-checkout-flow-support>
21
+ </checkout-flow-support>
22
+ </checkout-shopping-cart>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <add-merchant-order-number xmlns="http://checkout.google.com/schema/2"
3
+ google-order-number="841171949013218">
4
+ <merchant-order-number>P6502-53-7861SBJD</merchant-order-number>
5
+ </add-merchant-order-number>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <add-tracking-data xmlns="http://checkout.google.com/schema/2"
3
+ google-order-number="841171949013218">
4
+ <tracking-data>
5
+ <carrier>UPS</carrier>
6
+ <tracking-number>Z9842W69871281267</tracking-number>
7
+ </tracking-data>
8
+ </add-tracking-data>
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <archive-order xmlns="http://checkout.google.com/schema/2"
3
+ google-order-number="841171949013218" />
@@ -0,0 +1,2 @@
1
+ <authorize-order xmlns="http://checkout.google.com/schema/2"
2
+ google-order-number="6014423719"/>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <cancel-order xmlns="http://checkout.google.com/schema/2" google-order-number="841171949013218">
3
+ <reason>Buyer cancelled the order.</reason>
4
+ <comment>Buyer ordered another item.</comment>
5
+ </cancel-order>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <charge-order xmlns="http://checkout.google.com/schema/2" google-order-number="6014423719">
3
+ <amount currency="USD">335.55</amount>
4
+ </charge-order>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <deliver-order xmlns="http://checkout.google.com/schema/2"
3
+ google-order-number="841171949013218">
4
+ <tracking-data>
5
+ <carrier>UPS</carrier>
6
+ <tracking-number>Z5498W45987123684</tracking-number>
7
+ </tracking-data>
8
+ <send-email>false</send-email>
9
+ </deliver-order>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <process-order xmlns="http://checkout.google.com/schema/2" google-order-number="841171949013218"/>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <refund-order xmlns="http://checkout.google.com/schema/2" google-order-number="6014423719">
3
+ <amount currency="USD">15.00</amount>
4
+ <comment>Discount for inconvenience; ship replacement item</comment>
5
+ <reason>Damaged Merchandise</reason>
6
+ </refund-order>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <send-buyer-message xmlns="http://checkout.google.com/schema/2"
3
+ google-order-number="841171949013218">
4
+ <message>Due to high volume, your order will ship
5
+ next week. Thank you for your patience.</message>
6
+ <send-email>true</send-email>
7
+ </send-buyer-message>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <unarchive-order xmlns="http://checkout.google.com/schema/2" google-order-number="841171949013218" />
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <merchant-calculation-callback xmlns="http://checkout.google.com/schema/2">
3
+ <shopping-cart>
4
+ <cart-expiration>
5
+ <good-until-date>2007-12-31T23:59:59-05:00</good-until-date>
6
+ </cart-expiration>
7
+ <items>
8
+ <item>
9
+ <merchant-item-id>GGLAA1453</merchant-item-id>
10
+ <item-name>Dry Food Pack</item-name>
11
+ <item-description>One pack of nutritious dried food for emergencies.</item-description>
12
+ <quantity>1</quantity>
13
+ <unit-price currency="USD">4.99</unit-price>
14
+ </item>
15
+ <item>
16
+ <merchant-item-id>MGS2GBMP3</merchant-item-id>
17
+ <item-name>Megasound 2GB MP3 Player</item-name>
18
+ <item-description>This portable MP3 player stores 500 songs.</item-description>
19
+ <quantity>1</quantity>
20
+ <unit-price currency="USD">179.99</unit-price>
21
+ </item>
22
+ </items>
23
+ </shopping-cart>
24
+
25
+ <buyer-language>en_US</buyer-language>
26
+ <calculate>
27
+ <addresses>
28
+ <anonymous-address id="739030698069958">
29
+ <country-code>US</country-code>
30
+ <city>Anchorage</city>
31
+ <region>AK</region>
32
+ <postal-code>99501</postal-code>
33
+ </anonymous-address>
34
+ </addresses>
35
+ <shipping>
36
+ <method name="UPS 2nd Day Air"/>
37
+ <method name="UPS Ground"/>
38
+ </shipping>
39
+ </calculate>
40
+ </merchant-calculation-callback>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <authorization-amount-notification xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <google-order-number>841171949013218</google-order-number>
5
+ <authorization-amount currency="USD">226.06</authorization-amount>
6
+ <authorization-expiration-date>2006-03-18T20:25:31</authorization-expiration-date>
7
+ <avs-response>Y</avs-response>
8
+ <cvn-response>Y</cvn-response>
9
+ <timestamp>2006-03-18T20:25:31</timestamp>
10
+ </authorization-amount-notification>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <charge-amount-notification xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <google-order-number>841171949013218</google-order-number>
5
+ <latest-charge-amount currency="USD">226.06</latest-charge-amount>
6
+ <total-charge-amount currency="USD">226.06</total-charge-amount>
7
+ <timestamp>2006-03-18T18:25:31</timestamp>
8
+ </charge-amount-notification>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <google-order-number>841171949013218</google-order-number>
5
+ <latest-chargeback-amount currency="USD">226.06</latest-chargeback-amount>
6
+ <total-chargeback-amount currency="USD">226.06</total-chargeback-amount>
7
+ <timestamp>2006-03-18T20:25:31</timestamp>
8
+ </chargeback-amount-notification>
@@ -0,0 +1,85 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <new-order-notification xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <google-order-number>841171949013218</google-order-number>
5
+ <buyer-shipping-address>
6
+
7
+ <contact-name>John Smith</contact-name>
8
+ <email>johnsmith@example.com</email>
9
+ <address1>10 Example Road</address1>
10
+ <city>Sampleville</city>
11
+ <region>CA</region>
12
+ <postal-code>94141</postal-code>
13
+ <country-code>US</country-code>
14
+ </buyer-shipping-address>
15
+ <buyer-billing-address>
16
+ <contact-name>Bill Hu</contact-name>
17
+ <email>billhu@example.com</email>
18
+ <address1>99 Credit Lane</address1>
19
+ <city>Mountain View</city>
20
+ <region>CA</region>
21
+ <postal-code>94043</postal-code>
22
+ <country-code>US</country-code>
23
+ </buyer-billing-address>
24
+ <buyer-id>294873009217523</buyer-id>
25
+ <fulfillment-order-state>NEW</fulfillment-order-state>
26
+ <financial-order-state>REVIEWING</financial-order-state>
27
+
28
+ <shopping-cart>
29
+ <cart-expiration>
30
+ <good-until-date>2007-12-31T23:59:59-05:00</good-until-date>
31
+ </cart-expiration>
32
+ <items>
33
+ <item>
34
+ <merchant-item-id>GGLAA1453</merchant-item-id>
35
+ <item-name>Dry Food Pack</item-name>
36
+ <item-description>One pack of nutritious dried food for emergencies.</item-description>
37
+ <quantity>1</quantity>
38
+ <tax-table-selector>food</tax-table-selector>
39
+ <unit-price currency="USD">4.99</unit-price>
40
+ </item>
41
+ <item>
42
+ <merchant-item-id>MGS2GBMP3</merchant-item-id>
43
+ <item-name>Megasound 2GB MP3 Player</item-name>
44
+ <item-description>This portable MP3 player stores 500 songs.</item-description>
45
+ <quantity>1</quantity>
46
+ <unit-price currency="USD">179.99</unit-price>
47
+ <merchant-private-item-data>
48
+ <merchant-product-id>1234567890</merchant-product-id>
49
+ </merchant-private-item-data>
50
+ </item>
51
+ </items>
52
+ <merchant-private-data>
53
+ <peepcode-order-number>1234-5678-9012</peepcode-order-number>
54
+ </merchant-private-data>
55
+ </shopping-cart>
56
+ <order-adjustment>
57
+ <merchant-calculation-successful>true</merchant-calculation-successful>
58
+ <merchant-codes>
59
+ <coupon-adjustment>
60
+ <applied-amount currency="USD">5.00</applied-amount>
61
+ <code>FirstVisitCoupon</code>
62
+ <calculated-amount currency="USD">5.00</calculated-amount>
63
+ <message>You saved $5.00 for your first visit!</message>
64
+ </coupon-adjustment>
65
+ <gift-certificate-adjustment>
66
+ <applied-amount currency="USD">10.00</applied-amount>
67
+ <code>GiftCert12345</code>
68
+ <calculated-amount currency="USD">10.00</calculated-amount>
69
+ <message>You saved $10.00 with this gift certificate!</message>
70
+ </gift-certificate-adjustment>
71
+ </merchant-codes>
72
+ <total-tax currency="USD">0.0</total-tax>
73
+ <shipping>
74
+ <merchant-calculated-shipping-adjustment>
75
+ <shipping-name>SuperShip</shipping-name>
76
+ <shipping-cost currency="USD">9.95</shipping-cost>
77
+ </merchant-calculated-shipping-adjustment>
78
+ </shipping>
79
+ </order-adjustment>
80
+ <order-total currency="USD">190.98</order-total>
81
+ <buyer-marketing-preferences>
82
+ <email-allowed>false</email-allowed>
83
+ </buyer-marketing-preferences>
84
+ <timestamp>2006-05-03T17:32:11</timestamp>
85
+ </new-order-notification>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <order-state-change-notification xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <google-order-number>841171949013218</google-order-number>
5
+ <new-financial-order-state>CHARGING</new-financial-order-state>
6
+ <new-fulfillment-order-state>NEW</new-fulfillment-order-state>
7
+ <previous-financial-order-state>CHARGEABLE</previous-financial-order-state>
8
+ <previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
9
+ <reason>The reason goes here, if there is one.</reason>
10
+ <timestamp>2006-05-03T17:32:11</timestamp>
11
+ </order-state-change-notification>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <refund-amount-notification xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <google-order-number>841171949013218</google-order-number>
5
+ <latest-refund-amount currency="USD">226.06</latest-refund-amount>
6
+ <total-refund-amount currency="USD">226.06</total-refund-amount>
7
+ <timestamp>2006-03-18T20:25:31</timestamp>
8
+ </refund-amount-notification>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <risk-information-notification xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <google-order-number>841171949013218</google-order-number>
5
+ <risk-information>
6
+ <eligible-for-protection>true</eligible-for-protection>
7
+ <billing-address id="BuyerBillingAddress">
8
+ <contact-name>John Smith</contact-name>
9
+ <email>johnsmith@example.com</email>
10
+ <address1>10 Example Road</address1>
11
+ <city>Sampleville</city>
12
+ <region>CA</region>
13
+ <postal-code>94141</postal-code>
14
+ <country-code>US</country-code>
15
+ </billing-address>
16
+ <avs-response>Y</avs-response>
17
+ <cvn-response>M</cvn-response>
18
+ <partial-cc-number>3719</partial-cc-number>
19
+ <ip-address>10.11.12.13</ip-address>
20
+ <buyer-account-age>6</buyer-account-age>
21
+ </risk-information>
22
+ <timestamp>2006-01-15T10:44:06</timestamp>
23
+ </risk-information-notification>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <checkout-redirect xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <redirect-url>https://checkout.google.com/buy?foo=bar&amp;id=8572098456</redirect-url>
5
+ </checkout-redirect>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <error xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
4
+ <error-message>Bad username and/or password for API Access.</error-message>
5
+ </error>
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <request-received xmlns="http://checkout.google.com/schema/2"
3
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614"/>
@@ -0,0 +1,110 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe GoogleCheckout, "Cart (generic)" do
4
+
5
+ before(:each) do
6
+ @cart = GoogleCheckout::Cart.new("my_id", "my_key", {
7
+ :name => "PeepCode Screencast",
8
+ :description => "A few screencasts",
9
+ :price => 9.00
10
+ })
11
+ GoogleCheckout.use_sandbox
12
+ end
13
+
14
+ it "should generate proper live buy button_url" do
15
+ GoogleCheckout.use_production
16
+ @cart.button_url.should match(%r{http://checkout\.google\.com/buttons/buy\.gif})
17
+ end
18
+
19
+ it "should generate proper live checkout button_url" do
20
+ GoogleCheckout.use_production
21
+ @cart.button_url(:buy_or_checkout => :checkout).should match(%r{http://checkout\.google\.com/buttons/checkout\.gif})
22
+ end
23
+
24
+ it "should generate proper sandbox buy button_url" do
25
+ @cart.button_url.should match(%r{http://sandbox\.google\.com/buttons/buy\.gif})
26
+ end
27
+
28
+ it "should generate proper sandbox checkout button_url" do
29
+ @cart.button_url(:buy_or_checkout => :checkout).should match(%r{http://sandbox\.google\.com/checkout/buttons/checkout\.gif})
30
+ end
31
+
32
+ it "should generate checkout button" do
33
+ @cart.checkout_button.should match(/buy\.gif/)
34
+ end
35
+
36
+ end
37
+
38
+ describe GoogleCheckout, "Cart Post" do
39
+
40
+ before(:each) do
41
+ @cart = GoogleCheckout::Cart.new("my_id", "my_key", {
42
+ :name => "PeepCode Screencast",
43
+ :description => "One screencast",
44
+ :price => 9.00
45
+ })
46
+ GoogleCheckout.use_sandbox
47
+ end
48
+
49
+ it "should get merchant_id" do
50
+ @cart.merchant_id.should == 'my_id'
51
+ end
52
+
53
+ it "should get merchant_key" do
54
+ @cart.merchant_key.should == 'my_key'
55
+ end
56
+
57
+ it "should post request to Google" do
58
+ # :null_object means eat all other methods and return self
59
+ net_http = mock("net_http", { :null_object => true })
60
+ Net::HTTP.should_receive(:new).and_return(net_http)
61
+
62
+ success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
63
+ success_response.should_receive(:body).and_return(read_xml_fixture('responses/checkout-redirect'))
64
+ net_http.should_receive(:request).and_return(success_response)
65
+
66
+ response = @cart.post
67
+ response.should be_kind_of(GoogleCheckout::CheckoutRedirect)
68
+ response.serial_number.should == 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614'
69
+ response.redirect_url.should == 'https://checkout.google.com/buy?foo=bar&id=8572098456'
70
+ end
71
+
72
+ it "should set merchant private data" do
73
+ @cart.merchant_private_data = { "merchant-order-number" => "1234-5678-9012" }
74
+ @cart.merchant_private_data["merchant-order-number"].should == "1234-5678-9012"
75
+ end
76
+
77
+ it "should include merchant private in the generated xml" do
78
+ @cart.merchant_private_data = { "merchant-order-number" => "1234-5678-9012" }
79
+ @cart.to_xml.should match(/<merchant-order-number>1234-5678-9012<\/merchant-order-number>/)
80
+ end
81
+
82
+ it "should not include merchant private data if none is set" do
83
+ @cart.to_xml.should_not match(/<merchant-private-data>/)
84
+ end
85
+
86
+ it "should include merchant-item-id in XML if :item_id was passed with the item" do
87
+ @cart.add_item({
88
+ :name => "Item",
89
+ :description => "Item description",
90
+ :price => "1.00",
91
+ :quantity => 1,
92
+ :item_id => "ITEM-007"
93
+ })
94
+ @cart.to_xml.should match(%r{<merchant-item-id>ITEM-007</merchant-item-id>})
95
+ end
96
+
97
+ it "should include the merchant calculations url in the generated xml" do
98
+ @cart.merchant_calculations_url = 'http://my.calculations.com'
99
+ @cart.to_xml.should match(%r{<merchant-calculations-url>http://my.calculations.com</merchant-calculations-url>})
100
+ end
101
+
102
+ it "should not include the merchant calculations url if it's not set" do
103
+ @cart.to_xml.should_not match(%r{<merchant-calculations-url>})
104
+ end
105
+
106
+ it "should generate XML"
107
+
108
+ it "should receive error when placing false request"
109
+
110
+ end