LP#1474051 CRON script for clearing CC numbers
authorBill Erickson <berickxx@gmail.com>
Wed, 14 Oct 2015 15:59:32 +0000 (11:59 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 14 Oct 2015 19:31:42 +0000 (15:31 -0400)
Adds a new srfsh script which calls a new open-ils.storage API call
which sets the cc_number value to NULL on all credit card payments
older than the age specified in the srfsh script.

Adds example CRON entry.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/crontab.example
Open-ILS/src/Makefile.am
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/money.pm
Open-ILS/src/support-scripts/clear_cc_number.srfsh [new file with mode: 0755]

index 1060f77..f68575d 100644 (file)
@@ -61,6 +61,9 @@ EG_BIN_DIR = /openils/bin
 # Run the hard due date updater
 2  3  * * *   . ~/.bashrc && $EG_BIN_DIR/update_hard_due_dates.srfsh
 
+# Run the credit card number clearing script
+#5  4  * * *   . ~/.bashrc && $EG_BIN_DIR/clear_cc_number.srfsh
+
 # Action/Trigger entries ----
 
 # Runs all pending A/T events every half hour
index 4e62684..812c936 100644 (file)
@@ -69,6 +69,7 @@ core_scripts =   $(examples)/oils_ctl.sh \
                 $(supportscr)/purge_holds.srfsh \
                 $(supportscr)/purge_circulations.srfsh \
                 $(supportscr)/purge_pending_users.srfsh \
+                $(supportscr)/clear_cc_number.srfsh \
                 $(supportscr)/sitemap_generator \
                 $(srcdir)/extras/eg_config \
                 $(srcdir)/extras/openurl_map.pl \
@@ -271,6 +272,7 @@ ilscore-install:
        sed -i 's|BINDIR|@bindir@|g' '$(DESTDIR)@bindir@/long-overdue-status-update.pl'
        sed -i 's|SYSCONFDIR|@sysconfdir@|g' '$(DESTDIR)@bindir@/long-overdue-status-update.pl'
        sed -i 's|BINDIR|@bindir@|g' '$(DESTDIR)@bindir@/thaw_expired_frozen_holds.srfsh'
+       sed -i 's|BINDIR|@bindir@|g' '$(DESTDIR)@bindir@/clear_cc_number.srfsh'
        sed -i 's|LOCALSTATEDIR|@localstatedir@|g' '$(DESTDIR)@bindir@/oils_ctl.sh'
        sed -i 's|SYSCONFDIR|@sysconfdir@|g' '$(DESTDIR)@bindir@/oils_ctl.sh'
 
index 6507db9..d2db7ae 100644 (file)
@@ -522,4 +522,38 @@ __PACKAGE__->register_method(
 );
 
 
+sub clear_cc_number {
+    my $self = shift;
+    my $client = shift;
+    my $payment_age = shift;
+
+    # using NOW() in the AGE() calculation lets us modify payments 
+    # that occurred today without having to specify negative ages.
+
+    my $sql = <<"    SQL";
+        UPDATE money.credit_card_payment
+        SET cc_number = NULL 
+        WHERE AGE(NOW(), payment_ts) > ?::INTERVAL;
+    SQL
+
+    my $sth = actor::user->db_Main->prepare_cached($sql);
+    $sth->execute($payment_age);
+
+    return $sth->rows;
+}
+
+__PACKAGE__->register_method(
+    api_name  => 'open-ils.storage.money.clear_cc_number',
+    method    => 'clear_cc_number',
+    api_level => 1,
+    signature => q/
+        Credit card payments store the last 4 digits of the card
+        number.  This API call set the credit card number field
+        to NULL to remove this data after the payment has
+        reached the specified age.
+        @param payment_age The age as a string.
+    /
+);
+
+
 1;
diff --git a/Open-ILS/src/support-scripts/clear_cc_number.srfsh b/Open-ILS/src/support-scripts/clear_cc_number.srfsh
new file mode 100755 (executable)
index 0000000..6939d7f
--- /dev/null
@@ -0,0 +1,2 @@
+#!BINDIR/srfsh
+request open-ils.storage open-ils.storage.money.clear_cc_number "1 year"