The following code gives me an error in command at:
on processData pData -- pData is one order.
The code is attached to a button:
Code: Select all
on mouseUp
-- check the global connection ID to make sure we have a database connection
global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if
put "" into field "fldData"
put "" into field "fldSub"
global Totals
-- construct the SQL (this selects all the data from the specified table)
put "gccas38_paypal" into tTableName -- set this to the name of a table in your database
put "SELECT * FROM " & tTableName into tSQL
-- query the database
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
-- check the result and display the data or an error message
if item 1 of tData = "revdberr" then
answer error "There was a problem querying the database:" & cr & tData
else
--Old Code
--put urlDecode(s) into tData
--split tData by "&" and "="
--Zero stuff out
put "0.00" into Totals
put "0" into tTotalNumItems
put 1 into lineCount
--Main Loop
repeat for each line L in tData -- tData is all 248 orders, one per line
processData L -- "L" will contain the data block for one order; i.e., one Paypal line
end repeat
--Function to process data
on processData pData -- pData is one order
put urlEncode(pData) into pData
split pData by "&" and "="
repeat for each key k in pData -- loop through each key
if pData["order_id"] contains "PENDING" then next repeat -- ignore this one
-- Process Data
put pData["mc_gross"] into tPrice
put pData["first_name"] && s["last_name"] into tName -- full name
put pData["tax"] into tSalesTax
put pData["payment_date"] into tSaleDate
put pData["num_cart_items"] into tNumItems
-- last item is shipping - get rid of it
put tNumItems - 1 into tNumItems
repeat with tVarNum = 1 to tNumItems
put pData["item_name" & tVarNum] into tThingBought
put tThingBought into line lineCount of field "fldData"
put pData["quantity" & tVarNum] into tTotalNumItems
if tThingBought = "Gold Short Sleeve Polo Shirt Size Kids 8" then
put "1.80" * tTotalNumItems into tPayoutAmt[tVarNum]
end if
if tThingBought = "Maroon Short Sleeve Polo Shirt Size Kids 12" then
put "1.80" * tTotalNumItems into tPayoutAmt[tVarNum]
end if
if tThingBought = "Heather Gray Polo Shirt Short Sleeve Size Kids 14" then
put "1.80" * tTotalNumItems into tPayoutAmt[tVarNum]
end if
if tThingBought = "Royal Blue Short Sleeve Polo Shirt Size Kids 7" then
put "1.80" * tTotalNumItems into tPayoutAmt[tVarNum]
end if
if tThingBought = "Royal Blue School Spirit Shirt Size Kids Medium" then
put "4.00" * tTotalNumItems into tPayoutAmt[tVarNum]
end if
if tThingBought = "Gold School Spirit Shirt Size Kids Medium" then
put "4.00" * tTotalNumItems into tPayoutAmt[tVarNum]
end if
put tPayoutAmt[tVarNum] into line lineCount of field "fldSub"
put tTotalNumItems into line lineCount of field "fldQuantity"
add tPayoutAmt[tVarNum] to field "fldPayoutAmount"
end repeat
add tSalesTax to field "fldSalesTaxToDate"
add 1 to lineCount
--put tSaleDate into field "fldOrderDate"
--put tThingBought into line 1 of field "fldData"
--put tSaleDate into line 2 of field "fldData"
--put tSalesTax into line 3 of field "fldData"
end repeat
end processData
end if
end mouseUp
If the paypal order was not completed or shows pending, failed or whatever paypal deems as NOT going through needs to be ignored.
I'm not sure if L and pData have to somehow be referenced?
On the line where I try to filter what was bought:
if tThingBought = "Gold Short Sleeve Polo Shirt Size Kids 8" then
put "1.80" * tTotalNumItems into tPayoutAmt[tVarNum]
end if
It's a substitution table - there will be tons of these (4 product types with 4 color choices and up to 10 size choices per item). I put the payout
amount in a separate multi-line field. I need to list each item bought, its quantity, its payout and a total tally of all payouts in one value and all
sales tax in one value.
Here is a sample of paypal code:
Code: Select all
cmd=_notify-validate&mc_gross=104.23&protection_eligibility=Eligible&address_status=confirmed&item_number1=&tax=6.23&item_number2=&payer_id=privateID&item_number3=&address_street=PrivateAddr&item_number4=&payment_date=14%3A26%3A57+Jul+29%2C+2014+PDT&payment_status=Completed&charset=windows-1252&address_zip=Zippy&mc_shipping=0.00&mc_handling=0.00&first_name=Fname&mc_fee=3.32&address_country_code=US&address_name=Nope¬ify_version=3.8&custom=71_LongNum&payer_status=unverified&business=clientEmail&address_country=United+States&num_cart_items=4&mc_handling1=0.00&mc_handling2=0.00&mc_handling3=0.00&address_city=City&mc_handling4=0.00&verify_sign=PrivateNum&payer_email=Privateemail&mc_shipping1=0.00&mc_shipping2=0.00&mc_shipping3=0.00&mc_shipping4=0.00&txn_id=TaxID&payment_type=instant&last_name=Nope&address_state=FL&item_name1=Royal+Blue+Long+Sleeve+Polo+Shirt+Size+Kids+XL&receiver_email=ClientEmail&item_name2=Royal+Blue+Short+Sleeve+Polo+Shirt+Size+Kids+20&payment_fee=3.32&item_name3=Gold+Short+Sleeve+Polo+Shirt+Size+Kids+20&item_name4=shipping&quantity1=1&quantity2=3&receiver_id=Private&quantity3=1&txn_type=cart&quantity4=1&mc_gross_1=21.00&mc_currency=USD&mc_gross_2=51.00&mc_gross_3=17.00&residence_country=US&mc_gross_4=9.00&transaction_subject=PrivateNum&payment_gross=104.23&ipn_track_id=Nope-a-HTTP/1.1 200 OK
Server: Apache
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=14400
Strict-Transport-Security: max-age=14400
; charset=UTF-8
DC: slc-b-origin-www-2.paypal.com
Date: Tue, 29 Jul 2014 21:27:03 GMT
Content-Length: 8
Connection: close
Set-Cookie: cwrClyrK4LoCV1fydGbAxiNL6iG=a49RcAaudnrdjiRcaJbzGODaIVimNR9dnjLZlo3cWbbF6RWsokQil0hyVakCYLr_gWuYe0j4HRTkE6uHAfLvC8R2HOuy_03VDG3Qloi_PZj0_23Qr_CreJ9VVJI3lirv76p-uiXBxgO7DT7plGCrCx2xu4TIS01uwP46BbefeksTUKYuzfhFYg5qy79RabuWuSRxARTW3pimRGR1Z1C9fpuNC7XKmDEzjikvuaoJUp1zGnRC62YfzgfM7AOU7qy59AmFoOSTfMIRRR6j92vSKvirqzNn5BErwfVUa9jcthmw_Hwqwy-SAvB0l72X5ppHzYC-uPxySF-bSn6cI2bYxWV1X9MNPQGHXGStYTXNleD09UPJhGjlf6ubpm6RQ98SyC-Ec2UV3pVohMv-TzPPSFOkupWQaeVnczw1dm; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Fri, 26-Jul-2024 21:27:03 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Thu, 28-Jul-2016 21:27:03 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.74.8.137.1406669223448719; path=/; expires=Thu, 21-Jul-44 21:27:03 GMT
Set-Cookie: X-PP-SILOVER=name%3DLIVE6.WEB.1%26silo_version%3D880%26app%3Dslingshot%26TIME%3D2802964563; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
Set-Cookie: Apache=10.74.8.53.1406669223439437; path=/; expires=Thu, 21-Jul-44 21:27:03 GMT
Set-Cookie: AKDC=slc-b-origin-www-2.paypal.com; expires=Tue, 29-Jul-2014 21:57:03 GMT; path=/; secure
VERIFIED
Everything from Server: Apache and below can be ignored. I changed private info to nonsense text.
Can you help me as to why the code gives me an error on compile?
Thank you.
Mike