google checkout with ruby on rails

13
Google Checkout with Ruby on Rails

Upload: marco-otte-witte

Post on 29-Jun-2015

2.979 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Google Checkout with Ruby on Rails

Google Checkout with Ruby on Rails

Page 2: Google Checkout with Ruby on Rails

Software Engineer, Consultant, Trainer

http://simplabs.com

Open Source

http://github.com/marcoowhttp://github.com/simplabs

Marco Otte-Witte

Page 3: Google Checkout with Ruby on Rails

USA/UK only!

Page 4: Google Checkout with Ruby on Rails

Merchant Accounts

• Production Merchant Account https://checkout.google.com/sell

• Sandbox Merchant Accournt http://sandbox.google.com/checkout/sell

• => Merchant ID, Merchant Key

Page 5: Google Checkout with Ruby on Rails

APIs

• HTML and XML APIs• Notification APIs

• Example uses HTML API via HTTParty

Page 6: Google Checkout with Ruby on Rails

Very(!) simple example

• Create Purchase with Google Checkout• When Google Checkout confirms the payment handle the Purchase in the app

Page 7: Google Checkout with Ruby on Rails

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

Page 8: Google Checkout with Ruby on Rails

Create Purchase

Page 9: Google Checkout with Ruby on Rails

Notifications• Register for Notifications:

(need SSH tunnel for local development)

Page 10: Google Checkout with Ruby on Rails

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 => :okrescue head :internal_server_errorend

Page 11: Google Checkout with Ruby on Rails

A lot more can be done!

Page 13: Google Checkout with Ruby on Rails

Q&A