mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-05-01 02:33 pm

[dw-free] Add raw output of PayPal transaction and HTTP log to admin page.

[commit: http://hg.dwscoalition.org/dw-free/rev/af1bdcc59591]

Add raw output of PayPal transaction and HTTP log to admin page.

Patch by [staff profile] mark.

Files modified:
  • htdocs/admin/pay/view.bml
--------------------------------------------------------------------------------
diff -r 61481e10ee39 -r af1bdcc59591 htdocs/admin/pay/view.bml
--- a/htdocs/admin/pay/view.bml	Fri May 01 14:03:39 2009 +0000
+++ b/htdocs/admin/pay/view.bml	Fri May 01 14:33:36 2009 +0000
@@ -52,6 +52,51 @@
         $body .= "<p>This cart has no items in it.</p>";
     }
 
+    # very sad generic table dumper
+    my $dump = sub {
+        my ( $sql, @bind ) = @_;
+
+        # make an educated guess at durl-ing something
+        my $durl = sub {
+            my $val = shift;
+            return $val
+                unless $val =~ /&/ && $val =~ /=/;
+            my ( $hr, $ar ) = ( {}, [] );
+            LJ::decode_url_string( $val, $hr, $ar );
+            foreach ( qw/ SIGNATURE USER PWD / ) {
+                $hr->{$_} = '<em>redacted</em>'
+                    if exists $hr->{$_};
+            }
+            return join( '<br />', map { "<strong>$_:</strong> $hr->{$_}" } sort keys %$hr );
+        };
+
+        my $dbh = LJ::get_db_writer();
+        my $sth = $dbh->prepare( $sql )
+            or return $body .= "<p>Unable to prepare SQL.</p>";
+        $sth->execute( @bind );
+        return $body .= "<p>Error executing SQL.</p>"
+            if $sth->err;
+
+        my $rows = [];
+        push @$rows, $_
+            foreach $sth->fetchrow_hashref;
+        return $body .= "<p>No records found.</p>"
+            unless $rows && @$rows;
+
+        my @cols = sort { $a cmp $b } keys %{ $rows->[0] };
+        $body .= q{<table><tr><th>};
+        $body .= join( '</th><th>', @cols );
+        $body .= q{</th></tr>};
+
+        foreach my $row ( @$rows ) {
+            $body .= q{<tr><td>};
+            $body .= join( '</td><td>', map { $durl->( $row->{$_} ) } @cols );
+            $body .= q{</td></tr>};
+        }
+
+        $body .= q{</table>};
+    };
+
     # attempt to create an engine so we can get more info
     my $classname = $DW::Shop::PAYMENTMETHODS{$paymentmethod}->{class};
     my $engine = eval "DW::Shop::Engine::${classname}->new_from_cart( \$cart )";
@@ -65,6 +110,14 @@
         $body .= "<tr><th>PayPal Email Address:</th><td>" . $engine->email . "</td></tr>";
         $body .= "<tr><th>User Email Address:</th><td>" . $cart->email . "</td></tr>";
         $body .= "</table>";
+
+        # now show the pp_trans log
+        $body .= "<h2>raw: pp_trans (PayPal transactions)</h2>";
+        $dump->( 'SELECT * FROM pp_trans WHERE ppid = ?', $engine->ppid );
+
+        # now show the pp_log log
+        $body .= "<h2>raw: pp_log (PayPal raw log)</h2>";
+        $dump->( 'SELECT * FROM pp_log WHERE ppid = ?', $engine->ppid );
 
     } elsif ( $classname eq 'CheckMoneyOrder' ) {
         # show the payer's details.
--------------------------------------------------------------------------------