Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brennandunn
Created April 24, 2014 21:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brennandunn/11270180 to your computer and use it in GitHub Desktop.
Save brennandunn/11270180 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'infusionsoft'
require 'logger'
Infusionsoft.configure do |config|
config.api_url = 'XXXX.infusionsoft.com'
config.api_key = 'XXXXXXXXXXXXXXX'
config.api_logger = Logger.new("./infusionsoft_api.log")
end
# Stuff that comes over...
# → order_number
# → seller_id
# → product_id
# → product_permalink
# → email (the email of the buyer)
# → full_name (if present, the name of the buyer)
# → price (the price paid, in USD cents)
# → variants (if present, an array of each variant choice: ['blue', 'small'])
# → offer_code (if present)
# → test (if you are buying your own product, for testing purposes)
# → custom_fields (if present, a dictionary {'name' : 'john smith', 'spouse name' : 'jane smith'})
# → shipping_information (if present, a dictionary)
# → is_recurring_charge (if relevant, a boolean)
# → is_preorder_authorization (if relevant, a boolean)
# → revenue_share_amount_cents (if relevant, in USD cents)
def get_product_tag_id(product_id)
{
dyfr: [111],
dyfrcomplete: [111, 295]
}[product_id.to_sym]
end
def get_affiliate(offer_code)
return 0 unless offer_code
{
offer_code_1: <is_affiliate_id>,
offer_code_2: <is_affiliate_id>
}[offer_code.to_sym]
end
post '/hook' do
product_id = params[:permalink]
product_name = params[:product_name]
order_num = params[:order_number]
offer_code = params[:offer_code]
price = params[:price].to_i / 100
email = params[:email]
first_name, last_name = params[:full_name].split(' ')
contact = {
:Email => email,
:FirstName => first_name,
:LastName => last_name
}
icontact_id = Infusionsoft.contact_add_with_dup_check contact, "Email"
Infusionsoft.email_optin email, "Gumroad purchase"
tags = get_product_tag_id(product_id)
tags.each do |tag|
Infusionsoft.contact_add_to_group icontact_id, tag
end
invoice_id = Infusionsoft.invoice_create_blank_order icontact_id, "Order ##{order_num}: '#{product_name}'", Time.now, 0, get_affiliate(offer_code)
Infusionsoft.invoice_add_order_item invoice_id, 0, 4, price.to_f, 1, product_name, ""
Infusionsoft.invoice_add_manual_payment invoice_id, price.to_f, Time.now, "Gumroad", "Order #{order_num}", false
end
@Rojo143
Copy link

Rojo143 commented Jun 15, 2018

Hi brennandunn,

Can you explain to me what is the function of this code? Hope to have ASAP answer.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment