-
-
Save sradu/a563dd497101929782c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A rails controller method that opens | |
# the Two Tap Checkout interface with a product from NastyGal. | |
require 'semantics3' | |
# Open a popup or an iframe pointing to this action. | |
# It will pick a random product and redirect to the | |
# checkout interface. | |
def buy_nastygal_product | |
## | |
## Semantics | |
## | |
SEM_API_KEY = '#' | |
SEM_API_SECRET = '#' | |
# Set up a client to talk to the Semantics3 API | |
sem3 = Semantics3::Products.new(SEM_API_KEY, SEM_API_SECRET) | |
# Search through the nastygal catalogue and pick one random product. | |
sem3.products_field('site', 'nastygal.com') | |
products = sem3.get_products | |
a_product = products['results'][0] | |
## | |
## Two Tap | |
## | |
# Using our public token we can start a checkout interface. | |
TT_PUBLIC_TOKEN = '#' | |
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'] | |
redirect_to twotap_checkout_url | |
end | |
# This is called when the user presses confirm order. | |
def my_confirm_callback | |
if params[:purchase_id].blank? | |
render :nothing => true | |
return | |
end | |
# Check that order is valid | |
# | |
# .... | |
# | |
api_call = "https://api.twotap.com/v1.0/purchase_confirm?private_token=#{TT_PRIVATE_TOKEN}" | |
response = HTTParty.post(api_call, :body => | |
{ :purchase_id => params[:purchase_id], :test_mode => params[:test_mode] } | |
) | |
render :json => response.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment