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

[ljcom] r8416: LJSUP-5634 (LJ Wallet): miscellaneous ch...

Committer: ailyin
LJSUP-5634 (LJ Wallet): miscellaneous changes

U   trunk/cgi-bin/LJ/Pay/LoyaltyUserpic.pm
U   trunk/cgi-bin/LJ/Pay/Method.pm
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm
U   trunk/cgi-bin/LJ/Pay/Payment.pm
U   trunk/cgi-bin/LJ/Pay/Wallet.pm
U   trunk/cgi-bin/LJ/Widget/WalletHistory.pm
U   trunk/cgi-bin/bml/scheme/lanzelot.look
U   trunk/htdocs/pay/modify.bml
U   trunk/htdocs/shop/wallet.bml
Modified: trunk/cgi-bin/LJ/Pay/LoyaltyUserpic.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/LoyaltyUserpic.pm	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/cgi-bin/LJ/Pay/LoyaltyUserpic.pm	2010-04-01 11:10:59 UTC (rev 8416)
@@ -553,7 +553,7 @@
                                       ( "+$non_cons_ct userpics due to $mo_ct" .
                                         " months Paid Account time" ),
                                       ( @cart ? 
-                                        "<a href='" . LJ::Pay::Payment::cart_link(@cart) . "'>#$cart</a>" :
+                                        "<a href='$LJ::SITEROOT/pay/?c=$cart'>#$cart</a>" :
                                         undef ),
                                       "$pic_ct" );
             }

Modified: trunk/cgi-bin/LJ/Pay/Method.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method.pm	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/cgi-bin/LJ/Pay/Method.pm	2010-04-01 11:10:59 UTC (rev 8416)
@@ -22,13 +22,13 @@
 
 # initialization code. do not touch this.
 my @METHODS = LJ::ModuleLoader->module_subclasses(__PACKAGE__);
-my %METHOD_MAP;
+my %CLASS_MAP;
 
 foreach my $method (@METHODS) {
     eval "use $method";
     Carp::confess "Error loading module '$method': $@" if $@;
 
-    $METHOD_MAP{$method->code} = $method;
+    $CLASS_MAP{$method->code} = $method;
 }
 
 # parent class methods
@@ -36,10 +36,10 @@
     return \@METHODS;
 }
 
-sub method_by_code {
+sub class_by_code {
     my ($class, $code) = @_;
 
-    return $METHOD_MAP{$code};
+    return $CLASS_MAP{$code};
 }
 
 sub suitable_methods {

Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm	2010-04-01 11:10:59 UTC (rev 8416)
@@ -38,6 +38,25 @@
     my ($self, $payment, $buyer_u, $rcpt_u, $note_rec_change) = @_;
 
     LJ::Pay::Wallet->deliver_money($self->get_piid);
+
+    my $email_subject = "You've Received $LJ::SITENAMEABBREV Wallet Tokens!";
+
+    my $qty = $self->get_qty;
+    my $damt = sprintf("%.2f", $qty / LJ::Pay::Wallet::EXCHANGE_RATE);
+
+    my $email_body = qq{
+        You have received $qty $LJ::SITENAMEABBREV Wallet Tokens. You can redeem
+        them for \$$damt USD in $LJ::SITENAMESHORT services:
+        $LJ::SITEROOT/shop/
+
+        Enjoy!
+
+        $LJ::SITENAMESHORT Team
+        $LJ::SITEROOT
+    };
+    $email_body =~ s/^ +//gm;
+
+    return (1, $email_subject, $email_body);
 }
 
 sub render_cart_item {

Modified: trunk/cgi-bin/LJ/Pay/Payment.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment.pm	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/cgi-bin/LJ/Pay/Payment.pm	2010-04-01 11:10:59 UTC (rev 8416)
@@ -538,10 +538,8 @@
 }
 
 sub cart_link {
-    my ($payid, $anum) = @_;
-    return undef unless defined $payid && defined $anum;
-
-    my $cart = "$payid-$anum";
+    my ($self) = @_;
+    my $cart = $self->get_payid . '-' . $self->get_anum;
     return "$LJ::SITEROOT/pay/?c=$cart";
 }
 

Modified: trunk/cgi-bin/LJ/Pay/Wallet.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Wallet.pm	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/cgi-bin/LJ/Pay/Wallet.pm	2010-04-01 11:10:59 UTC (rev 8416)
@@ -142,4 +142,19 @@
     return 1;
 }
 
