vizjerai-google-checkout 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +14 -0
- data/MIT-LICENSE.txt +23 -0
- data/README.txt +143 -0
- data/Rakefile +34 -0
- data/VERSION.yml +4 -0
- data/examples/google_notifications_controller.rb +159 -0
- data/lib/duck_punches/hpricot.rb +24 -0
- data/lib/google-checkout/cart.rb +304 -0
- data/lib/google-checkout/command.rb +255 -0
- data/lib/google-checkout/geography/area.rb +11 -0
- data/lib/google-checkout/geography/postal.rb +26 -0
- data/lib/google-checkout/geography/us_country.rb +24 -0
- data/lib/google-checkout/geography/us_state.rb +22 -0
- data/lib/google-checkout/geography/us_zip.rb +22 -0
- data/lib/google-checkout/geography/world.rb +12 -0
- data/lib/google-checkout/geography.rb +7 -0
- data/lib/google-checkout/merchant_calculation.rb +30 -0
- data/lib/google-checkout/notification.rb +352 -0
- data/lib/google-checkout/shipping/filters.rb +32 -0
- data/lib/google-checkout/shipping/flat_rate.rb +26 -0
- data/lib/google-checkout/shipping/merchant_calculated.rb +29 -0
- data/lib/google-checkout/shipping/method.rb +11 -0
- data/lib/google-checkout/shipping/pickup.rb +22 -0
- data/lib/google-checkout/shipping/restrictions.rb +32 -0
- data/lib/google-checkout/shipping.rb +8 -0
- data/lib/google-checkout.rb +65 -0
- data/spec/fixtures/google/checkout-shopping-cart.xml +22 -0
- data/spec/fixtures/google/commands/add-merchant-order-number.xml +5 -0
- data/spec/fixtures/google/commands/add-tracking-data.xml +8 -0
- data/spec/fixtures/google/commands/archive-order.xml +3 -0
- data/spec/fixtures/google/commands/authorize-order.xml +2 -0
- data/spec/fixtures/google/commands/cancel-order.xml +5 -0
- data/spec/fixtures/google/commands/charge-order.xml +4 -0
- data/spec/fixtures/google/commands/deliver-order.xml +9 -0
- data/spec/fixtures/google/commands/process-order.xml +2 -0
- data/spec/fixtures/google/commands/refund-order.xml +6 -0
- data/spec/fixtures/google/commands/send-buyer-message.xml +7 -0
- data/spec/fixtures/google/commands/unarchive-order.xml +2 -0
- data/spec/fixtures/google/merchant_calculations/shipping.xml +40 -0
- data/spec/fixtures/google/notifications/authorization-amount-notification.xml +10 -0
- data/spec/fixtures/google/notifications/charge-amount-notification.xml +8 -0
- data/spec/fixtures/google/notifications/chargeback-amount-notification.xml +8 -0
- data/spec/fixtures/google/notifications/new-order-notification.xml +94 -0
- data/spec/fixtures/google/notifications/order-state-change-notification.xml +11 -0
- data/spec/fixtures/google/notifications/refund-amount-notification.xml +8 -0
- data/spec/fixtures/google/notifications/risk-information-notification.xml +23 -0
- data/spec/fixtures/google/responses/checkout-redirect.xml +5 -0
- data/spec/fixtures/google/responses/error-charged.xml +5 -0
- data/spec/fixtures/google/responses/error.xml +5 -0
- data/spec/fixtures/google/responses/request-received.xml +3 -0
- data/spec/google-checkout/cart_spec.rb +110 -0
- data/spec/google-checkout/command_spec.rb +216 -0
- data/spec/google-checkout/geography/postal_spec.rb +26 -0
- data/spec/google-checkout/geography/us_country_spec.rb +26 -0
- data/spec/google-checkout/geography/us_state_spec.rb +11 -0
- data/spec/google-checkout/geography/us_zip_spec.rb +11 -0
- data/spec/google-checkout/geography/world_spec.rb +12 -0
- data/spec/google-checkout/merchant_calculation_spec.rb +17 -0
- data/spec/google-checkout/notification_spec.rb +253 -0
- data/spec/google-checkout/response_spec.rb +49 -0
- data/spec/google-checkout/shipping/flat_rate_spec.rb +46 -0
- data/spec/google-checkout/shipping/merchant_calculated_spec.rb +70 -0
- data/spec/google-checkout/shipping/pickup_spec.rb +22 -0
- data/spec/google-checkout_spec.rb +15 -0
- data/spec/spec_helper.rb +47 -0
- data/support/cacert.pem +7815 -0
- metadata +145 -0
@@ -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,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,94 @@
|
|
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
|
+
<contact-name>John Smith</contact-name>
|
7
|
+
<email>johnsmith@example.com</email>
|
8
|
+
<address1>10 Example Road</address1>
|
9
|
+
<city>Sampleville</city>
|
10
|
+
<region>CA</region>
|
11
|
+
<postal-code>94141</postal-code>
|
12
|
+
<country-code>US</country-code>
|
13
|
+
<phone>5555551234</phone>
|
14
|
+
<structured-name>
|
15
|
+
<first-name>John</first-name>
|
16
|
+
<last-name>Smith</last-name>
|
17
|
+
</structured-name>
|
18
|
+
</buyer-shipping-address>
|
19
|
+
<buyer-billing-address>
|
20
|
+
<contact-name>Bill Hu</contact-name>
|
21
|
+
<email>billhu@example.com</email>
|
22
|
+
<address1>99 Credit Lane</address1>
|
23
|
+
<city>Mountain View</city>
|
24
|
+
<region>CA</region>
|
25
|
+
<postal-code>94043</postal-code>
|
26
|
+
<country-code>US</country-code>
|
27
|
+
<phone>5555557890</phone>
|
28
|
+
<structured-name>
|
29
|
+
<first-name>Bill</first-name>
|
30
|
+
<last-name>Hu</last-name>
|
31
|
+
</structured-name>
|
32
|
+
</buyer-billing-address>
|
33
|
+
<buyer-id>294873009217523</buyer-id>
|
34
|
+
<fulfillment-order-state>NEW</fulfillment-order-state>
|
35
|
+
<financial-order-state>REVIEWING</financial-order-state>
|
36
|
+
|
37
|
+
<shopping-cart>
|
38
|
+
<cart-expiration>
|
39
|
+
<good-until-date>2007-12-31T23:59:59-05:00</good-until-date>
|
40
|
+
</cart-expiration>
|
41
|
+
<items>
|
42
|
+
<item>
|
43
|
+
<merchant-item-id>GGLAA1453</merchant-item-id>
|
44
|
+
<item-name>Dry Food Pack</item-name>
|
45
|
+
<item-description>One pack of nutritious dried food for emergencies.</item-description>
|
46
|
+
<quantity>1</quantity>
|
47
|
+
<tax-table-selector>food</tax-table-selector>
|
48
|
+
<unit-price currency="USD">4.99</unit-price>
|
49
|
+
</item>
|
50
|
+
<item>
|
51
|
+
<merchant-item-id>MGS2GBMP3</merchant-item-id>
|
52
|
+
<item-name>Megasound 2GB MP3 Player</item-name>
|
53
|
+
<item-description>This portable MP3 player stores 500 songs.</item-description>
|
54
|
+
<quantity>1</quantity>
|
55
|
+
<unit-price currency="USD">179.99</unit-price>
|
56
|
+
<merchant-private-item-data>
|
57
|
+
<merchant-product-id>1234567890</merchant-product-id>
|
58
|
+
</merchant-private-item-data>
|
59
|
+
</item>
|
60
|
+
</items>
|
61
|
+
<merchant-private-data>
|
62
|
+
<peepcode-order-number>1234-5678-9012</peepcode-order-number>
|
63
|
+
</merchant-private-data>
|
64
|
+
</shopping-cart>
|
65
|
+
<order-adjustment>
|
66
|
+
<merchant-calculation-successful>true</merchant-calculation-successful>
|
67
|
+
<merchant-codes>
|
68
|
+
<coupon-adjustment>
|
69
|
+
<applied-amount currency="USD">5.00</applied-amount>
|
70
|
+
<code>FirstVisitCoupon</code>
|
71
|
+
<calculated-amount currency="USD">5.00</calculated-amount>
|
72
|
+
<message>You saved $5.00 for your first visit!</message>
|
73
|
+
</coupon-adjustment>
|
74
|
+
<gift-certificate-adjustment>
|
75
|
+
<applied-amount currency="USD">10.00</applied-amount>
|
76
|
+
<code>GiftCert12345</code>
|
77
|
+
<calculated-amount currency="USD">10.00</calculated-amount>
|
78
|
+
<message>You saved $10.00 with this gift certificate!</message>
|
79
|
+
</gift-certificate-adjustment>
|
80
|
+
</merchant-codes>
|
81
|
+
<total-tax currency="USD">0.0</total-tax>
|
82
|
+
<shipping>
|
83
|
+
<merchant-calculated-shipping-adjustment>
|
84
|
+
<shipping-name>SuperShip</shipping-name>
|
85
|
+
<shipping-cost currency="USD">9.95</shipping-cost>
|
86
|
+
</merchant-calculated-shipping-adjustment>
|
87
|
+
</shipping>
|
88
|
+
</order-adjustment>
|
89
|
+
<order-total currency="USD">190.98</order-total>
|
90
|
+
<buyer-marketing-preferences>
|
91
|
+
<email-allowed>false</email-allowed>
|
92
|
+
</buyer-marketing-preferences>
|
93
|
+
<timestamp>2006-05-03T17:32:11</timestamp>
|
94
|
+
</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,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
|
@@ -0,0 +1,216 @@
|
|
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
|
10
|
+
|
11
|
+
describe GoogleCheckout, "Command class" do
|
12
|
+
|
13
|
+
it "should read SSL certs" do
|
14
|
+
GoogleCheckout::Command.x509_store.should be_kind_of(OpenSSL::X509::Store)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe GoogleCheckout, "Command instance" do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@command = GoogleCheckout::Command.new("my_id", "my_key")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should generate sandbox url" do
|
26
|
+
GoogleCheckout.use_sandbox
|
27
|
+
@command.url.should match(/sandbox/)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should generate production url" do
|
31
|
+
GoogleCheckout.use_production
|
32
|
+
@command.url.should match(/checkout\.google\.com/)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe GoogleCheckout, "Charge Order" do
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
@order = GoogleCheckout::ChargeOrder.new("my_id", "my_key", "1234567890")
|
41
|
+
GoogleCheckout.use_sandbox
|
42
|
+
@order.amount = 123.45
|
43
|
+
end
|
44
|
+
|
45
|
+
it_should_behave_like "basic command"
|
46
|
+
|
47
|
+
it "should retrieve order number" do
|
48
|
+
@order.google_order_number.should == '1234567890'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should get merchant_id" do
|
52
|
+
@order.merchant_id.should == 'my_id'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should get merchant_key" do
|
56
|
+
@order.merchant_key.should == 'my_key'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should generate XML" do
|
60
|
+
@order.to_xml.should match(/amount currency="USD"/)
|
61
|
+
@order.to_xml.should match(/123\.45<\/amount>/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should post request to Google successfully" do
|
65
|
+
# :null_object means eat all other methods and return self
|
66
|
+
net_http = mock("net_http", { :null_object => true })
|
67
|
+
Net::HTTP.should_receive(:new).and_return(net_http)
|
68
|
+
|
69
|
+
success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
|
70
|
+
success_response.should_receive(:body).and_return(read_xml_fixture('responses/request-received'))
|
71
|
+
net_http.should_receive(:request).and_return(success_response)
|
72
|
+
|
73
|
+
response = @order.post
|
74
|
+
response.should be_kind_of(GoogleCheckout::RequestReceived)
|
75
|
+
response.should_not be_error
|
76
|
+
response.serial_number.should == 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should post request to Google and return error" do
|
80
|
+
# :null_object means eat all other methods and return self
|
81
|
+
net_http = mock("net_http", { :null_object => true })
|
82
|
+
Net::HTTP.should_receive(:new).and_return(net_http)
|
83
|
+
|
84
|
+
# NOTE HTTP response code is irrelevant here.
|
85
|
+
error_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
|
86
|
+
error_response.should_receive(:body).and_return(read_xml_fixture('responses/error'))
|
87
|
+
net_http.should_receive(:request).and_return(error_response)
|
88
|
+
|
89
|
+
lambda { @order.post }.should raise_error(GoogleCheckout::APIError)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should post request to Google and return error charged already" do
|
93
|
+
net_http = mock("net_http", { :null_object => true })
|
94
|
+
Net::HTTP.should_receive(:new).and_return(net_http)
|
95
|
+
|
96
|
+
# NOTE HTTP response code is irrelevant here.
|
97
|
+
error_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
|
98
|
+
error_response.should_receive(:body).and_return(read_xml_fixture('responses/error-charged'))
|
99
|
+
net_http.should_receive(:request).and_return(error_response)
|
100
|
+
|
101
|
+
response = @order.post
|
102
|
+
response.message.should == 'You cannot charge an order that is already completely charged'
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe GoogleCheckout, "Add Tracking Data" do
|
108
|
+
|
109
|
+
before(:each) do
|
110
|
+
@order = GoogleCheckout::AddTrackingData.new("my_id", "my_key", "1234567890","UPS","Z5498W45987123684")
|
111
|
+
GoogleCheckout.use_sandbox
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should generate XML" do
|
115
|
+
xml = @order.to_xml
|
116
|
+
xml.should match(%r{google-order-number="1234567890"})
|
117
|
+
xml.should match(%r{<carrier>UPS</carrier>})
|
118
|
+
xml.should match(%r{<tracking-number>Z5498W45987123684</tracking-number>})
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe GoogleCheckout, "Refund Order" do
|
124
|
+
|
125
|
+
before(:each) do
|
126
|
+
@order = GoogleCheckout::RefundOrder.new("my_id", "my_key", "1234567890")
|
127
|
+
GoogleCheckout.use_sandbox
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should generate XML" do
|
131
|
+
@order.amount = '15.00'
|
132
|
+
@order.currency = 'USD'
|
133
|
+
@order.reason = 'Damaged Merchandise'
|
134
|
+
@order.comment = 'Discount for inconvenience; ship replacement item'
|
135
|
+
|
136
|
+
xml = @order.to_xml
|
137
|
+
xml.should match(%r{google-order-number="1234567890"})
|
138
|
+
xml.should match(%r{<amount currency="USD">15.00</amount>})
|
139
|
+
xml.should match(%r{<reason>Damaged Merchandise</reason>})
|
140
|
+
xml.should match(%r{<comment>Discount for inconvenience; ship replacement item</comment>})
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should generate XML with no comment" do
|
144
|
+
@order.amount = '15.00'
|
145
|
+
@order.currency = 'USD'
|
146
|
+
@order.reason = 'Damaged Merchandise'
|
147
|
+
|
148
|
+
xml = @order.to_xml
|
149
|
+
xml.should match(%r{google-order-number="1234567890"})
|
150
|
+
xml.should match(%r{<amount currency="USD">15.00</amount>})
|
151
|
+
xml.should match(%r{<reason>Damaged Merchandise</reason>})
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return an error when amount is 0" do
|
155
|
+
lambda { @order.post }.should raise_error("Refund amount must be greater than 0!")
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should return an error when reason is not longer than 0 characters" do
|
159
|
+
@order.amount = '15.00'
|
160
|
+
@order.reason = ''
|
161
|
+
lambda { @order.post }.should raise_error("Reason must be longer than 0 characters!")
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should return an error when reason length is greater than 140 characters" do
|
165
|
+
@order.amount = '15.00'
|
166
|
+
@order.reason = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vitae est dui, at aliquam ligula. Ut imperdiet, justo eleifend ultricies nullam.'
|
167
|
+
lambda { @order.post }.should raise_error("Reason cannot be greater than 140 characters!")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should return an error when comment length is greater than 140 characters" do
|
171
|
+
@order.amount = '15.00'
|
172
|
+
@order.reason = 'Refund'
|
173
|
+
@order.comment = 'Sed tincidunt auctor feugiat. Nam ut enim ligula, vel scelerisque velit. Nulla eu eros nibh. Nullam sit amet sapien a leo sagittis cras amet.'
|
174
|
+
lambda { @order.post }.should raise_error("Comment cannot be greater than 140 characters!")
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe GoogleCheckout, "Checkout API Request (with Cart)" do
|
180
|
+
|
181
|
+
it "should use HTTP Basic Auth"
|
182
|
+
|
183
|
+
it "should use proper content type"
|
184
|
+
|
185
|
+
it "should use proper accept type"
|
186
|
+
|
187
|
+
it "should report success of request"
|
188
|
+
|
189
|
+
it "should report error and error message"
|
190
|
+
|
191
|
+
it "should return redirect url"
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
describe GoogleCheckout, "Send Buyer Email" do
|
197
|
+
|
198
|
+
before(:each) do
|
199
|
+
@command = GoogleCheckout::SendBuyerMessage.new("my_id", "my_key", "1234567890", "Thanks for the order!")
|
200
|
+
end
|
201
|
+
|
202
|
+
# <send-buyer-message xmlns="http://checkout.google.com/schema/2"
|
203
|
+
# google-order-number="841171949013218">
|
204
|
+
# <message>Due to high volume, your order will ship
|
205
|
+
# next week. Thank you for your patience.</message>
|
206
|
+
# <send-email>true</send-email>
|
207
|
+
# </send-buyer-message>
|
208
|
+
|
209
|
+
it "should post email to the buyer" do
|
210
|
+
xml = @command.to_xml
|
211
|
+
xml.should match(%r{google-order-number="1234567890"})
|
212
|
+
xml.should match(%r{<message>Thanks for the order!</message>})
|
213
|
+
xml.should match(%r{<send-email>true</send-email>})
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Geography::Postal do
|
4
|
+
before(:each) do
|
5
|
+
@area = GoogleCheckout::Geography::Postal.new('US')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should generate the postal area tag' do
|
9
|
+
@area.to_xml.should match(%r{<postal-area>.*</postal-area>})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should include the country in the generated xml' do
|
13
|
+
@area.country = 'CA'
|
14
|
+
@area.to_xml.should match(%r{<country-code>CA</country-code>})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not include the postal pattern by default' do
|
18
|
+
@area.to_xml.should_not match(%r{<postal-code-pattern>})
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should include the postal pattern when set' do
|
22
|
+
@area.postal_pattern = '53*'
|
23
|
+
@area.to_xml.should match(%r{<postal-code-pattern>53\*</postal-code-pattern>})
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Geography::UsCountry do
|
4
|
+
before(:each) do
|
5
|
+
@area = GoogleCheckout::Geography::UsCountry.new(:all)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should generate the us country area tag with the ALL region' do
|
9
|
+
@area.to_xml.should match(%r{<us-country-area country-area="ALL"/>})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should generate the us country area tag with the CONTINENTAL_48 region' do
|
13
|
+
@area.region = :continental_48
|
14
|
+
@area.to_xml.should match(%r{<us-country-area country-area="CONTINENTAL_48"/>})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should generate the us country area tag with the FULL_50_STATES region' do
|
18
|
+
@area.region = :full_50_states
|
19
|
+
@area.to_xml.should match(%r{<us-country-area country-area="FULL_50_STATES"/>})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should not allow invalid regions' do
|
23
|
+
lambda {GoogleCheckout::Geography::UsCountry.new(:my_house).to_xml}.should raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Geography::UsState do
|
4
|
+
before(:each) do
|
5
|
+
@area = GoogleCheckout::Geography::UsState.new('WI')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should include the state' do
|
9
|
+
@area.to_xml.should match(%r{<us-state-area><state>WI</state></us-state-area>})
|
10
|
+
end
|
11
|
+
end
|