changelog_bot (changelog_bot) wrote in changelog,
changelog_bot
changelog_bot
changelog

[ljcom] r7526: LJSUP-4585

Committer: gproschaev
LJSUP-4585
refactor function signatures

LJ::Pay::get_item_base_price change to LJ::Pay::Payment::PayItem::get_item_base_price
Each PayItem has that method.


U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm
U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm
U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm
U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem.pm
U   branches/shop/cgi-bin/LJ/Pay/RecBill.pm
U   branches/shop/htdocs/manage/account/modify.bml
U   branches/shop/htdocs/paidaccounts/index.bml
Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm	2009-07-31 16:48:38 UTC (rev 7525)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm	2009-08-03 03:29:36 UTC (rev 7526)
@@ -124,10 +124,13 @@
 }
 
 sub get_item_base_price {
-    my ($item, $qty, $size, $is_rec, %opts) = @_;
+    my $self = shift;
+    my ($qty, $size, %opts) = @_;
+    
+    my $item = $self->item;
 
-    return undef unless LJ::Pay::is_valid_bool_bonus($item, $qty, $is_rec);
-    return $LJ::Pay::Payment::PayItem::Addon::bonus{$item}->{items}->{$qty}->{$is_rec ? 'amount_rec' : 'amount'};
+    return undef unless LJ::Pay::is_valid_bool_bonus($item, $qty, 1);
+    return $LJ::Pay::Payment::PayItem::Addon::bonus{$item}->{items}->{$qty}->{'amount_rec'};
 }
 
 sub can_be_added {
@@ -138,7 +141,7 @@
     # can't buy paid time for permanent accounts
     if ($rcptuser->in_class('perm')) {
         my $dispname = $self->product_name("short");
-        $errs_ref->[0] = BML::ml('.error.cantbuyitemforperm', {'item' => "<b>$dispname</b>"})
+        $errs_ref->[0] = BML::ml('.error.cantbuyitemforperm', {'item' => "<b>$dispname</b>"});
         return 0;
     }
 

Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm	2009-07-31 16:48:38 UTC (rev 7525)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm	2009-08-03 03:29:36 UTC (rev 7526)
@@ -218,10 +218,13 @@
 }
 
 sub get_item_base_price {
-    my ($item, $qty, $size, $is_rec, %opts) = @_;
+    my $self = shift;
+    my ($qty, $size, %opts) = @_;
 
-    return undef unless LJ::Pay::is_valid_sized_bonus($item, $size, $qty, $is_rec);
-    return $LJ::Pay::Payment::PayItem::Addon::bonus{$item}->{'items'}->{$size}->{'qty'}->{$qty}->{$is_rec ? 'amount_rec' : 'amount'};
+    my $item = $self->item;
+
+    return undef unless LJ::Pay::is_valid_sized_bonus($item, $size, $qty);
+    return $LJ::Pay::Payment::PayItem::Addon::bonus{$item}->{'items'}->{$size}->{'qty'}->{$qty}->{'amount_rec'};
 }
 
 sub can_be_added {
@@ -233,7 +236,7 @@
     # can't buy paid time for permanent accounts
     if ($rcptuser->in_class('perm')) {
         my $dispname = $self->product_name("short");
-        $errs_ref->[0] = BML::ml('.error.cantbuyitemforperm', {'item' => "<b>$dispname</b>"})
+        $errs_ref->[0] = BML::ml('.error.cantbuyitemforperm', {'item' => "<b>$dispname</b>"});
         return 0;
     }
 

Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm	2009-07-31 16:48:38 UTC (rev 7525)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm	2009-08-03 03:29:36 UTC (rev 7526)
@@ -331,17 +331,13 @@
 }
 
 sub get_item_base_price {
-    my ($item, $qty, $size, $is_rec, %opts) = @_;
+    my $self = shift;
+    my ($qty, $size, %opts) = @_;
 
-   if ($item eq 'paidacct') {
-        return undef
-            unless ref $LJ::Pay::Payment::PayItem::PaidAccount::account{$qty};
+    return undef
+        unless ref $LJ::Pay::Payment::PayItem::PaidAccount::account{$qty};
 
-        return LJ::Pay::paid_account_price( interval => $qty, rec => $is_rec, %opts );
-    }
-
-    # this shouldn't happen, we'll error loudly
-    return undef;
+    return LJ::Pay::paid_account_price( interval => $qty, rec => 1, %opts );
 }
 
 sub can_be_added {

Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem.pm	2009-07-31 16:48:38 UTC (rev 7525)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem.pm	2009-08-03 03:29:36 UTC (rev 7526)
@@ -51,6 +51,20 @@
     return $class->load($self->{piid});
 }
 
