Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Orders with failed/pending payments


Go to End


996 Views

Avatar
rog

Community Member, 8 Posts

20 November 2011 at 8:28pm

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?