Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r11125: LJSUP-9908 (LJ SHOP 2011 update)

Committer: ailyin
LJSUP-9908 (LJ SHOP 2011 update)
U   trunk/bin/maint/pay.pl
Modified: trunk/bin/maint/pay.pl
===================================================================
--- trunk/bin/maint/pay.pl	2011-10-28 07:35:39 UTC (rev 11124)
+++ trunk/bin/maint/pay.pl	2011-10-28 11:22:45 UTC (rev 11125)
@@ -203,14 +203,16 @@
 
     my $dbh = LJ::get_db_writer()
         or die "Could not contact global database master";
-    my $sth;
 
     my $now = time();
     my $res = $dbh->selectall_arrayref(
-                         "SELECT payid, userid, months, forwhat, amount, method, datesent ".
-                         "FROM payments WHERE used='N' ".
-                         "AND (IFNULL(giveafter,0) = 0 OR $now >= giveafter)",
-                         { "Slice" => {} }
+        qq{
+            SELECT * FROM payments
+            WHERE
+                used="N" AND
+                ( giveafter IS NULL or giveafter <= UNIX_TIMESTAMP() )
+        },
+        { 'Slice' => {} }
     );
     die $dbh->errstr if $dbh->err;
 
@@ -219,38 +221,43 @@
     my %is_beta; # payid => 'beta' payvar
 
     my @used = ();
