initial commit master
authorLisa Marie Maginnis <lisam@fsf.org>
Mon, 16 Mar 2015 02:05:15 +0000 (22:05 -0400)
committerLisa Marie Maginnis <lisam@fsf.org>
Mon, 16 Mar 2015 02:05:15 +0000 (22:05 -0400)
.gitignore [new file with mode: 0644]
etc/ipn.conf.sh.example [new file with mode: 0644]
ipn.sh [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e4e5f6c
--- /dev/null
@@ -0,0 +1 @@
+*~
\ No newline at end of file
diff --git a/etc/ipn.conf.sh.example b/etc/ipn.conf.sh.example
new file mode 100644 (file)
index 0000000..037981b
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+USER=
+PASS=''
+
+vault_url=https://example.com/query/
+civicrm_url=https://example.com/sites/all/modules/civicrm/extern/tcIPN.php
+
+datafile=$HOME/dat/tcipn.$(date '+%Y%m%d').csv
+logfile=$HOME/log/tcipn.$(date '+%Y%m%d').log
diff --git a/ipn.sh b/ipn.sh
new file mode 100755 (executable)
index 0000000..e497db9
--- /dev/null
+++ b/ipn.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+# TrustCommerce IPN generator
+# This script generates a TrustCommerece CSV report via a POST request
+# and then loops though the results and contacts CiviCRM to submit IPN
+# requests. This script exists because TrustCommerce does not currently
+# support sending IPNs.
+#
+# Author: Lisa Marie Maginnis, Sr SysAdmin
+# Copyright: Free Software Foundation 2014
+
+# Load out configs
+. $HOME/etc/ipn.conf.sh
+
+# Get todays report
+curl -s "$vault_url?custid=$USER&password=$PASS&querytype=transaction&begindate="$(date '+%m-%d-%Y') > $datafile 
+
+# Flip date for consitancy (TC changes this)
+sed 's/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)/\3-\1-\2/g' -i $datafile
+
+# Loop though today's IPNs (this is an embedded awk script that generates our query string)
+for link in `awk -F, '
+/payment/{
+   if($36!="") {
+      
+      date=$4
+      sub(/[[:blank:]].*/,"",date);
+      sub(/"/,"",date);
+      tid=$5;
+      bid=$36;
+      amount=$7/100;
+
+      if($13 == "approved") {
+         status=1;
+
+      } else if($13 == "decline") { 
+         status=4;
+      }
+
+      checks=sprintf("%s%s%s%s", bid, tid, amount, date);
+      command="printf \"%s\" \"" checks "\" | md5sum";
+      command | getline data;
+      close(command);
+      sub(/[[:blank:]].*/,"",data);
+      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);
+   }
+}' $datafile`; do 
+    
+    # Process IPN URL and log it
+    echo "Running: $link" >> $logfile
+    curl -s $link >> $logfile
+ done