Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Google Checkout with Ruby on Rails

3,340 views

Published on

Published in: Technology, Business

Google Checkout with Ruby on Rails

  1. 1. Google Checkout with Ruby on Rails
  2. 2. Software Engineer, Consultant, Trainer http://simplabs.com Open Source http://github.com/marcoow http://github.com/simplabs Marco Otte-Witte
  3. 3. USA/UK only!
  4. 4. Merchant Accounts • Production Merchant Account https://checkout.google.com/sell • Sandbox Merchant Accournt http://sandbox.google.com/checkout/sell • => Merchant ID, Merchant Key
  5. 5. APIs • HTML and XML APIs • Notification APIs • Example uses HTML API via HTTParty
  6. 6. Very(!) simple example • Create Purchase with Google Checkout • When Google Checkout confirms the payment handle the Purchase in the app
  7. 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
  8. 8. Create Purchase
  9. 9. Notifications • Register for Notifications: (need SSH tunnel for local development)
  10. 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
  11. 11. A lot more can be done!
  12. 12. Resources • http://code.google.com/intl/de-DE/apis/checkout/ • https://rubygems.org/gems/google4r-checkout
  13. 13. Q&A

×