5. APIs
• HTML and XML APIs
• Notification APIs
• Example uses HTML API via HTTParty
6. Very(!) simple example
• Create Purchase with Google Checkout
• When Google Checkout confirms the
payment handle the Purchase in the app
7. Create Purchase
• Post an HTML Form to Google
• or create via HTML API:
post("/requestForm/Merchant/#{merchant_id}", :body => {
:_type => 'checkout-shopping-cart',
:'shopping-cart.items.item-1.item-name' => product.name,
:'shopping-cart.items.item-1.item-description' => product.description,
:'shopping-cart.items.item-1.quantity' => 1,
:'shopping-cart.items.item-1.unit-price' => price,
:'shopping-cart.items.item-1.unit-price.currency' => currency
})
• => returns serial-number to later identify
the purchase
10. Complete Purchase
• State Change Notifications:
def callback
type = params[:'_type']
serial_number = params[:'serial-number']
if type == 'order-state-change-notification'
order_state = params[:'new-financial-order-state']
purchase = GoogleCheckoutPurchase.find_by_serial_number(serial_number)
case order_state.try(:downcase)
when 'charged'
purchase.book!
when 'payment_declined', 'cancelled', 'cancelled_by_google'
purchase.fail!
end
end
render :text => "serial-number=#{serial_number}", :status => :ok
rescue
head :internal_server_error
end