Skip to content

Commit

Permalink
checkout with analytics
Browse files Browse the repository at this point in the history
git-svn-id: http://google-checkout-ruby-sample-code.googlecode.com/svn/trunk@20 e8951a00-ae37-0410-a62f-61f35e791711
  • Loading branch information
dandukeson committed Oct 7, 2007
1 parent 55e6dab commit e0e119f
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 14 deletions.
7 changes: 7 additions & 0 deletions lib/google4r/checkout/commands.rb
Expand Up @@ -219,6 +219,13 @@ class CheckoutCommand < Command

# A Google Checkout merchant ID that identifies the eCommerce provider.
attr_accessor :platform_id

# Setting this allows Google Analytics to track purchases that use Checkout
# The value should be as set by the analytics javascript in the hidden form
# element names "analyticsdata" on the page with the checkout button.
# If left unset then the element will not be generated.
# see: http://code.google.com/apis/checkout/developer/checkout_analytics_integration.html
attr_accessor :analytics_data

# Generates the XML for this CheckoutCommand.
def to_xml
Expand Down
7 changes: 7 additions & 0 deletions lib/google4r/checkout/xml_generation.rb
Expand Up @@ -171,6 +171,13 @@ def process_command(command)
command.shipping_methods.each do |shipping_method|
self.process_shipping_method(shippings_element, shipping_method)
end

# <analytics-data>
unless command.analytics_data.nil? then
analytics_element = flow_element.add_element('analytics-data')
analytics_element.text = command.analytics_data
end

end

# adds the tax-tables to the parent xml element
Expand Down
25 changes: 12 additions & 13 deletions test/frontend_configuration.rb
@@ -1,13 +1,12 @@
# Uncomment the following line if you are using Google Checkout in Great Britain
# and adjust it if you want to test google4r-checkout against any other (future)
# Google Checkout service.

# Money.default_currency = 'GBP'

# The test configuration for the Google4R::Checkout::Frontend class.
FRONTEND_CONFIGURATION =
{
:merchant_id => '',
:merchant_key => '',
:use_sandbox => true
}
# The test configuration for the Google4R::Checkout::Frontend class.

Money.default_currency = 'GBP'

FRONTEND_CONFIGURATION =
{
:merchant_id => '344031641964896',
:merchant_key => 'z1F88L1KsENu2MJvMrv0RQ',
:use_sandbox => true,
:currency_code => 'GBP'

}
7 changes: 6 additions & 1 deletion test/unit/checkout_command_test.rb
Expand Up @@ -82,6 +82,11 @@ def test_accessors_work_correctly

@command.request_buyer_phone_number = true
assert_equal true, @command.request_buyer_phone_number

assert_nil @command.analytics_data
@command.analytics_data = 'abcd1234defgh5678ijklmn'
assert_equal 'abcd1234defgh5678ijklmn', @command.analytics_data

end

def test_create_shipping_method_works_correctly_with_block
Expand Down Expand Up @@ -117,4 +122,4 @@ def test_create_shipping_method_raises_exception_on_invalid_clazz_parameter
def test_to_xml_does_not_raise_exception
assert_nothing_raised { @command.to_xml }
end
end
end
1 change: 1 addition & 0 deletions test/unit/checkout_command_xml_generator_test.rb
Expand Up @@ -102,6 +102,7 @@ def test_check_persisting_works
@command.accept_merchant_coupons = true
@command.accept_gift_certificates = true
@command.platform_id = '1234567890'
@command.analytics_data = 'abcd1234defgh5678ijklmn'

@generator = CheckoutCommandXmlGenerator.new(@command)

Expand Down
132 changes: 132 additions & 0 deletions test/unit/risk_info_notification_test.rb
@@ -0,0 +1,132 @@
#--
# Project: google_checkout4r
# File: test/unit/risk_info_notification_test.rb
# Author: Dan Dukeson <dandukeson AT gmail.com>
# Copyright: (c) 2007 by Dan Dukeson
# License: MIT License as follows:
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++

require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
require 'google4r/checkout'

