Hi,
I notice that when an order is placed and the payment fails or is left pending because the user closes the browser etc then is no notification that the order was placed. I know that this could easily be done in php but I'm a sysadmin at heart. My solution was to run the following as a cron job on say the 50th minute of every hour or could be as often as you like. This would then let you know that an order as been placed and you could contact the customer to find out why it wasn't completed or what when wrong.
#!/bin/bash
db_username='username'
db_password='paswword'
db_database='`database`'
emailbody="/tmp/order.txt"
OldestTime="2"
NewestTime="1"
TimeType="HOUR" # HOUR, DAY, MONTH, etc
ORDER_EMAIL="you@example.com"
dbquery=$(mysql -u$db_username -p$db_password -e "SELECT OrderID, Status, AmountAmount FROM $db_database.Payment WHERE LastEdited > now() - INTERVAL $OldestTime $TimeType and LastEdited < now() - INTERVAL $NewestTime $TimeType ;" | sed '1d' | sed 's/\t/,/g;s/\n//g')
for row in $dbquery ;
do
IFS=',' cell=( ${row} )
echo "OrderID: ${cell[0]}" > $emailbody
echo "Status: ${cell[1]}" >> $emailbody
echo "Amount: ${cell[2]}" >> $emailbody
Order=$(mysql -u$db_username -p$db_password -e "SELECT MemberID FROM $db_database.Order WHERE ID = \"${cell[0]}\";" | tail -n 1)
echo "$Order" >> $emailbody
Member=$(mysql -u$db_username -p$db_password -e "SELECT FirstName, Surname, Email FROM $db_database.Member WHERE ID = \"$Order\";" | tail -n 1 | sed 's/\t/\n/g')
echo "$Member" >> $emailbody
cat $emailbody
# mail -s "Order #${cell[0]} Has ${cell[1]} Payments " -a "From:errors@example.com" $ORDER_EMAIL < $emailbody
done
The other thing that I notice that happens is that the stock is removed. Is there a simple way of reversing this? Maybe the stock should only be taken once the payment has been received?