-
Notifications
You must be signed in to change notification settings - Fork 2
Plugin for easy enabling Google Checkout payment processing on Rails site
kelyar/accepts_gcheckout
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Google Checkout module for Rails Hi, I wrote this code like 2 years ago when started using rails. Since than many things changed and I decided that it is a good chance to register on github to clean up this library and learn new things like git and plugin generators. So I am going to rewrite this bunch of code and make a nice plugin because code is awful right now (altough it works). Below is a old README file. TODO: - remove hardcoded things - generate migrations and controllers/models with rake - TESTS!!! -------- This is simple but working library for accepting Google Checkout Orders. It can be easily integrated with any Rails application and what is even more important - can be easily improved to support features that I dont need at this moment. This code is a part of another project. I couldnt find completed solution when writing this so I decided to put the results online. Details: - sends digitally signed shopping carts (source code is cut to support USD only but it is easy to fix) - autocharging orders - saving and processing transactions via system of hooks - shipping is NOT supported as my main project just sells music online. So "shippped" status is set automatically once the order is charged INSTALL - copy files to corresponding places in your RAILS_ROOT- migrations - to db/migrate, *.rb files to lib run <b>rake db:migrate</b> or manually run migration. It will create 2 tables: one for transactions, another one - for order statuses Ensure 'net/https' library is also installed "hmac-sha" library is required to digitally sign your shopping carts. On FreeBSD you can find it in /usr/ports/security/ruby-hmac Put require "googlecheckout"a in the end of your config/environment.rb or whatever you use to include modules Put <b>include CanAcceptGoogleCheckout</b> to your sort of payment controller. You need to define 3 constants (G_LIVE, G_MERCHANTID, G_MERCHANTKEY) like it is made in sample. Remember to keep key in secret. Now it should look like this: require "#{RAILS_ROOT}/lib/can_accept_google_checkout.rb" class PaymentController < ApplicationController G_MERCHANTID = "PUT_YOUR_ID_HERE" G_MERCHANTKEY = "PUT_YOUR_KEY_HERE" G_LIVE = true include CanAcceptGoogleCheckout Go to https://google.com/checkout/sell/settings?section=Integration and enter API callback URL: it will be smth like "https://yourserver.com/YOURPAYMENTCONTROLLERHERE/g_checkout_callback", set "Callback method" to HTML and you can also set extra security flag to only post digitally signed XML shopping carts. This page also shows your Google Checkout Merchant Key in case you forgot - now put all your business logic into <b>g_charge_amount_notification</b> method of your controller that is responsible for accepting online orders. See example. def g_charge_amount_notification(opts) tr = GcheckoutTransaction.find_by_order_number(opts["google-order-number"],:include=>:user) if tr && tr.user options = { :value => opts['total-charge-amount'], :method=>"gcheckout", :data => tr[:order_number] } begin tr.user.credit_money(options) if tr.credited_at.nil? or tr.credited_at.to_i.zero? tr.update_attribute(:credited_at, Time.now) rescue end deliver(opts["google-order-number"]) # this will autoset "shipped" status end end Restart your webserver Check :g_server2server and :status method samples in payment controller You should also think about proper way to display transaction status for users that are returning from google's page. It is NOT as fast as paypal and you can not assume order is already charged when user clicks "return". We on payplay.fm made a dynamic page with ajax progress bar that shows transaction status: reviewing, charging, charged. See method action in sample payment controller called <i>status</i>. Author http://workingwithrails.com/person/6232-evgeniy-kelyarsky
About
Plugin for easy enabling Google Checkout payment processing on Rails site
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published