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

[ljcom] r9579: LJSUP-6936 (Webmoney integration): clean...

Committer: ailyin
LJSUP-6936 (Webmoney integration): clean up outdated shop code
U   trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm
U   trunk/cgi-bin/LJ/Pay/Method/Free.pm
U   trunk/cgi-bin/LJ/Pay/Method/PayPal.pm
U   trunk/cgi-bin/LJ/Pay/Method/SMS.pm
U   trunk/cgi-bin/LJ/Pay/Method/Wallet.pm
U   trunk/cgi-bin/LJ/Pay/Method/YandexMoney.pm
U   trunk/cgi-bin/LJ/Pay/Method.pm
U   trunk/htdocs/pay/index.bml
U   trunk/htdocs/pay/modify.bml
Modified: trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm	2010-10-01 10:02:01 UTC (rev 9579)
@@ -7,28 +7,6 @@
 
 sub can_pay_for_coppa { 1 }
 
-sub checkout_should_redirect {
-    return !$LJ::AUTHNET_DOWN;
-}
-
-sub checkout_redirect {
-    my ($class, $cart) = @_;
-
-    BML::redirect("$LJ::SSLROOT/pay/cc.bml?c=".$cart->get_cart_as_string);
-}
-
-sub checkout_render {
-    my ($class, $cart, $title, $body) = @_;
-
-    BML::set_language_scope('/pay/modify.bml');
-
-    $$title = $BML::ML{'.ccprocessordown.title'};
-
-    $$body =
-        "<?h1 $BML::ML{'.ccprocessordown.header'} h1?>" .
-        "<?p $BML::ML{'.ccprocessordown.text'} p?>";
-}
-
 sub get_page_params {
     my ($class, $cart) = @_;
 

Modified: trunk/cgi-bin/LJ/Pay/Method/Free.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method/Free.pm	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/cgi-bin/LJ/Pay/Method/Free.pm	2010-10-01 10:02:01 UTC (rev 9579)
@@ -18,31 +18,6 @@
     return $ret;
 }
 