+sub get_wallet_link {
+    my ($class, $u) = @_;
+
+    return '' unless $class->is_user_eligible($u);
+
+    my $balance = int $class->get_user_balance($u);
+
+    my $link = "$LJ::SITEROOT/wallet/";
+    my $text = $balance > 0 ?
+        "LJ Wallet ($balance tokens)":
+        "LJ Wallet";
+
+    return qq{<a href="$link">$text</a>};
+}
+
 1;

Modified: trunk/cgi-bin/LJ/Widget/WalletHistory.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/WalletHistory.pm	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/cgi-bin/LJ/Widget/WalletHistory.pm	2010-04-01 11:10:59 UTC (rev 8416)
@@ -44,15 +44,15 @@
     foreach my $logitem (@logitems) {
         my $time_formatted = $format_time->($logitem->time_end);
         my ($tokens_in, $tokens_out) = ('', '');
-        if ($logitem->action == ACTION_ADD) {
-            $tokens_in = $logitem->qty;
-        } elsif ($logitem->action == ACTION_REMOVE) {
-            $tokens_out = $logitem->qty;
+        if ($logitem->action eq ACTION_ADD) {
+            $tokens_in = int $logitem->qty;
+        } elsif ($logitem->action eq ACTION_REMOVE) {
+            $tokens_out = int $logitem->qty;
         }
 
         my $des;
         my $token_xfer = 0;
-        if ($logitem->action == ACTION_ADD) {
+        if ($logitem->action eq ACTION_ADD) {
             my $buyer_userid = $logitem->cart->get_userid;
             if ($logitem->userid == $buyer_userid) {
                 $des = 'Buy tokens';
@@ -62,17 +62,25 @@
                 $token_xfer = 1;
             }
         } else {
-            my $cart_link = $logitem->cart->cart_link;
-            $des = qq{
-                <a href="$cart_link">Order in LJ Shop</a>
-            };
+            my $cart = $logitem->cart;
+            if (LJ::Pay::Payment::PayItem::WalletTokens->present_in($cart)) {
+                my @items = $cart->get_items;
+                my $rcptid = $items[0]->get_rcptid;
+                my $rcpt = LJ::load_userid($rcptid);
+                $des = "Sent to " . $rcpt->ljuser_display;
+            } else {
+                my $cart_link = $cart->cart_link;
+                $des = qq{
+                    <a href="$cart_link">Order in LJ Shop</a>
+                };
+            }
         }
 
-        my $method = '';
+        my $method_name = '';
         unless ($token_xfer) {
             my $method_code = $logitem->cart->get_method;
-            my $method_class = LJ::Pay::Method->method_by_code($method_code);
-            $method = $method_class->name_generic;
+            my $method_class = LJ::Pay::Method->class_by_code($method_code);
+            $method_name = $method_class->name_generic;
         }
 
         my $result;
@@ -95,7 +103,7 @@
                 <td>$tokens_in</td>
                 <td>$tokens_out</td>
                 <td>$des</td>
-                <td>$method</td>
+                <td>$method_name</td>
                 <td>$result</td>
                 $cell_user
             </tr>

Modified: trunk/cgi-bin/bml/scheme/lanzelot.look
===================================================================
--- trunk/cgi-bin/bml/scheme/lanzelot.look	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/cgi-bin/bml/scheme/lanzelot.look	2010-04-01 11:10:59 UTC (rev 8416)
@@ -183,6 +183,10 @@
         ? 'http://livejournal.ru/counter/'
         : '<?siteroot?>/statistics/';
 
+    my $wallet_link = LJ::Pay::Wallet->get_wallet_link($remote);
+    my $wallet_link_li;
+    $wallet_link_li = "<li>$wallet_link</li>" if $wallet_link;
+
     my $ljuser = $remote->ljuser_display;
     
     return <<"LOGOUT_FORM";
@@ -202,6 +206,9 @@
             <li><a href="$LJ::SITEROOT/update.bml"><?_ml lanzelot.item.postlj _ml?></a> <a href="$remote_friends_url"><?_ml lanzelot.item.friends _ml?></a> $messages
             <li><a href="<?siteroot?>/manage/settings/index2.bml?cat=account"><?_ml lanzelot.item.account _ml?></a><a href="<?siteroot?>/manage/account/" class="account-icon">$account_icon</a> <a href="$stat_link""><?_ml lanzelot.item.ljru.statistics _ml?></a> <a href="http://pics.livejournal.com"><?_ml lanzelot.item.ljplus.photo _ml?></a></li>
                 </ul>
+        <ul>
+            $wallet_link_li
+        </ul>
                 <div class="lj-games"><img src="<?statprefix?>/lanzelot/img/lj_games.gif" width="16" height="10"><a href="$LJ::SITEROOT/games/"><?_ml lanzelot.item.games _ml?></a></div>
         </dd>
         </dl>

Modified: trunk/htdocs/pay/modify.bml
===================================================================
--- trunk/htdocs/pay/modify.bml	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/htdocs/pay/modify.bml	2010-04-01 11:10:59 UTC (rev 8416)
@@ -173,7 +173,7 @@
             }));
         }
 