+sub get_list_item_base_price {
+    my $self = shift;
+    my $amount = shift;
+    my %list = @_;
+
+    my %price = ();
+    foreach my $item_name (keys %list) {
+        my $item = LJ::Pay::Payment::PayItem->new_memonly(item => $list{$item_name}[0]);
+        $price{$item_name} = $item->get_item_base_price( $amount, $list{$item_name}[1] );
+    }
+
+    return \%price;
+}
+
 sub new_memonly {
     my $self = shift;
     my %args = @_;
@@ -61,7 +75,6 @@
         return $child_class->new_memonly(%args)
             if $child_class;
     }
-
     # here and below - default constructor for inheritance
 
     unless (ref $self) { # $self eq 'LJ::Pay::Payment::PayItem' or subclass

Modified: branches/shop/cgi-bin/LJ/Pay/RecBill.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/RecBill.pm	2009-07-31 16:48:38 UTC (rev 7525)
+++ branches/shop/cgi-bin/LJ/Pay/RecBill.pm	2009-08-03 03:29:36 UTC (rev 7526)
@@ -1639,14 +1639,16 @@
 
     return _err("no size specified for sized bonus")
         if LJ::Pay::is_bonus($item, 'sized') && ! $size;
-
+ 
     my $price = 0.0;
     my $now = time();
     my $exptime = $now;
 
     # find base price for this item at the current bill interval
-    $price = LJ::Pay::get_item_base_price
-        ($item, $bill_interval, $size, 'rec');
+    my $item_obj = LJ::Pay::Payment::Payitem->new_onlymem(
+        item => $item,
+    );
+    $price = $item_obj->get_item_base_price($bill_interval, $size);
     _debug("item base price ($item, $bill_interval, $size) => $price");
     return _err("unable to calculate item base price" => $item)
         unless defined $price;
@@ -1783,8 +1785,11 @@
 
         # find the base price for this item and the given
         # interval (recurring)
-        my $base_price = LJ::Pay::get_item_base_price
-            ($it->{name}, $interval, $it->{size}, 'rec');
+        my $item = LJ::Pay::Payment::Payitem->new_onlymem(
+            item => $it->{name},
+        );
+        my $base_price = $item->get_item_base_price
+            ($interval, $it->{size});
         return _err("unable to calculate item base price" => $it->{name})
             unless defined $base_price;
 
@@ -2096,8 +2101,11 @@
 
         my $size = $items{$item}->{size};
 
-        $full_price += LJ::Pay::get_item_base_price
-            ($item, $bill_interval, $size, 'rec');
+        my $item_obj = LJ::Pay::Payment::Payitem->new_onlymem(
+            item => $item,
+        );
+        $full_price += $item_obj->get_item_base_price
+            ($bill_interval, $size);
     }
 
     foreach (1..24) {
@@ -2121,8 +2129,11 @@
     foreach my $it ($self->get_items) {
         next unless $it->get_recflag eq 'on';
 
-        $full_price += LJ::Pay::get_item_base_price
-            ($it->{name}, $self->{bill_interval}, $it->{size}, 'rec');
+        my $item_obj = LJ::Pay::Payment::Payitem->new_onlymem(
+            item => $it->{name},
+        );
+        $full_price += $item_obj->get_item_base_price
+            ($self->{bill_interval});
     }
 
     return $full_price;
@@ -2144,8 +2155,9 @@
 
     my $u = $self->{u};
 
-    my $price = LJ::Pay::get_item_base_price
-        ($item, $bill_interval, $size, 'rec');
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly( item => $item );
+    my $price = $item_obj->get_item_base_price
+        ($bill_interval, $size);
     return _err("unable to calculate base price for item" => $item)
         unless defined $price;
 
@@ -2185,8 +2197,9 @@
     my $it = $self->get_item($item)
         or return _err("invalid item");
 
-    my $price = LJ::Pay::get_item_base_price
-        ($item, $self->{bill_interval}, $it->{size}, 'rec', user => $u, expiring => 1);
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly( item => $item );
+    my $price = $item_obj->get_item_base_price
+        ($self->{bill_interval}, $it->{size}, user => $u, expiring => 1);
     return _err("unable to calculate base price for item" => $item)
         unless defined $price;
 

Modified: branches/shop/htdocs/manage/account/modify.bml
===================================================================
--- branches/shop/htdocs/manage/account/modify.bml	2009-07-31 16:48:38 UTC (rev 7525)
+++ branches/shop/htdocs/manage/account/modify.bml	2009-08-03 03:29:36 UTC (rev 7526)
@@ -81,16 +81,14 @@
     my %prices;
     my @disk_sizes = keys %{$LJ::Pay::bonus{diskquota}->{items}};
 
+    ## Hash as { Item => [ Item, PriceName], ... }
+    my %price_keys = ( 'paidacct' => ['paidacct', undef], 'userpic' => ['userpic', undef] );
     # possible bill intervals -- 'master' list is for paidacct
+    foreach my $ds (@disk_sizes) {
+        $price_keys{"disk_$ds"} = ['diskquota', $ds];
+    }
     foreach (grep { defined $LJ::Pay::account{$_}->{amount_rec} } keys %LJ::Pay::account) {
-        $prices{$_} = {
-            paidacct => LJ::Pay::get_item_base_price( 'paidacct', $_, undef, 'rec' ),
-            userpic  => LJ::Pay::get_item_base_price( 'userpic', $_, undef, 'rec' ),
-        };
-        foreach my $ds (@disk_sizes) {
-            $prices{$_}->{"disk_$ds"} =
-                LJ::Pay::get_item_base_price( 'diskquota', $_, $ds, 'rec' );
-        }
+        $prices{$_} = LJ::Pay::Payment::PayItem->get_list_item_base_price ($_, %price_keys);
     }
 
     # make pricing info available to JS

Modified: branches/shop/htdocs/paidaccounts/index.bml
===================================================================
--- branches/shop/htdocs/paidaccounts/index.bml	2009-07-31 16:48:38 UTC (rev 7525)
+++ branches/shop/htdocs/paidaccounts/index.bml	2009-08-03 03:29:36 UTC (rev 7526)
@@ -26,7 +26,8 @@
     $ret .= "<td><b>$ML{'.costs.rates.time.header'}</b></td><td><b>$ML{'.costs.rates.amount.header'}</b></td><td> </td></tr>";
 
     foreach my $prid (sort { $b <=> $a } keys %LJ::Pay::account) {
-        my $price = LJ::Pay::get_item_base_price( 'paidacct', $prid, undef, 1 );
+        my $item = LJ::Pay::Payment::PayItem->new_memonly( item => 'paidacct' );
+        my $price = $item->get_item_base_price( $prid, undef );
         my $asterix = "*" if $prid == 12 || $prid == 1;
         $ret .= "<tr valign='middle'><td><a href='/manage/payments/modify.bml?bill_when=$prid'>" . BML::ml($LJ::Pay::account{$prid}->{'name'}, {'num' => $prid}) . "</a></td><td align='right'>\$$price USD$asterix</td><td><form style='display:inline' action='/manage/payments/modify.bml'><input type='hidden' name='bill_when' value='$prid' /><input type='submit' value='$ML{'.costs.rates.btn.order'}' /></form></td></tr>";
     }

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