-    foreach my $p (@$res)
-    {
+    foreach my $row (@$res) {
         LJ::start_request();
 
         $dbh = LJ::get_db_writer()
             or die "Could not contact global database master";
 
-        my $userid = $p->{'userid'};
+        my $cart = LJ::Pay::Payment->new_memonly(%$row);
 
-        # check userids of all the affected clusterids before deciding whether to process this payment
+        my $userid = $cart->get_userid;
+        my $payid  = $cart->get_payid;
+
+        # check userids of all the affected clusterids
+        # before deciding whether to process this payment
         my %userids = $userid ? ($userid => 1) : ();
-        if ($p->{'forwhat'} eq 'cart') {
+        if ( $cart->get_forwhat eq 'cart' ) {
             my $s = $dbh->prepare("SELECT rcptid FROM payitems WHERE payid=? AND rcptid>0");
-            $s->execute($p->{'payid'});
+            $s->execute($payid);
             die $dbh->errstr if $dbh->err;
             while (my $uid = $s->fetchrow_array) {
                 $userids{$uid} = 1;
             }
         }
 
-        # simplified copy of LJ::Payment->payvar_get
-        # loading of unneeded payments is hard
-        my $is_beta = $dbh->selectrow_array("SELECT pval FROM payvars WHERE payid=? AND pkey=?",
-                                             undef, $p->{'payid'}, 'beta');
-        die $dbh->errstr if $dbh->err;
-        if ($LJ::SHOP_DELIVERY_SPECIAL) { # process only specially marked payments
+        # prevent shop3 goods from being delivered here
+        next if $cart->payvar_get('shop_version');
+
+        my $is_beta = $cart->payvar_get('beta');
+        if ($LJ::SHOP_DELIVERY_SPECIAL) {
+            # process only specially marked payments
             next unless $is_beta eq $LJ::SHOP_DELIVERY_SPECIAL;
-        } else { # process only non-marked payments
+        } else {
+            # process only non-marked payments
             next if $is_beta;
         }
 
-        $is_beta{ $p->{'payid'} } = $is_beta; # will be used later, on payitems phase
+        # will be used later, on payitems phase:
+        $is_beta{$payid} = $is_beta;
 
         if (%userids) {
             # call into LJ::load_userids_multi() to get clusterids for these users
@@ -260,52 +267,61 @@
 
             # verify we can get all of the handles necessary to complete this request
             my $dirty = 0;
-            foreach (values %$users) {
-                $dirty = $_->{clusterid}, last unless $_->writer;
+            foreach my $u ( values %$users ) {
+                next if $u->writer;
+                $dirty = $u->clusterid;
             }
 
             if ($dirty) {
-                print "Cluster $dirty unreachable, skipping payment: $p->{payid}\n";
+                print "Cluster $dirty unreachable, skipping payment: $payid\n";
                 next;
             }
         }
 
-        print "Payment: $p->{'payid'} ($p->{'forwhat'})\n";
+        print "Payment: $payid (" . $cart->get_forwhat . ")\n";
 
-        # mail notification of large orders... but only if it was automatically processed
-        if ($LJ::ACCOUNTS_EMAIL && $LJ::LARGE_ORDER_NOTIFY &&
-            ($p->{'method'} eq "cc" || $p->{'method'} eq "paypal") &&
-            $p->{'amount'} > $LJ::LARGE_ORDER_NOTIFY) {
+        # mail notification of large orders... but only if it
+        # was automatically processed
+        if ( $LJ::ACCOUNTS_EMAIL && $LJ::LARGE_ORDER_NOTIFY &&
+            ( $cart->get_method eq 'cc' || $cart->get_method eq 'paypal' ) &&
+            $cart->get_amount > $LJ::LARGE_ORDER_NOTIFY )
+        {
 
             my $dollars = sub { sprintf("\$%.02f", shift()) };
-            print "Sending large order notification: " . $dollars->($p->{'amount'}) . "\n";
+            my $amount_display = $dollars->( $cart->get_amount );
+            print "Sending large order notification: $amount_display\n";
 
             LJ::send_mail({
                 'to' => $LJ::ACCOUNTS_EMAIL,
                 'from' => $LJ::ACCOUNTS_EMAIL,
                 'wrap' => 1,
                 'charset' => 'utf-8',
-                'subject' => "Large order processed: " . $dollars->($p->{'amount'}) .
-                             " [payid: $p->{'payid'}]",
+                'subject' => "Large order processed: $amount_display" .
+                             " [payid: $payid]",
                 'body' => "This warning has been sent because the following order of over " .
                           $dollars->($LJ::LARGE_ORDER_NOTIFY) .
                           " has been processed on $LJ::SITENAMESHORT.\n\n" .
 
-                          "        Amount: " . $dollars->($p->{'amount'}) . "\n" .
-                          "         Payid: $p->{'payid'}\n" .
-                          "        Method: $p->{'method'}\n" .
-                          "     Date Sent: $p->{'datesent'}\n\n"
+                          "        Amount: $amount_display\n" .
+                          "         Payid: $payid\n" .
+                          "        Method: " . $cart->get_method . "\n" .
+                          "     Date Sent: " . $cart->get_datesent . "\n\n"
                           });
         }
 
         # park this payment as used
-        push @used, $p->{'payid'};
+        push @used, $payid;
 
         # if a cart, mark each item in the cart as ready to be processed,
         # then we'll do that below.
-        if ($p->{'forwhat'} eq "cart") {
-            $dbh->do("UPDATE payitems SET status='pend' WHERE ".
-                     "payid=? AND status='cart'", undef, $p->{'payid'});
+        if ( $cart->get_forwhat eq "cart" ) {
+            $dbh->do(
+                qq{
+                    UPDATE payitems SET status='pend'
+                    WHERE payid=? AND status='cart'
+                },
+                undef, $payid,
+            );
 
             LJ::end_request();
 
@@ -337,7 +353,7 @@
     # get pending cart items
     # FIXME: code below does sorting, that can be done by new method LJ::Pay::Payment::PayItem::sort_order
     my %payitems = ( 'paidacct' => [], 'other' => [] );
-    $sth = $dbh->prepare("SELECT * FROM payitems WHERE status='pend' AND (IFNULL(giveafter,0) = 0 OR $now >= giveafter)");
+    my $sth = $dbh->prepare("SELECT * FROM payitems WHERE status='pend' AND (IFNULL(giveafter,0) = 0 OR $now >= giveafter)");
     $sth->execute;
     while (my $pi = $sth->fetchrow_hashref) {
         my $key = $pi->{'item'} eq 'perm' ? 'perm' :
@@ -399,6 +415,9 @@
             warn "cannot load cart: $@";
         } else {
 
+            # prevent shop3 goods from being delivered here
+            next if $pp->payvar_get('shop_version');
+
             my $is_beta = $is_beta{ $pi->{'payid'} };
             $is_beta = $pp->payvar_get('beta') unless exists $is_beta{ $pi->{'payid'} };
             $is_beta{ $pi->{'payid'} } = $is_beta; # store (found) value

Tags: ailyin, andy, ljcom, pl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments