7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/controllers/google_checkout_notification_controller.rb', line 7
def create
frontend = get_google_checkout_frontend
frontend.tax_table_factory = TaxTableFactory.new
handler = frontend.create_notification_handler
begin
notification = handler.handle(request.raw_post) puts "GoogleCheckoutNotification: #{notification.inspect}"
if notification.is_a?(Google4R::Checkout::NewOrderNotification)
@order = Order.find_by_id(params[:new_order_notification][:shopping_cart][:merchant_private_data][:order_number].strip.to_i)
unless @order.completed?
@order.user_id = current_user.try(:id)
@order.email = notification.buyer_shipping_address.email || "[email protected]"
@order.ip_address = request.env['REMOTE_ADDR'] if @order.respond_to?('ip_address=')
@order.adjustment_total = notification.order_adjustment.adjustment_total.cents.to_f / 100
@order.buyer_id = notification.buyer_id
@order.financial_order_state = notification.financial_order_state
@order.google_order_number = notification.google_order_number
@order.gateway = "Google Checkout"
new_billing_address =
create_spree_address_from_google_address(notification.buyer_billing_address)
@order['bill_address_id'] = new_billing_address.id
new_shipping_address =
create_spree_address_from_google_address(notification.buyer_shipping_address)
@order['ship_address_id'] = new_shipping_address.id
ship_method = ShippingMethod.find_by_name(notification.order_adjustment.shipping.name)
@order.shipping_method = ship_method
@order.save
@order.next while @order.errors.blank? && @order.state != "complete"
end
render :text => 'proccess Google4R::Checkout::NewOrderNotification' and return
end
if notification.is_a?(Google4R::Checkout::ChargeAmountNotification)
@order = Order.find_by_google_order_number(notification.google_order_number)
payment = Payment.new(:amount => notification.latest_charge_amount, :payment_method_id => Billing::GoogleCheckout.current.id)
payment.order = @order
payment.save
payment.started_processing
payment.complete
render :text => 'proccess Google4R::Checkout::ChargeAmountNotification' and return
end
rescue Google4R::Checkout::UnknownNotificationType => e
render :text => 'ignoring unknown notification type', :status => 200 and return
end
end
|