-        my $meth_class = LJ::Pay::Method->method_by_code($paymeth) ||
+        my $meth_class = LJ::Pay::Method->class_by_code($paymeth) ||
             return $err->("Unknown payment method: " . LJ::ehtml($paymeth));
 
         return $err->($meth_class->error_message_unsuitable)

Modified: trunk/htdocs/shop/wallet.bml
===================================================================
--- trunk/htdocs/shop/wallet.bml	2010-04-01 09:18:38 UTC (rev 8415)
+++ trunk/htdocs/shop/wallet.bml	2010-04-01 11:10:59 UTC (rev 8416)
@@ -9,6 +9,7 @@
     use LJ::JSON;
     use LJ::Pay::Wallet;
     use LJ::Pay::Payment::PayItem::WalletTokens;
+    use LJ::Pay::Method::Wallet;
 
     $title = 'LJ Wallet';
 
@@ -26,8 +27,7 @@
         if ($act eq 'buy') {
             my $addr = '';
             eval {
-                my $cartobj = LJ::Pay::Payment::new_cart($remote);
-                my $cart = $cartobj->get_cart_as_string;
+                my $cart = LJ::Pay::Payment::new_cart($remote);
 
                 my $it = LJ::Pay::Payment::PayItem->new_memonly(
                     item => 'tokens',
@@ -39,9 +39,9 @@
 
                 $it->{'amt'} = $it->calculate_price;
 
-                $cartobj->add_item(%$it);
+                $cart->add_item(%$it);
 
-                $addr = "$LJ::SITEROOT/pay/?c=$cart";
+                $addr = $cart->cart_link;
             };
 
             return qq{
@@ -50,11 +50,49 @@
 
             return BML::redirect($addr);
         } elsif ($act eq 'send') {
+            my $cart;
+
+            eval {
+                $cart = LJ::Pay::Payment::new_cart($remote);
+
+                my $it = LJ::Pay::Payment::PayItem->new_memonly(
+                    'item' => 'tokens',
+                    'subitem' => 0,
+                    'qty' => $POST{'send_amt'},
+                    'rcptid' => LJ::load_user($POST{'send_to'})->userid,
+                );
+
+                $it->{'amt'} = $it->calculate_price;
+                $cart->add_item(%$it);
+
+                $cart->set_method(LJ::Pay::Method::Wallet->code);
+
+                LJ::Pay::Wallet->pay_for_cart($cart->get_payid);
+            };
+
+            return qq{
+                <?errorbar couldn't xfer: $@ errorbar?>
+            } if $@;
+
+            my $qargs = '?xferred='.$cart->get_cart_as_string;
+            return BML::redirect($self_uri . $qargs);
         }
 
         return BML::redirect($self_uri);
     }
 
+    if ($GET{'xferred'}) {
+        my $cart = LJ::Pay::Payment::load_cart($GET{'xferred'});
+        my @items = $cart->get_items;
+        my $rcptid = $items[0]->get_rcptid;
+        my $rcpt_ljuser = LJ::load_userid($rcptid)->ljuser_display;
+        my $qty = $items[0]->get_qty;
+
+        push @warnings, qq{<?warningbar
+            You have successfully sent $qty tokens to $rcpt_ljuser
+        warningbar?>};
+    }
+
     my $balance = int eval { LJ::Pay::Wallet->get_user_balance($remote) };
 
     my %packages = %{LJ::Pay::Payment::PayItem::WalletTokens::PACKAGES()};
@@ -102,6 +140,8 @@
     }
 
     return qq{
+        @warnings
+
         <p>Available balance: $balance tokens.</p>
 
         <form action="$self_uri" method="post">

Tags: andy, bml, ljcom, look, pm
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