Need to parse text using chunks and tokens (??)
Posted: Mon Aug 18, 2014 4:33 pm
Hello all.
I am using a MySQL Database and have been able to login and query data thus far, however, the shopping cart I am using puts everything together in massive strings.
I need to separate certain parts so that I can add them to an array of variables. The end result is to separate all the purchases from each record (there are hundreds) and figure out what they bought (like 2 gold short sleeve polo shirts, as shown below). Then, knowing what each item is worth, write a variable to that array record. For example, each gold short sleeve polo shirt = $2.00 and two were bought, so I write $4.00 into a variable. All of these same variables will later be added together to form the sum total of what is owed to the client.
These are the fields of the database:
Fields:
ID of person = id
Actual ordering = ipnline
Not sure the difference, but it's there anyway = orderline
ID of order = orderid
Date of order = created
Status of payment = payment_status
Verified or not = verified
Reason/Notes = reason
So, I have to first get the ID (the person shopping) and the orderID (I assume the present order). I then have to see if in that record, the payment_status = 'completed'. If it does, then the order went through and I can then parse what data I need. If not, then it was never an order, so ignore it.
Here is the kind of CRAP I have to deal with now (I have replaced client-sensitive data with nonsense text):
So, the important stuff is the following:
&mc_gross=51.80
&item_number1=&tax=2.80
&payment_date=11%3A18%3A52+Jul+25%2C+2014+PDT
&payment_status=Completed
&num_cart_items=2
&item_name1=Gold+Short+Sleeve+Polo+Shirt+Size+Adult+Small
&item_name2=shipping
&quantity1=2
&quantity2=1
&mc_gross_1=40.00
&mc_gross_2=9.00
&payment_gross=51.80
Most important is the number of items and what they actually are (so in the above example, 2 items were bought and it seems they were both the exact same shirt (&item_name1=Gold+Short+Sleeve+Polo+Shirt+Size+Adult+Small). That particular item's % equals $2.00 and 2 were purchased (&num_cart_items=2) so the variable to be written to is $4.00 (the payout commission for those items).
Unfortunately, each shopping cart item has a different % value, so the client is sending me a list of each item and its % payout.
SO, how to I parse the above text for each record and then store the important data into an array so that I can then figure out what was purchased, how many of them, assign the payout commission value to each item and then add up the sum total payout commission for that order AND then do that for ALL orders for a set number of days (every two weeks, monthly, etc). I assume I have to use the date/time field (&payment_date=11%3A18%3A52+Jul+25%2C+2014+PDT) to help segment it into 14 or 30 day increments?
The end result is a payout commission in a certain amount of days (so the client owes the vendor $200 over all orders for the last 30 days).
Thank you to ANYONE that can help me with this in any way, shape or form. I just need the right direction (how to parse the text, how to set up and write to the array and then how to do the math/divide it up into 2 week structures) and a bit of math help and I am pretty sure I can do the rest.
Mike
I am using a MySQL Database and have been able to login and query data thus far, however, the shopping cart I am using puts everything together in massive strings.
I need to separate certain parts so that I can add them to an array of variables. The end result is to separate all the purchases from each record (there are hundreds) and figure out what they bought (like 2 gold short sleeve polo shirts, as shown below). Then, knowing what each item is worth, write a variable to that array record. For example, each gold short sleeve polo shirt = $2.00 and two were bought, so I write $4.00 into a variable. All of these same variables will later be added together to form the sum total of what is owed to the client.
These are the fields of the database:
Fields:
ID of person = id
Actual ordering = ipnline
Not sure the difference, but it's there anyway = orderline
ID of order = orderid
Date of order = created
Status of payment = payment_status
Verified or not = verified
Reason/Notes = reason
So, I have to first get the ID (the person shopping) and the orderID (I assume the present order). I then have to see if in that record, the payment_status = 'completed'. If it does, then the order went through and I can then parse what data I need. If not, then it was never an order, so ignore it.
Here is the kind of CRAP I have to deal with now (I have replaced client-sensitive data with nonsense text):
Code: Select all
cmd=_notify-validate&mc_gross=51.80&protection_eligibility=Eligible&address_status=confirmed&item_number1=&tax=2.80&item_number2=&payer_id=blahblah&address_street=blah+blahblah+blah&payment_date=11%3A18%3A52+Jul+25%2C+2014+PDT&payment_status=Completed&charset=windows-1252&address_zip=blah&mc_shipping=0.00&mc_handling=0.00&first_name=blah&mc_fee=1.80&address_country_code=US&address_name=blah+blah¬ify_version=3.8&custom=34_probably private info8&payer_status=unverified&business=fg%40blah-blah.com&address_country=United+States&num_cart_items=2&mc_handling1=0.00&mc_handling2=0.00&address_city=blah&verify_sign=noneofyourbusiness&payer_email=blahblahblah&mc_shipping1=0.00&mc_shipping2=0.00&txn_id=noneofyourbusiness&payment_type=instant&last_name=blah&address_state=FL&item_name1=Gold+Short+Sleeve+Polo+Shirt+Size+Adult+Small&receiver_email=fg%40blahblah.com&item_name2=shipping&payment_fee=1.80&quantity1=2&quantity2=1&receiver_id=private&txn_type=cart&mc_gross_1=40.00&mc_currency=USD&mc_gross_2=9.00&residence_country=US&transaction_subject=34_likelyprivate&payment_gross=51.80&ipn_track_id=private-a-HTTP/1.1 200 OK
&mc_gross=51.80
&item_number1=&tax=2.80
&payment_date=11%3A18%3A52+Jul+25%2C+2014+PDT
&payment_status=Completed
&num_cart_items=2
&item_name1=Gold+Short+Sleeve+Polo+Shirt+Size+Adult+Small
&item_name2=shipping
&quantity1=2
&quantity2=1
&mc_gross_1=40.00
&mc_gross_2=9.00
&payment_gross=51.80
Most important is the number of items and what they actually are (so in the above example, 2 items were bought and it seems they were both the exact same shirt (&item_name1=Gold+Short+Sleeve+Polo+Shirt+Size+Adult+Small). That particular item's % equals $2.00 and 2 were purchased (&num_cart_items=2) so the variable to be written to is $4.00 (the payout commission for those items).
Unfortunately, each shopping cart item has a different % value, so the client is sending me a list of each item and its % payout.
SO, how to I parse the above text for each record and then store the important data into an array so that I can then figure out what was purchased, how many of them, assign the payout commission value to each item and then add up the sum total payout commission for that order AND then do that for ALL orders for a set number of days (every two weeks, monthly, etc). I assume I have to use the date/time field (&payment_date=11%3A18%3A52+Jul+25%2C+2014+PDT) to help segment it into 14 or 30 day increments?
The end result is a payout commission in a certain amount of days (so the client owes the vendor $200 over all orders for the last 30 days).
Thank you to ANYONE that can help me with this in any way, shape or form. I just need the right direction (how to parse the text, how to set up and write to the array and then how to do the math/divide it up into 2 week structures) and a bit of math help and I am pretty sure I can do the rest.
Mike