-sub checkout_should_redirect { 0 }
-
-sub checkout_process {
-    my ($class, $cart) = @_;
-
-    my $dbh = LJ::get_db_writer();
-
-    $dbh->do(qq{
-        UPDATE payments
-        SET mailed='N', used='N', method='free', daterecv=NOW()
-        WHERE payid=? AND mailed='C' AND used='C'
-    }, undef, $cart->{'payid'});
-}
-
-sub checkout_render {
-    my ($class, $cart, $title, $body) = @_;
-
-    BML::set_language_scope('/pay/modify.bml');
-
-    $$title = $BML::ML{'.success.title'};
-    $$body = LJ::Lang::ml('.success.text', {
-        'id' => "<b>" . $cart->get_cart_as_string . "</b>"
-    });
-}
-
 sub get_page_params {
     my ($class, $cart) = @_;
 

Modified: trunk/cgi-bin/LJ/Pay/Method/PayPal.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method/PayPal.pm	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/cgi-bin/LJ/Pay/Method/PayPal.pm	2010-10-01 10:02:01 UTC (rev 9579)
@@ -5,81 +5,6 @@
 
 sub code { 'paypal' }
 
-sub checkout_should_redirect {
-    return 0;
-}
-
-sub checkout_redirect {
-    my ($class, $cart) = @_;
-
-    # paypal no longer accepts GET requests
-    return;
-
-    my $count = scalar(@{$cart->{'items'}});
-    my $amount = $cart->{'amount'};
-    my $pp_url =
-        "$LJ::PAYPAL_URL?amount=$amount" .
-        "&return=http%3A//www.$LJ::DOMAIN/paidaccounts/thankyou.bml" .
-        "&item_name=" . LJ::eurl("Cart ID $cart ($count item(s))") .
-        "&custom=" . LJ::eurl("cart=" . $cart->get_cart_as_string) .
-        "&business=$LJ::PAYPAL_ACCT" .
-        "&cmd=_xclick" .
-        "&no_shipping=1" .
-        "&no_note=1" .
-        "&notify_url=http%3A//www.$LJ::DOMAIN/paidaccounts/pp_notify.bml";
-
-    return BML::redirect($pp_url);
-}
-
-sub checkout_render {
-    my ($class, $cart, $title, $body) = @_;
-
-    BML::set_language_scope('/pay/modify.bml');
-
-    if ($LJ::PAYPAL_DOWN) {
-        $$title = $BML::ML{'.paypaldown.title'};
-
-        $$body =
-            "<?h1 $BML::ML{'.paypaldown.header'} h1?>" .
-            "<?p $BML::ML{'.paypaldown.text'} p?>";
-
-        return;
-    }
-
-    my $count = scalar(@{$cart->{'items'}});
-    my $amount = $cart->{'amount'};
-    my $cart_string = $cart->get_cart_as_string;
-
-    $$title = $BML::ML{'.ccprocessordown.paypal.link'};
-
-    my $fields = LJ::html_hidden(
-        'amount' => $amount,
-        'return' => "$LJ::SITEROOT/paidaccounts/thankyou.bml",
-        'item_name' => "Cart ID $cart_string ($count item(s))",
-        'custom' => "cart=$cart_string",
-
-        ## some clever guy put escaped account name into config
-        'business' => LJ::durl($LJ::PAYPAL_ACCT),
-
-        'cmd' => '_xclick',
-        'no_shipping' => 1,
-        'no_note' => 1,
-        'notify_url' => "$LJ::SITEROOT/paidaccounts/pp_notify.bml",
-    );
-
-    $$body = qq{
-        <?h1 $BML::ML{'.ccprocessordown.paypal.go_to_paypal'} h1?>
-        <form method='POST' action='$LJ::PAYPAL_URL'>
-            $fields
-            <input
-                type="image" name="submit"
-                alt="Make payments with PayPal - it's fast, free and secure!"
-                src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif"
-            >
-        </form>
-    };
-}
-
 sub get_page_params {
     my ($class, $cart) = @_;
 

Modified: trunk/cgi-bin/LJ/Pay/Method/SMS.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method/SMS.pm	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/cgi-bin/LJ/Pay/Method/SMS.pm	2010-10-01 10:02:01 UTC (rev 9579)
@@ -16,15 +16,6 @@
     return LJ::Pay::can_use_sup_sms($remote);
 }
 
-sub checkout_should_redirect { 1 }
-
-sub checkout_redirect {
-    my ($class, $cart) = @_;
-
-    return BML::redirect("$LJ::PAY_SUP_SMS_URI?order_num=" .
-        LJ::eurl($cart->get_cart_as_string));
-}
-
 sub get_page_params {
     my ($class, $cart) = @_;
 

Modified: trunk/cgi-bin/LJ/Pay/Method/Wallet.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method/Wallet.pm	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/cgi-bin/LJ/Pay/Method/Wallet.pm	2010-10-01 10:02:01 UTC (rev 9579)
@@ -39,14 +39,6 @@
     return 1;
 }
 
-sub checkout_should_redirect { 1 }
-
-sub checkout_redirect {
-    my ($class, $cart) = @_;
-
-    BML::redirect("$LJ::SSLROOT/pay/wallet.bml?c=".$cart->get_cart_as_string);
-}
-
 sub get_page_params {
     my ($class, $cart) = @_;
 

Modified: trunk/cgi-bin/LJ/Pay/Method/YandexMoney.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method/YandexMoney.pm	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/cgi-bin/LJ/Pay/Method/YandexMoney.pm	2010-10-01 10:02:01 UTC (rev 9579)
@@ -16,15 +16,6 @@
     return LJ::Pay::can_use_sup_yandex($remote);
 }
 
-sub checkout_should_redirect { 1 }
-
-sub checkout_redirect {
-    my ($class, $cart) = @_;
-
-    return BML::redirect("$LJ::PAY_SUP_YANDEX_URI?c=" .
-        LJ::eurl($cart->get_cart_as_string));
-}
-
 sub allow_open_proxy { 1 }
 
 sub get_page_params {

Modified: trunk/cgi-bin/LJ/Pay/Method.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method.pm	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/cgi-bin/LJ/Pay/Method.pm	2010-10-01 10:02:01 UTC (rev 9579)
@@ -19,14 +19,8 @@
  die "method not suitable"
      unless $method_class->suitable_for($cart);
 
- $method_class->checkout_process($cart);
- my ($title, $body);
- if ($method_class->checkout_should_redirect($cart)) {
-     return $method_class->checkout_redirect($cart);
- } else {
-     $method_class->checkout_render($cart, \$title, \$body);
- }
- print "<title>$title</title><body>$body</body>";
+ my $template_params = $method_class->get_page_params($cart);
+ $method_class->process_post_request($cart);
 
 =cut
 
@@ -270,51 +264,6 @@
 
 =head2 Purely virtual methods
 
-=head3 checkout_process
-
-Given a cart, does whatever actions the system needs to do when using this
-method before rendering a page or redirecting the user to another page.
-
-=cut
-
-sub checkout_process { }
-
-=head3 checkout_should_redirect
-
-Given a cart, returns a boolean value indicating whether the user should be
-redirected to checkout that cart using this method.
-
-=cut
-
-sub checkout_should_redirect { 1 }
-
-=head3 checkout_redirect
-
-Given a cart, redirects the client to the page where they can proceed with
-the checkout.
-
-=cut
-
-sub checkout_redirect {
-    my ($class, $cart) = @_;
-
-    BML::redirect('/');
-}
-
-=head3 checkout_redirect
-
-Given a cart and two scalarrefs (title and body), renders a page to inform
-user how to proceed with the checkout.
-
-=cut
-
-sub checkout_render {
-    my ($class, $cart, $title, $body) = @_;
-
-    $$title = 'checkout';
-    $$body = 'checkout body';
-}
-
 =head3 get_page_params
 
 Gets cart object. Returns hashref with parameters to ~/templates/Shop/method/<method_code>.tmpl template,

Modified: trunk/htdocs/pay/index.bml
===================================================================
--- trunk/htdocs/pay/index.bml	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/htdocs/pay/index.bml	2010-10-01 10:02:01 UTC (rev 9579)
@@ -1,137 +1,4 @@
 <?_code
-    use strict;
-    use vars qw(%GET);
-
-    return BML::redirect("$LJ::SITEROOT/shop/cart.bml?cart=$GET{c}")
-        unless LJ::Request->uri eq '/shop/cart.bml';
-
-    BML::set_language_scope('/pay/index.bml');
-
-    return '';
-_code?><?_info
-NOCACHE=>1
-_info?><?page
-title=><?_code $ML{'.title2'} _code?>
-body<=
-
-<?_code
-{
-    use strict;
-    use vars qw(%COOKIE %GET);
-
-    use LJ::Widget::Payment;
-    require URI::Escape;
-
-    LJ::set_active_crumb('cart');
-
-    # Auto redirect to status if disabled
-    return BML::redirect("http://status.livejournal.org/") if $LJ::DISABLED{'recbill_shop'};
-
-    my $postrender = sub {
-        my ($ret) = @_;
-        return LJ::Widget::Shop->render(body => $ret);
-    };
-
-    my $ret;
-    my $remote = LJ::get_remote();
-
-    my $referer = URI::Escape::uri_unescape($GET{prevpage}) || BML::get_client_header('Referer');
-    my $backto;
-    if ($referer) {
-        $backto .= "<?p <a href='$referer'>&lt; $ML{'.backto'} ";
-        if ($referer =~ /vgift/) {
-            $backto.= $ML{'.backto.vg'};
-        } else {
-            $backto .= $ML{'.backto.pp'};
-        }
-        $backto .= "</a> p?>";
-    }
-
-    $ret .= $backto if $backto;
-    $ret .= "<?p $ML{'.intro2'} p?>";
-
-    my $cart = $GET{'c'} || $COOKIE{'cart'};
-    my ($payid, $anum);
-    if ($cart =~ /^(\d+)-(\d+)$/) {
-        ($payid, $anum) = ($1, $2);
-
-        $COOKIE{'cart'} ||= $cart;
-    }
-
-    # FIXME: remove after ugly hack is gone
-    if ($LJ::PAY_INCLUDE_DISKQUOTA && $GET{include}) {
-        $COOKIE{'ljpayinclude'} = $GET{include};
-    }
-
-    my $cartobj;
-    if ($payid) {
-        $cartobj = eval{ LJ::Pay::Payment->load( payid => $payid, anum => $anum ) };
-    }
-
-    if ($cartobj && $cartobj->{'userid'}) {
-        return $postrender->("<?p $ML{'.error.notloggedin'} p?>")
-            unless $remote;
-        return $postrender->("<?p " . BML::ml('.error.notyourcart', {'aopts' => "href='$LJ::SITEROOT/shop/?c=new'"}) . " p?>")
-            unless $cartobj->{'userid'} == $remote->{'userid'};
-    }
-
-    # don't let them modify the cart if they've already started
-    # any sort of checkout process
-    my $can_mod = ! $cartobj || $cartobj->can_modify;
-
-    # see if cart's dead, c=new requested, or already checked out
-    if (! $cartobj && $cart || $GET{'c'} eq "new") {
-        delete $COOKIE{'cart'};
-        undef $cartobj;
-        undef $cart;
-    }
-
-    # redirect back to the shop if there's no cart or there's no items
-    if ((! $cartobj && !$cart) ||
-        ($cartobj && scalar @{$cartobj->{items}} <= 0)) {
-	    return BML::redirect("/shop/index.bml");
-    }
-
-    # display a configurable banner if it exists
-    $ret .= ref $LJ::PAY_MARQUEE_HTML eq 'CODE' ? $LJ::PAY_MARQUEE_HTML->() : $LJ::PAY_MARQUEE_HTML . '';
-
-    $ret .= "<form action='$LJ::SITEROOT/pay/modify.bml' method='post' style='display: inline'>";
-    $ret .= LJ::html_hidden("cart", $cart);
-    $ret .= LJ::html_hidden("prevpage", $referer);
-
-    $ret .= "<div style='margin-left: 20px; margin-top: 2em'>";
-
-    $ret .= LJ::Widget::Payment->render($cartobj, {
-        'checkout' => 1,
-        'pics' => 1,
-        'remove' => $can_mod,
-    });
-    $ret .= "</div>";
-    $ret .= "<?de $ML{'.note.norefund'} de?><br /><br />";
-
-    # let 'em know if cart is paid for (if they're actually viewing a cart)
-    if ($cartobj && $cartobj->{'mailed'} ne "C") {
-        $ret .= "<?h1 $ML{'.paidfor.header'} h1?><?p " . BML::ml('.paidfor.text', {'date' => $cartobj->{'daterecv'}}) . " p?>";
-        $ret .= "<ul><input type=\"submit\" name=\"action:neworder\" value=\"$ML{'.btn.neworder'}\"></ul>";
-        $ret .= "</form>";
-        return $postrender->($ret);
-    }
-
-    # let 'em know if cart is locked
-    unless ($can_mod) {
-        $ret .= "<?h1 $ML{'.neworder.header'} h1?>";
-        $ret .= "<?p $ML{'.neworder.text'}";
-        $ret .= "<ul><input type=\"submit\" name=\"action:neworder\" value=\"$ML{'.btn.neworder'}\"></ul>";
-        $ret .= " p?></form>";
-        return $postrender->($ret);
-    }
-
-    $ret .= "</form>";
-
-    $ret .= $backto if $backto;
-    return $postrender->($ret);
-}
+    my $cart = LJ::Request->get_param('c');
+    return LJ::Request->redirect("$LJ::SITEROOT/shop/cart.bml?cart=$cart");
 _code?>
-
-<=body
-page?>

Modified: trunk/htdocs/pay/modify.bml
===================================================================
--- trunk/htdocs/pay/modify.bml	2010-10-01 09:34:33 UTC (rev 9578)
+++ trunk/htdocs/pay/modify.bml	2010-10-01 10:02:01 UTC (rev 9579)
@@ -1,425 +1 @@
-<?_info
-nocache=>1
-_info?>
-<?_code
-{
-    use strict;
-    use LJ::TimeUtil;
-
-    use vars qw(%POST %COOKIE $title $body);
-
-    # Continue shopping if they hit that button
-    return BML::redirect("/shop/") if $POST{'action:continue'};
-
-    # require POST
-    return BML::redirect("./")
-        unless LJ::did_post();
-
-    my $now = time();
-
-    ($title, $body) = ("", "");
-    my $err = sub {
-        my @err = @_;
-        $title = $ML{'Error'};
-        $body = LJ::bad_input(@err);
-        return;
-    };
-
-    my $dbh = LJ::get_db_writer();
-    my $remote = LJ::get_remote();
-    my $cart = $POST{'cart'} || $COOKIE{cart};
-    my $cartobj = eval { LJ::Pay::Payment::load_cart($cart) };
-
-    # make sure they own this cart
-    if ($cartobj && $cartobj->{'userid'}) {
-        return $err->($ML{'.error.notloggedin'})
-            unless $remote;
-        return $err->(BML::ml('.error.notyourcart', {'aopts' => "href='$LJ::SITEROOT/shop/?c=new'"}))
-            unless $cartobj->{'userid'} == $remote->{'userid'};
-    }
-
-    my $ensurecookie = sub {
-        if (! $COOKIE{'cart'} && $cart =~ /^(\d+)-(\d+)$/) {
-            $COOKIE{'cart'} = $cart;
-        }
-    };
-
-    my $ensurecart = sub {
-        if ($cartobj) {
-            # $cartobj implies valid $cart
-            $ensurecookie->();
-            return 1;
-        }
-        $cartobj = eval{ LJ::Pay::Payment::new_cart($remote) };
-        return unless $cartobj;
-        $cart = "$cartobj->{'payid'}-$cartobj->{'anum'}";
-        $ensurecookie->();
-        return 1;
-    };
-
-    # don't let them modify the cart if they've already started
-    # any sort of checkout process
-    my $can_mod = ! $cartobj || ! $cartobj->{'method'};
-
-    # new order
-    if ($POST{'action:neworder'}) {
-        delete $BML::COOKIE{'cart'};
-        return BML::redirect("/pay/?c=new&old=$cart");
-    }
-
-    # no cart... senseless action
-    if (($POST{'action:checkout'} || $POST{'action:removesel'})
-        && ! $cartobj) { return BML::redirect("/pay/"); }
-
-    # remove item(s) from cart
-    if ($POST{'action:removesel'}) {
-
-        # $cartobj is a valid object, checked above.  no need to worry about
-        # auto-vivification in this block
-
-        return $err->($ML{'.error.cantmodifycart'}) unless $can_mod;
-
-        my @remove = ();          # payitems to be removed, based on %POST submission
-
-        foreach my $it (@{$cartobj->{'items'}}) {
-            push @remove, $it if $POST{"del_$it->{'piid'}"};
-        }
-
-        $cartobj->remove_items(@remove) if @remove;
-        @remove = (); # already remove - clean list
-
-        my @errs = ();
-        my @warns = ();
-
-        # make new list to remove - payitems, which depends on removed
-        $cartobj->short_recheck_cart(\@errs, \@warns, \@remove);
-        #push @errs, '{{error}}';
-        #push @remove, LJ::Pay::Payment::PayItem::Coupon->new_memonly(rcptid => 2, subitem => 'dollaroff');
-        #push @warns, '{{warning}}';
-
-        if (@errs) {
-            $body .= "<?h2 $ML{'.errors'} h2?>";
-            $body .= join('<br>', @errs);
-        }
-
-        if (@remove) {
-
-            $body .= "<?h2 $ML{'.extrasremoved.header'} h2?>";
-            $body .= "<ul>";
-
-            # load usernames so we can report them below
-            my $users = LJ::load_userids(map { $_->{'rcptid'} } @remove);
-            foreach my $it (@remove) {
-                $body .= "<li>" . LJ::ljuser($users->{$it->{'rcptid'}}) . " - ";
-                $body .= $it->product_name("short") . "</li>";
-            }
-            $body .= "</ul>";
-
-            $cartobj->remove_items(@remove);
-        }
-
-        if (@warns) {
-            $body .= "<?h2 $ML{'.warns'} h2?>";
-            $body .= join('<br>', @warns);
-        }
-
-        if (@errs or @remove or @warns) {
-            $body .= "<form method='get' action='/pay/'>";
-            $body .= LJ::html_hidden('c', $cart);
-            $body .= "<p align='center'>" . LJ::html_submit($ML{'.btn.acknowledged'}) . "</p>";
-            $body .= "</form>";
-            return;
-        }
-
-        my $prevpage = '';
-        if ($POST{prevpage}){
-            require URI::Escape;
-            $prevpage = "&prevpage=" . URI::Escape::uri_escape($POST{prevpage});
-        }
-
-        return BML::redirect("/pay/?c=$cart$prevpage");
-    }
-    # end removesel block
-
-    # checkout
-    if ($POST{'action:checkout'}) {
-        # $cartobj is a valid object, checked above.  no need to worry about
-        # auto-vivification in this block
-
-        my $paymeth         = $POST{'paymeth'};
-        my $cart_has_coppa  = LJ::Pay::Payment::PayItem::Coppa->present_in($cartobj);
-        my $remote          = LJ::get_remote();
-        
-        ## pre-checks: cart status
-        return $err->("Can't check-out already processed cart")
-            unless $cartobj->get_used eq 'C';
-
-        ## pre-checks: cart owner/remote user
-        if (!$cartobj->get_userid && $remote) {
-            ## user has logged-in after filling cart
-            ## TODO: this block should be moved into $cartobj->some_method
-            $dbh->do("UPDATE payments SET userid=? WHERE payid=? ",
-                     undef, $remote->{'userid'}, $cartobj->{'payid'});
-            $cartobj->set_userid($remote->{'userid'});
-        } else {
-            ## either both $cart_owner and $remote must be empty, or they must be the same user
-            my $cart_owner = $cartobj->get_userid;
-            return $err->("This is not your cart ('$cart_owner', '$remote->{userid}')")
-                unless (!$cart_owner && !$remote) || $cart_owner==$remote->{userid};
-        }
-
-        ## pre-check: verify that selected payment method is valid
-        $paymeth = 'free' if $cartobj->{'amount'} == 0 && !$cart_has_coppa;
-
-        ## Underage users can buy carts with COPPA only
-        if ($remote && $remote->underage && !$cart_has_coppa) {
-            return $err->(BML::ml('.error.underage', {
-                'aopts' => "href='$LJ::SITEROOT/legal/coppa.bml'"
-            }));
-        }
-
-        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)
-            unless $meth_class->suitable_for($cartobj);
-
-        ## coppa can be paid by credit card only
-        return $err->($ML{'.error.invalidpaymentmethodforage'}) if
-            $paymeth ne 'cc' && $cart_has_coppa;
-
-        # open proxy check (disabled if remote has allow_pay set or method is yandex money)
-        unless (($remote && $remote->prop('allow_pay') eq 'Y') || $meth_class->allow_open_proxy) {
-            my $remote_ip = LJ::get_remote_ip();
-            if (LJ::is_open_proxy($remote_ip)) {
-                $title = $ML{'.openproxy.title'};
-                $body = BML::ml('.openproxy.text', {'ip' => $remote_ip});
-                return;
-            }
-        }
-
-        # verify cart items (check for items that have been invalidated since adding)
-        my @errs = ();
-        if (!$cartobj->is_valid_cart(\@errs)) {
-            $title = $ML{'Sorry'};
-            $body .= BML::ml('.error.invalidcart_new', {'aopts' => "href='$LJ::SITEROOT/pay/?c=new'"});
-            return $err->( join("<br/>", @errs) );
-        }
-
-        ## All checks are done,
-        $dbh->do("UPDATE payments SET method=? WHERE payid=? AND used='C'",
-                 undef, $paymeth, $cartobj->{'payid'});
-
-        # for debugging, log the browser
-        my $ua = BML::get_client_header("User-Agent");
-        $cartobj->payvar_add("browser", $ua) if $ua;
-
-        # log uniq
-        my $uniq = LJ::Request->notes('uniq');
-        $cartobj->payvar_add("uniq", LJ::TimeUtil->mysql_time() . " - $uniq") if $uniq;
-
-        # clear the cookie before we redirect
-        delete $BML::COOKIE{'cart'};
-
-        $meth_class->checkout_process($cartobj);
-        if ($meth_class->checkout_should_redirect($cartobj)) {
-            return $meth_class->checkout_redirect($cartobj);
-        } else {
-            $meth_class->checkout_render($cartobj, \$title, \$body);
-            return;
-        }
-    }
-    # end checkout block
-
-    my $msg_already_out = BML::ml('.error.alreadycheckedout', {'aopts1' => "href='$LJ::SITEROOT/pay/?c=$cart'", 'aopts2' => "href='$LJ::SITEROOT/pay/?c=new&amp;old=$cart'"});
-
-    # add coupon to cart
-    if ($POST{'action:coupon'}) {
-        return $err->($msg_already_out) unless $can_mod;
-        return $err->($ML{'.error.cantaddcoupontoemptyorder'})
-            unless $cartobj;
-
-        my $coupon = $POST{'coupon'};
-        return $err->($ML{'.error.invalidcouponformat'}) unless $coupon =~ /^(\d+)-(.+)$/;
-        my ($cpid, $auth) = ($1, $2);
-        return $err->($ML{'.error.invalidcoupon'}) if $auth =~ /^-*$/;
-
-        my $item =  LJ::Pay::Payment::PayItem::Coupon->new_memonly(
-            'tokenid' => $cpid,
-            'token' => $coupon,
-            'rcptid' => 0,
-        );
-
-        my @errs;
-        my $can_add = $item->can_belong_to($cartobj, \@errs, undef, 'additem');
-        return $err->(join('<br>', @errs)) if @errs; # now can be only one error
-        return BML::redirect("/pay/?c=$cart") unless $can_add; # there are one silent error (duplicate insertion of one coupon)
-
-        my $added = $cartobj->add_item_to_cart($item);
-        return $err->(BML::ml('.error.cantaddcoupon', {'errormsg' => LJ::last_error()})) unless $added;
-
-        # mark coupon as used by this cart
-        $item->mark_coupon_as_used($cartobj);
-
-        return BML::redirect("/pay/?c=$cart");
-    }
-
-    # add item to cart
-    if ($POST{'action:additem'}) {
-        return $err->($msg_already_out) unless $can_mod;
-
-        $ensurecart->() or return $err->(BML::ml('.error.cantcreatecart', {'errormsg' => $@}));
-
-        # itemname-subitem?-qty, subitem is optional
-        my ($itemname, $subitem, $qty) = split(/\-/, $POST{'item'});
-        unless ($qty) {
-            $qty = $subitem;
-            undef $subitem unless $POST{'subitem'};
-        }
-        $subitem = $POST{'subitem'} if $POST{'subitem'};
-
-        ### Decide recipient
-
-        my ($rcptuser, $rcptid);
-        if ($POST{'for'} eq "remote") {
-            return $err->($ML{'.error.notloggedinpaying'}) unless $remote;
-            $rcptid = $remote->{'userid'};
-            $rcptuser = $remote;
-        } elsif ($POST{'for'} eq "other") {
-            my $ou = LJ::load_user($POST{'otheruser'});
-            return $err->($ML{'.error.nousernamegiven'}) if $POST{'otheruser'} eq "";
-            return $err->(BML::ml('.error.cantfinduser', {'user' => LJ::ehtml($POST{'otheruser'})})) unless $ou;
-            return $err->($ML{'.error.cantbuyforsyn'})
-                if $ou->{'journaltype'} eq 'Y';
-            return $err->($ML{'.error.cantbuyforrenamed'})
-                if $ou->{'journaltype'} eq 'R';
-            return $err->(BML::ml('.error.cantbuyduetoaccountstatus', {'user' => LJ::ljuser($ou)}))
-                unless $ou->is_visible || $ou->is_memorial;
-
-            $rcptid = $ou->{'userid'};
-            $rcptuser = $ou;
-
-            # don't let them easily check to see if they're blocked
-            unless ($remote && $remote->{'user'} eq $ou->{'user'}) {
-                my $pay_user = $remote ? $remote->{'user'} : 'anonymous';
-                my $pay_userid = $remote ? $remote->{'userid'} : undef;
-                if (LJ::sysban_check('pay_user', $ou->{'user'})) {
-                    LJ::sysban_note($pay_userid,
-                                    "Gift blocked based on user",
-                                    { 'item' => $itemname,
-                                      'pay_user' => $pay_user,
-                                      'rcpt_user' => $ou->{'user'},
-                                      'cart' => $cart });
-                      return $err->(BML::ml('.error.cantbuygifts', {'user' => LJ::ljuser($ou->{'user'})}));
-                  }
-            }
-
-        }
-
-        return $err->($ML{'.error.norecipientgiven'}) unless $rcptid;
-
-        my $item = LJ::Pay::Payment::PayItem->new_memonly(item => $itemname, subitem => $subitem, qty => $qty, rcptid => $rcptid,
-                                                          anon => $POST{'anongift'} ? 1 : 0);
-
-        return BML::redirect("/pay/?c=$cart") unless $item; # very bad params?! even object construction is impossible...
-
-        ### Decide pricing/qty information depending on item type
-        $item->calculate_price($POST{for} eq "other" ? 1 : 0, $cartobj); # safe function, we can use it before early verification
-
-        # vgift are added through LJ::Widget::IPPU::AddVGift
-        # so, we have no check or set for vgift_note payitem prop
-        # even more, we do not allow vgifts to have giveafter for remoteid == rcpt_id
-
-        my @errs;
-        my @warns;
-        my $warn_ref = $POST{'action:additem:confirm'} ? undef : \@warns; # user have seen warning already? skip it now...
-        my $can_be_added = $item->can_belong_to($cartobj, \@errs, $warn_ref, 'additem');
-        return BML::redirect("/pay/?c=$cart") if not $can_be_added and not @errs; # nothing to say? draw the cart silently
-        return $err->(@errs) unless $can_be_added;
-
-        # Ignore 'give after' date when remote user and recipient are the same.
-        delete $POST{'giveafter_yyyy'}
-            if $remote && $item->{'rcptid'} == $remote->{'userid'} && $POST{'giveafter_yyyy'};
-
-        if ($POST{'giveafter'} =~ /^\d+$/) {
-            $item->{'giveafter'} = $POST{'giveafter'} + 0;
-        } else {
-            my $err_msg = $item->set_giveafter($POST{giveafter_yyyy}, $POST{giveafter_mm}, $POST{giveafter_dd}, $rcptuser->timezone);    
-            return $err->($err_msg) if $err_msg;
-        }
-
-        if (@warns) {
-
-            # fixing for user possibly changed giveafter
-            $POST{'giveafter'} = $item->{'giveafter'};
-
-            # pass on post variables
-            $body .= "<form method='post' action='modify.bml'>";
-            $body .= LJ::html_hidden( map { $_ => $POST{$_} }
-                                      qw(otheruser paymeth action:additem for item subitem cart
-                                         giveafter giveafter_yyyy giveafter_mm giveafter_dd anongift) );
-
-            # explain warning condition (most times it is expiration of paid account)
-            $body .= join('<br>', @warns);
-            $body .= "<p align='center'>" . LJ::html_submit('action:additem:confirm', $ML{'.btn.acknowledged'}) . "</p>";
-            $body .= "</form>";
-
-            return;
-        }
-
-        # add the item
-        my $added = $cartobj->add_item_to_cart($item);
-        return $err->(BML::ml('.error.cantadditem', {'errormsg' => LJ::last_error()})) unless $added;
-
-        if ($item->should_recheck_cart) {
-            my @remove = ();
-
-            $cartobj->short_recheck_cart(\@errs, \@warns, \@remove);
-            #push @errs, '{{error}}';
-            #push @remove, LJ::Pay::Payment::PayItem::Coupon->new_memonly(rcptid => 2, subitem => 'dollaroff');
-            #push @warns, '{{warning}}';
-
-            if (@errs) {
-                $body .= "<?h2 $ML{'.errors'} h2?>";
-                $body .= join('<br>', @errs);
-            }
-
-            if (@remove) {
-
-                $body .= "<?h2 $ML{'.extrasremoved.header'} h2?>";
-                $body .= "<ul>";
-
-                # load usernames so we can report them below
-                my $users = LJ::load_userids(map { $_->{'rcptid'} } @remove);
-                foreach my $it (@remove) {
-                    $body .= "<li>" . LJ::ljuser($users->{$it->{'rcptid'}}) . " - ";
-                    $body .= $it->product_name("short") . "</li>";
-                }
-                $body .= "</ul>";
-
-                $cartobj->remove_items(@remove);
-            }
-
-            if (@warns) {
-                $body .= "<?h2 $ML{'.warns'} h2?>";
-                $body .= join('<br>', @warns);
-            }
-
-            if (@errs or @remove or @warns) {
-                $body .= "<form method='get' action='/pay/'>";
-                $body .= LJ::html_hidden('c', $cart);
-                $body .= "<p align='center'>" . LJ::html_submit($ML{'.btn.acknowledged'}) . "</p>";
-                $body .= "</form>";
-                return;
-            }
-        }
-
-        return BML::redirect("/pay/?c=$cart");
-    }
-    # end add item block
-
-}
-_code?><?page
-title=><?_code return $title; _code?>
-body=><?_code return $body; _code?>
-page?>
+<?_code return LJ::Request->redirect("$LJ::SITEROOT/shop/"); _code?>

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