\n \n <\/td>\n | # A rails controller method that opens<\/td>\n <\/tr>\n |
\n <\/td>\n | # the Two Tap Checkout interface with a product from NastyGal.<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | require 'semantics3'<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | # Open a popup or an iframe pointing to this action.<\/td>\n <\/tr>\n |
\n <\/td>\n | # It will pick a random product and redirect to the<\/td>\n <\/tr>\n |
\n <\/td>\n | # checkout interface.<\/td>\n <\/tr>\n |
\n <\/td>\n | def buy_nastygal_product<\/td>\n <\/tr>\n |
\n <\/td>\n | ##<\/td>\n <\/tr>\n |
\n <\/td>\n | ## Semantics<\/td>\n <\/tr>\n |
\n <\/td>\n | ##<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | SEM_API_KEY = '#'<\/td>\n <\/tr>\n |
\n <\/td>\n | SEM_API_SECRET = '#'<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | # Set up a client to talk to the Semantics3 API<\/td>\n <\/tr>\n |
\n <\/td>\n | sem3 = Semantics3::Products.new(SEM_API_KEY, SEM_API_SECRET)<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | # Search through the nastygal catalogue and pick one random product.<\/td>\n <\/tr>\n |
\n <\/td>\n | sem3.products_field('site', 'nastygal.com')<\/td>\n <\/tr>\n |
\n <\/td>\n | products = sem3.get_products<\/td>\n <\/tr>\n |
\n <\/td>\n | a_product = products['results'][0]<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | ##<\/td>\n <\/tr>\n |
\n <\/td>\n | ## Two Tap <\/td>\n <\/tr>\n |
\n <\/td>\n | ##<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | # Using our public token we can start a checkout interface.<\/td>\n <\/tr>\n |
\n <\/td>\n | TT_PUBLIC_TOKEN = '#'<\/td>\n <\/tr>\n |
\n <\/td>\n | twotap_checkout_url = "https://checkout.twotap.com/?public_token#{TT_PUBLIC_TOKEN}&unique_token=#{rand(99999)}&callback_url=http://MY_SERVER/my_confirm_callback&product=" + a_product['url']<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | redirect_to twotap_checkout_url<\/td>\n <\/tr>\n |
\n <\/td>\n | end<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | # This is called when the user presses confirm order.<\/td>\n <\/tr>\n |
\n <\/td>\n | def my_confirm_callback<\/td>\n <\/tr>\n |
\n <\/td>\n | if params[:purchase_id].blank?<\/td>\n <\/tr>\n |
\n <\/td>\n | render :nothing => true<\/td>\n <\/tr>\n |
\n <\/td>\n | return<\/td>\n <\/tr>\n |
\n <\/td>\n | end<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | # Check that order is valid<\/td>\n <\/tr>\n |
\n <\/td>\n | #<\/td>\n <\/tr>\n |
\n <\/td>\n | # ....<\/td>\n <\/tr>\n |
\n <\/td>\n | #<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | api_call = "https://api.twotap.com/v1.0/purchase_confirm?private_token=#{TT_PRIVATE_TOKEN}"<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | response = HTTParty.post(api_call, :body => <\/td>\n <\/tr>\n |
\n <\/td>\n | { :purchase_id => params[:purchase_id], :test_mode => params[:test_mode] }<\/td>\n <\/tr>\n |
\n <\/td>\n | )<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | render :json => response.body<\/td>\n <\/tr>\n |
\n <\/td>\n | end<\/td>\n <\/tr>\n <\/table>\n<\/div>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n |