| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # TrustCommerce IPN generator |
| 4 | # This script generates a TrustCommerece CSV report via a POST request |
| 5 | # and then loops though the results and contacts CiviCRM to submit IPN |
| 6 | # requests. This script exists because TrustCommerce does not currently |
| 7 | # support sending IPNs. |
| 8 | # |
| 9 | # Author: Lisa Marie Maginnis, Sr SysAdmin |
| 10 | # Copyright: Free Software Foundation 2014 |
| 11 | |
| 12 | # Load out configs |
| 13 | . $HOME/etc/ipn.conf.sh |
| 14 | |
| 15 | # Get todays report |
| 16 | curl -s "$vault_url?custid=$USER&password=$PASS&querytype=transaction&begindate="$(date '+%m-%d-%Y') > $datafile |
| 17 | |
| 18 | # Flip date for consitancy (TC changes this) |
| 19 | sed 's/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)/\3-\1-\2/g' -i $datafile |
| 20 | |
| 21 | # Loop though today's IPNs (this is an embedded awk script that generates our query string) |
| 22 | for link in `awk -F, ' |
| 23 | /payment/{ |
| 24 | if($36!="") { |
| 25 | |
| 26 | date=$4 |
| 27 | sub(/[[:blank:]].*/,"",date); |
| 28 | sub(/"/,"",date); |
| 29 | tid=$5; |
| 30 | bid=$36; |
| 31 | amount=$7/100; |
| 32 | |
| 33 | if($13 == "approved") { |
| 34 | status=1; |
| 35 | |
| 36 | } else if($13 == "decline") { |
| 37 | status=4; |
| 38 | } |
| 39 | |
| 40 | checks=sprintf("%s%s%s%s", bid, tid, amount, date); |
| 41 | command="printf \"%s\" \"" checks "\" | md5sum"; |
| 42 | command | getline data; |
| 43 | close(command); |
| 44 | sub(/[[:blank:]].*/,"",data); |
| 45 | printf("'$civicrm_url'?reset=1&billingid=%s&amount=%s&trxn_id=%s&date=%s&status=%s&checksum=%s&key=meh&module=contribute\n", bid, amount, tid, date, status, data); |
| 46 | } |
| 47 | }' $datafile`; do |
| 48 | |
| 49 | # Process IPN URL and log it |
| 50 | echo "Running: $link" >> $logfile |
| 51 | curl -s $link >> $logfile |
| 52 | done |