Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2011 20:19
Show Gist options
  • Save anonymous/1337667 to your computer and use it in GitHub Desktop.
Save anonymous/1337667 to your computer and use it in GitHub Desktop.
get_file example
def getapk
if params[:tx] && !params[:tx].blank?
@tx = params[:tx]
# c = Curl::Easy.http_post('https://www.sandbox.paypal.com/cgi-bin/webscr',
# Curl::PostField.content('cmd', '_notify-synch'),
# Curl::PostField.content('tx', @tx),
# Curl::PostField.content('at', 'RQHRFNo3aCvvifPUqR97zWyfngx4RkYv7CI4hQknF2YQH4CjPN07qAaRvdi'),
# Curl::PostField.content('submit', 'PDT'))
# c.verbose = 'True'
# c.perform
# result = c.body_str
# puts result
# @results=result
# Test Result String
result = "SUCCESS mc_gross=9.99 protection_eligibility=Ineligible payer_id=EW4ET4DZFZV8A tax=0.00 payment_date=08%3A39%3A23+Oct+12%2C+2011+PDT payment_status=Pending charset=windows-1252 first_name=Test mc_fee=0.59 custom= payer_status=verified business=ross_1318278699_biz%40triplingo.com quantity=1 payer_email=ross_1318278753_per%40triplingo.com txn_id=5F068167W5498491A payment_type=instant btn_id=2146086 last_name=User receiver_email=ross_1318278699_biz%40triplingo.com payment_fee=0.59 shipping_discount=0.00 insurance_amount=0.00 receiver_id=4MP78DRFQW2DN pending_reason=paymentreview txn_type=web_accept item_name=TripLingo+France+French discount=0.00 mc_currency=USD item_number=FRENFRA residence_country=US handling_amount=0.00 shipping_method=Default transaction_subject=TripLingo+France+French payment_gross=9.99 shipping=0.00"
result_b = result.split
puts result_b
paypalResponse = result_b[0]
if paypalResponse == 'SUCCESS'
firstName = result_b[8].split('=')
txId = result_b[15].split('=')
itemNumber = result_b[29].split('=')
itemName = result_b[33].split('=')
@email = result_b[14].split('=')
@name = firstName[1]
@txId = txId[1]
@itemNumber = itemNumber[1]
@itemName = itemName[1].gsub("+", " ")
requestedfile = Rails.root.join('downloads') + (itemNumber[1] + '.apkz')
if File.exists?(requestedfile)
send_file(requestedfile, :type=>"application/zip", :disposition => "inline")
else
flash[:error] = 'Missing APK file'
@name = 'Missing APK file'
redirect_to '/pperror'
end
UserMailer.purchase_email(@name, @email, @txId, @itemName, @code).deliver
else
flash[:error] = result
redirect_to '/pperror'
return
end
else
flash[:error] = 'no Transaction ID'
@name = 'Missing transaction ID'
redirect_to '/pperror'
return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment