ssafronova (ssafronova) wrote in changelog,
ssafronova
ssafronova
changelog

[ljcom] r7537: LJSUP-4203: Userpic Add-on - LJSUP-4457:...

Committer: ssafronova
LJSUP-4203: Userpic Add-on - LJSUP-4457: move bulk code to class structure - cleaning recurrent billing code
removed unneeded checks
removed doubling algorithm

U   branches/shop/cgi-bin/LJ/Pay/RecBill/Item.pm
U   branches/shop/cgi-bin/LJ/Pay/RecBill/Log.pm
U   branches/shop/cgi-bin/LJ/Pay/RecBill/PendTime.pm
U   branches/shop/cgi-bin/LJ/Pay/RecBill.pm
Modified: branches/shop/cgi-bin/LJ/Pay/RecBill/Item.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/RecBill/Item.pm	2009-08-04 10:12:01 UTC (rev 7536)
+++ branches/shop/cgi-bin/LJ/Pay/RecBill/Item.pm	2009-08-04 11:05:16 UTC (rev 7537)
@@ -91,8 +91,9 @@
 
     my ($uuid, $itemname) = @_;
     my $userid = LJ::want_userid($uuid);
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $itemname);
     return _err("invalid item name")
-        unless $itemname eq 'paidacct' || LJ::Pay::is_bonus($itemname);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     my $dbh = _get_dbh()
         or return _err("unable to connect to global db master");
@@ -122,9 +123,7 @@
         return _err($dbh->errstr) if $dbh->err;
 
         _debug("daysleft: $args{daysleft}");
-
         _debug("itemname: $itemname, size: $args{size}");
-        $args{size} = undef unless LJ::Pay::is_bonus($itemname, 'sized');
     }
 
     return LJ::Pay::RecBill::Item->new(%args);
@@ -238,11 +237,12 @@
         or return _err("invalid arguments");
 
     my $invalid = sub { _err("invalid value for element" => @_) };
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $self->{name});
 
     return $invalid->('userid')
         unless $self->{userid} > 0;
     return $invalid->('name')
-        unless ($self->{name} eq 'paidacct' || LJ::Pay::is_bonus($self->{name}));
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     my $is_bonus = LJ::Pay::is_bonus($self->{name});
     my $is_sized = LJ::Pay::is_bonus($self->{name}, 'sized');

Modified: branches/shop/cgi-bin/LJ/Pay/RecBill/Log.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/RecBill/Log.pm	2009-08-04 10:12:01 UTC (rev 7536)
+++ branches/shop/cgi-bin/LJ/Pay/RecBill/Log.pm	2009-08-04 11:05:16 UTC (rev 7537)
@@ -118,6 +118,7 @@
         or return _err("invalid arguments");
 
     my $invalid = sub { _err("invalid value for element" => @_) };
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $self->{item});
 
     return $invalid->('userid')
         unless $self->{userid} > 0;
@@ -125,7 +126,7 @@
         unless $self->{payid} > 0;
 
     return $invalid->('item')
-        unless ($self->{item} eq 'paidacct' || LJ::Pay::is_bonus($self->{item}));
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     return $invalid->('old_exptime')
         unless $self->{old_exptime} =~ /^\d+$/;

Modified: branches/shop/cgi-bin/LJ/Pay/RecBill/PendTime.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/RecBill/PendTime.pm	2009-08-04 10:12:01 UTC (rev 7536)
+++ branches/shop/cgi-bin/LJ/Pay/RecBill/PendTime.pm	2009-08-04 11:05:16 UTC (rev 7537)
@@ -89,8 +89,9 @@
 
     my ($uuid, $itemname, $ident) = @_;
     my $userid = LJ::want_userid($uuid);
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $itemname);
     return _err("invalid item name")
-        unless $itemname eq 'paidacct' || LJ::Pay::is_bonus($itemname);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
     return _err("invalid ident")
         unless length $ident > 0 && length $ident <= 25;
 
@@ -159,10 +160,12 @@
 
     my $invalid = sub { _err("invalid value for element" => @_) };
 
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $self->{itemname});
+
     return $invalid->('userid')
         unless $self->{userid} > 0;
     return $invalid->('itemname')
-        unless $self->{itemname} eq 'paidacct' || LJ::Pay::is_bonus($self->{itemname});
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
     return $invalid->('ident')
         unless length $self->{ident} > 0 && length $self->{ident} <= 25;
     return $invalid->('applytime')

Modified: branches/shop/cgi-bin/LJ/Pay/RecBill.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/RecBill.pm	2009-08-04 10:12:01 UTC (rev 7536)
+++ branches/shop/cgi-bin/LJ/Pay/RecBill.pm	2009-08-04 11:05:16 UTC (rev 7537)
@@ -788,27 +788,13 @@
     # need at least a paid account to be recurring
     return 0 unless grep { $_->get_recflag eq 'on' } @{$self->{items}};
 
-    my $paidacct = $self->get_item('paidacct')
-        or return 0;
-
-    _debug("ref paidacct: " . ref($paidacct) . "");
-
     my $next_check_time = $self->get_next_check_time
         or return _err("unable to calculate next check time");
 
-    # will their paid account be expiring during the next bill interval?
-    if ($paidacct->get_recflag eq 'on' &&
-        $paidacct->get_exptime <= $next_check_time) {
-        _debug("Paid account expiring: " . $paidacct->get_recflag . ";" .
-            $paidacct->get_exptime . " <= $next_check_time");
-        return 1;
-    }
-
     # will any bonus items be expiring during the next bill interval?
-    return 1 foreach grep { LJ::Pay::is_bonus($_->get_name) &&
-                            $_->get_recflag eq 'on' &&
-                            $_->get_exptime <= $next_check_time
-                          } @{$self->{items}};
+    return 1 if scalar grep { $_->get_recflag eq 'on' &&
+                              $_->get_exptime <= $next_check_time
+                            } @{$self->{items}};
 
     # nothing to modify
     return 0;
@@ -1638,9 +1624,6 @@
 
     $bill_interval ||= $self->{bill_interval};
 
-    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;
@@ -1865,47 +1848,21 @@
 
     my @to_extend = ();
 
