Google Checkout with Ruby on Rails

Post on 29-Jun-2015

2,975 views 4 download

Tags:

transcript

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

USA/UK only!

Merchant Accounts

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

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

• => Merchant ID, Merchant Key

APIs

• HTML and XML APIs• Notification APIs

• Example uses HTML API via HTTParty

Very(!) simple example

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

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

Create Purchase

Notifications• Register for Notifications:

(need SSH tunnel for local development)

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

A lot more can be done!

Q&A