require 'test/frontend_configuration'

# Test for the class Area.
class Google4R::Checkout::RiskInformationNotificationTest < Test::Unit::TestCase

include Google4R::Checkout

def setup

@example_xml = %q{
<?xml version="1.0" encoding="UTF-8"?>
<risk-information-notification xmlns="http://checkout.google.com/schema/2" serial-number="4f5adc5b-aac5-4618-9e3b-75e60eaf29cd">
<timestamp>2007-04-30T08:03:57.000Z</timestamp>
<google-order-number>1564645586934214</google-order-number>
<risk-information>
<billing-address>
<contact-name>Mr Contact Smith</contact-name>
<company-name>ACME Products</company-name>
<email>contact_smith@example.com</email>
<phone>012345 234567</phone>
<fax>012345 345678</fax>
<address1>123 Testing Road</address1>
<address2>Test Village</address2>
<country-code>GB</country-code>
<city>Testcity</city>
<region>South Testshire</region>
<postal-code>S6 1TT</postal-code>
</billing-address>
<ip-address>123.456.123.456</ip-address>
<avs-response>Y</avs-response>
<cvn-response>M</cvn-response>
<eligible-for-protection>true</eligible-for-protection>
<partial-cc-number>6789</partial-cc-number>
<buyer-account-age>61</buyer-account-age>
</risk-information>
</risk-information-notification>
}

frontend = Frontend.new(FRONTEND_CONFIGURATION)
root_element = REXML::Document.new(@example_xml).root

@risk = RiskInformationNotification.create_from_element(root_element, frontend)

end

def test_xml_parsing_works
root = REXML::Document.new(@example_xml).root
assert_equal '4f5adc5b-aac5-4618-9e3b-75e60eaf29cd', root.attributes['serial-number']
end

def test_serial_accessor

@risk.serial_number = 'e4r'
assert_equal 'e4r', @risk.serial_number
end

def test_risk_not_nil
assert_not_nil @risk
end

def test_serial_number
assert_equal '4f5adc5b-aac5-4618-9e3b-75e60eaf29cd', @risk.serial_number
end

def test_google_order_number
assert_equal '1564645586934214', @risk.google_order_number
end

def test_eligible_protection
assert_equal true, @risk.eligible_for_protection
end

def test_buyer_billing_address
# address has its own unit tests, just check we have an address
assert @risk.buyer_billing_address
end

def test_avs_response
assert_equal 'Y', @risk.avs_response
end

def test_cvn_response
assert_equal 'M', @risk.cvn_response
end

def test_partial_card_number
assert_equal 6789, @risk.partial_card_number
end

def test_ip_address
assert_equal '123.456.123.456', @risk.ip_address
end

def test_buyer_account_age
assert_equal 61, @risk.buyer_account_age
end

def test_timestamp
assert_equal Time.parse('2007-04-30T08:03:57.000Z'), @risk.timestamp
end

end
41 changes: 41 additions & 0 deletions test/unit/shipping_method_test.rb
@@ -0,0 +1,41 @@
#--
# Project: google_checkout4r
# File: test/unit/shipping_method_test.rb
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
# Copyright: (c) 2007 by Manuel Holtgrewe
# License: MIT License as follows:
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++

require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'

require 'google4r/checkout'

require 'test/frontend_configuration'

# Test for the ShippingMethod class.
class Google4R::Checkout::ShippingMethodTest < Test::Unit::TestCase
include Google4R::Checkout

def test_shipping_method_raises_runtime_error_on_initialisation
assert_raises(RuntimeError) { ShippingMethod.new }
end
end
1 change: 1 addition & 0 deletions test/xml/test_check_persisting_works_expected.xml
Expand Up @@ -207,6 +207,7 @@
</shipping-restrictions>
</flat-rate-shipping>
</shipping-methods>
<analytics-data>abcd1234defgh5678ijklmn</analytics-data>
</merchant-checkout-flow-support>
</checkout-flow-support>
</checkout-shopping-cart>

0 comments on commit e0e119f

Please sign in to comment.