-    # paid account (paiduser table)
     {
-        my $paid_it = $self->get_item('paidacct')
-            or return _err("no paid account item found");
-        my $paid_exp = $paid_it->get_exptime;
-        _debug("paid_exp: $paid_exp");
-        return _err("invalid existing paid account expiration")
-            unless $paid_exp > 0;
-
-        # if the paid account is expiring before the next check will be
-        # performed, then we need to prorate the item price and bill them
-        _debug("$paid_exp < $next_check: " . ($paid_exp < $next_check) . "");
-        if ($paid_exp < $next_check) {
-
-            my $prorate_len = $next_check - _max($paid_exp, $now);
-            _debug("prorate_len: $prorate_len");
-            my $price = $self->calc_item_extension_price('paidacct', $prorate_len)
-                or return _err();
-            _debug("paidacct, price=$price");
-
-            push @to_extend, [ 'paidacct', $prorate_len, $price ];
-            _debug("push: [ 'paidacct', $next_check, $price ]");
-        }
-    }
-
-    # bonus features (paidexp table)
-    if (my @bonus_items = grep { LJ::Pay::is_bonus($_) } map { $_->{name} } @items)
-    {
-        _debug("bonus: @bonus_items");
-
         # Note: This code does not handle sized bonus feature upgrades
         #       during extension.  This logic only works to take an existing
         #       item and extend it to the end of the next billing interval.
         #       For sized bonus upgrades, upgrade/extension must be done
         #       at a higher level.
 
-        foreach my $item (@bonus_items) {
-            my $it = $self->get_item($item);
-            my $exp = $it->{exptime};
+        foreach my $it (@items) {
+            my $item = $it->get_name;
+            my $exp = $it->get_exptime;
             _debug("bonus=$item");
 
+            return _err("invalid existing paid account/addon expiration")
+                unless $exp > 0;
+
             # if the bonus feature already extends past the next check time
             # then there is no need to extend it.
             _debug("exp:$exp; next_check:$next_check");
@@ -2009,39 +1966,10 @@
 
     my @item_prices = ();
 
-    # paid account (paiduser table)
-    {
-        my $paid_exp = $items{paidacct}->{exptime};
-        _debug("next_start: " . LJ::mysql_time($next_start));
-        _debug("next_end:   " . LJ::mysql_time($next_end));
-        _debug("paid_exp:   " . LJ::mysql_time($paid_exp));
-        return _err("no paid account found") unless $paid_exp > 0;
+    return _err("no paid account found") unless $items{paidacct}->{exptime} > 0;
 
-        my $price = 0.00;
-
-        # if the paid account is expiring before the next check will be
-        # performed, then we need to prorate the item price and bill them
-        _debug("paid_exp < next_end? $paid_exp < $next_end [" . LJ::mysql_time($paid_exp) . " < " . LJ::mysql_time($next_end) . "]");
-        if ($paid_exp < $next_end) {
-            my $prorate_len = $next_end - _max($paid_exp, $next_start);
-            undef $prorate_len if $prorate_len == $period_len;
-            _debug("prorate_len: $prorate_len");
-
-            $price = $self->calc_item_prorate_price('paidacct', undef, $bill_interval, $prorate_len)
-                or return _err();
-            _debug("paidacct, price=$price");
-        }
-
-        push @item_prices, [ 'paidacct' => $price ];
-        $total_price += $price;
-    }
-
-    # bonus features (paidexp table)
-    if (my @bonus_items = grep { LJ::Pay::is_bonus($_) } keys %items) {
-
-        _debug("bonus: @bonus_items");
-
-        foreach my $item (@bonus_items) {
+    {
+        foreach my $item (keys %items) {
             my ($exp, $size, $is_rec)  = @{$items{$item}}{qw(exptime size is_rec)};
 
             # don't figure into price if item isn't recurring
@@ -2151,9 +2079,6 @@
     _debug("Args:$item, $size, $bill_interval, $prorate_len");
     return _err("invalid arguments") unless $item;
 
-    return _err("no size specified for sized bonus")
-        if LJ::Pay::is_bonus($item, 'sized') && ! $size;
-
     my $u = $self->{u};
 
     my $item_obj = LJ::Pay::Payment::PayItem->new_memonly( item => $item );
@@ -2871,8 +2796,9 @@
         unless exists $PROMO{$pr};
 
     my $item = shift;
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $item);
     return _err("invalid item" => $item)
-        unless $item eq 'paidacct' || LJ::Pay::is_bonus($item);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     my $rv = $PROMO{$pr}->{revoke_item}->($item, $self);
     return _err("unable to revoke promo" => $pr)
@@ -2904,8 +2830,9 @@
         or return _err("invalid arguments");
 
     my $item = shift;
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $item);
     return _err("invalid item" => $item)
-        unless $item eq 'paidacct' || LJ::Pay::is_bonus($item);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     my @to_revoke = @_;
     _debug("LJ::Pay::RecBill::revoke_promo_multi(@to_revoke)");
@@ -2926,8 +2853,9 @@
     my ($pr, $item, $price) = @_;
     return _err("invalid promo code")
         unless exists $PROMO{$pr};
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $item);
     return _err("invalid item" => $item)
-        unless $item eq 'paidacct' || LJ::Pay::is_bonus($item);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
     return _err("no price specified")
         unless defined $price;
 
@@ -2941,8 +2869,9 @@
     my LJ::Pay::RecBill $self = shift
         or return _err("invalid arguments");
     my ($item, $price) = @_;
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $item);
     return _err("invalid item" => $item)
-        unless $item eq 'paidacct' || LJ::Pay::is_bonus($item);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
     return _err("no price specified")
         unless defined $price;
 
@@ -2999,8 +2928,9 @@
     return _err("invalid promo code")
         unless exists $PROMO{$pr};
     my $item = shift;
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $item);
     return _err("invalid item" => $item)
-        unless $item eq 'paidacct' || LJ::Pay::is_bonus($item);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     my $rv = $PROMO{$pr}->{is_active_item}->($self, $item);
     return _err("unable to decide item activation status" => $pr)
@@ -3056,8 +2986,9 @@
         unless exists $PROMO{$pr};
 
     my $item = shift;
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $item);
     return _err("invalid item" => $item)
-        unless $item eq 'paidacct' || LJ::Pay::is_bonus($item);
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     my $action = shift;
     return _err("no action specified")
@@ -3098,8 +3029,9 @@
         or return _err("invalid arguments");
 
     my $item = shift;
-    return _err("invalid item specified" => $item)
-        unless $item eq 'paidacct' || LJ::Pay::is_bonus($item);
+    my $item_obj = LJ::Pay::Payment::PayItem->new_memonly(item => $item);
+    return _err("invalid item" => $item)
+        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
     my $action = shift;
     return _err("no action specified")

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