Skip to content

Instantly share code, notes, and snippets.

@thomasv314
Forked from anonymous/gist:1337667
Created November 3, 2011 20:31
Show Gist options
  • Save thomasv314/1337701 to your computer and use it in GitHub Desktop.
Save thomasv314/1337701 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>work!</title>
</head>
<body>
<h1>Congratulations! </h1>
<p> This has worked.</p>
<script type="text/javascript">
$(document).ready(function() {
window.open(<%= file_success_path(@itemNumber) %>);
}
</script>
def getapk
found_file = false
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("+", " ")
if File.exists?(requestedfile)
found_file = true
else
flash[:error] = 'Missing APK file'
@name = 'Missing APK '
end
UserMailer.purchase_email(@name, @email, @txId, @itemName, @code).deliver
else
flash[:error] = result
end
else
flash[:error] = 'no Transaction ID'
@name = 'Missing transaction ID'
end
if (!found_file)
redirect_to :error_path
else
render 'file_success'
end
end
# ADD A NAMED ROUTE FOR THIS PATH
# get '/dl/:item_number' => 'paypal#file_success', :as => 'file_success'
def file_success
itemNumber = params[:item_number]
send_file("#{Rails.root}/downloads/#{itemNumber}.apkz", :type=>"application/zip", :disposition => "inline")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment