Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added donation support #8

Merged
merged 3 commits into from
May 31, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
=google4r-checkout Changelog

== 1.1.2 (2012-05-24)

* Added support for donation processing

== 1.1.1 (2011-12-16)

* Bug fix for subscriptions not being processed, contributed by Larry Salibra
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

google4r/checkout is a library to access the Google Checkout API.

It currently supports version 2.3 of the API and subscription beta API.

### License

google4r itself is distributed under an MIT style license.
Expand Down
6 changes: 3 additions & 3 deletions google4r-checkout.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Gem::Specification.new do |gem|
gem.summary = "Full-featured Google Checkout library for Ruby"
gem.description = <<-EOF
google4r-checkout is a lightweight, framework-agnostic Ruby library to access the Google Checkout service and implement
notification handlers. It exposes object-oriented wrappers for all of Google Checkout's API commands and notifications.
notification handlers. It exposes object-oriented wrappers for all of Google Checkout's API commands and notifications.
EOF
gem.version = "1.1.1"
gem.authors = ["Tony Chan", "Dan Dukeson", "Nat Budin", "George Palmer", "Daniel Higham", "Johnathan Niziol", "Chris Parrish", "Larry Salibra"]
gem.version = "1.1.2"
gem.authors = ["Tony Chan", "Dan Dukeson", "Nat Budin", "George Palmer", "Daniel Higham", "Johnathan Niziol", "Chris Parrish", "Larry Salibra", "Paul Schreiber"]
gem.email = "natbudin@gmail.com"
gem.homepage = "http://github.com/nbudin/google4r-checkout"

Expand Down
28 changes: 21 additions & 7 deletions lib/google4r/checkout/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ class Command
# is to be put in via String#%.
PRODUCTION_URL_PREFIX = 'https://checkout.google.com/'

# Orders
CHECKOUT_API_URL = 'api/checkout/v2/merchantCheckout/Merchant/%s'

ORDER_PROCESSING_API_URL = 'api/checkout/v2/request/Merchant/%s'

ORDER_REPORT_API_URL = 'api/checkout/v2/reports/Merchant/%s'

# Donations
DONATE_CHECKOUT_API_URL = 'api/checkout/v2/merchantCheckout/Donations/%s'
DONATE_ORDER_PROCESSING_API_URL = 'api/checkout/v2/request/Donations/%s'
DONATE_ORDER_REPORT_API_URL = 'api/checkout/v2/reports/Donations/%s'


# The Frontent class that was used to create this CheckoutCommand and whose
# configuration will be used.
Expand Down Expand Up @@ -91,12 +95,22 @@ def send_to_google_checkout
PRODUCTION_URL_PREFIX
end
url_str +=
if self.class == CheckoutCommand then
CHECKOUT_API_URL
elsif self.class == OrderReportCommand || self.class == NotificationHistoryRequestCommand then
ORDER_REPORT_API_URL
if frontend.configuration[:purchase_type] == Google4R::Checkout::Frontend::PURCHASE_TYPE_DONATION
if self.class == CheckoutCommand then
DONATE_CHECKOUT_API_URL
elsif self.class == OrderReportCommand || self.class == NotificationHistoryRequestCommand then
DONATE_ORDER_REPORT_API_URL
else
DONATE_ORDER_PROCESSING_API_URL
end
else
ORDER_PROCESSING_API_URL
if self.class == CheckoutCommand then
CHECKOUT_API_URL
elsif self.class == OrderReportCommand || self.class == NotificationHistoryRequestCommand then
ORDER_REPORT_API_URL
else
ORDER_PROCESSING_API_URL
end
end
url_str = url_str % frontend.configuration[:merchant_id]

Expand Down
17 changes: 17 additions & 0 deletions lib/google4r/checkout/frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ module Checkout #:nodoc:
#
# frontend = Google4R::Checkout::Frontend.new(configuration)
#
# === Donations
#
# If you are processing orders for a Google-verified 501(c)(3) or 510(c)(6) nonprofit,
# you can collect donations instead of orders. To do so, specify the :purchase_type option
# as Google4R::Checkout::Frontend::PURCHASE_TYPE_DONATION.
#
# configuration = { :merchant_id => '123456789', :merchant_key => '12345abcd',
# :purchase_type => Google4R::Checkout::Frontend::PURCHASE_TYPE_DONATION }
#
# frontend = Google4R::Checkout::Frontend.new(configuration)
#
# == Tax Table Factory
#
# You have to set the tax_table_factory attribute of every Frontend object before you
Expand Down Expand Up @@ -74,6 +85,9 @@ module Checkout #:nodoc:
# # ...
# handler = frontend.create_notification_handler
class Frontend
PURCHASE_TYPE_DONATION = 10
PURCHASE_TYPE_ORDER = 20

# The configuration for this Frontend class. It will be used by all classes created
# by this Frontend instance (Hash).
attr_reader :configuration
Expand All @@ -88,6 +102,9 @@ def initialize(configuration)
raise "Missing configuration setting: merchant_id" if configuration[:merchant_id].nil?
raise "Missing configuration setting: merchant_key" if configuration[:merchant_key].nil?
raise "Missing configuration setting: use_sandbox" if configuration[:use_sandbox].nil?
raise "Invalid configuration setting: purchase_type" unless[PURCHASE_TYPE_DONATION, PURCHASE_TYPE_ORDER, nil].include?(configuration[:purchase_type])

configuration[:purchase_type] = PURCHASE_TYPE_ORDER if configuration[:purchase_type].nil?

@configuration = configuration.dup.freeze
end
Expand Down