Allow premium paid users to buy regular paid time within fourteen days 
of their account expiring.

        Patch by fu. 

diffs (51 lines):

diff -r f4fd12b8dc1e -r a47859f5df81 cgi-bin/DW/Shop/Item/Account.pm
--- a/cgi-bin/DW/Shop/Item/Account.pm   Wed Jul 07 12:51:39 2010 +0800
+++ b/cgi-bin/DW/Shop/Item/Account.pm   Wed Jul 07 17:58:25 2010 +0800
@@ -276,7 +276,7 @@ sub can_be_added {
             # no paid time can be purchased for seed accounts
             $$errref = LJ::Lang::ml( 
'shop.item.account.canbeadded.alreadyperm', { user => $target_u->ljuser_display 
} );
             return 0;
-        } elsif ( $account_type eq 'premium' && $self->class eq 'paid' ) {
+        } elsif ( ! DW::Shop::Item::Account->allow_account_conversion( 
$target_u, $self->class ) ) {
             # premium accounts can't get normal paid time
             $$errref = LJ::Lang::ml( 
'shop.item.account.canbeadded.nopaidforpremium', { user => 
$target_u->ljuser_display } );
             return 0;
@@ -286,6 +286,26 @@ sub can_be_added {
     return 1;
 }
 
+# this checks whether we can downgrade the premium to paid
+# FIXME: a better fix for this is to have an autorenewal system, and have the 
paid time
+# applied to their account once their current premium time expires
+sub allow_account_conversion {
+    my ( $class, $u, $to ) = @_;
+
+    # no existing user; assume no previous conflicting account
+    return 1 unless LJ::isu( $u );
+
+    my $paid_status = DW::Pay::get_paid_status( $u );
+    my $from = DW::Pay::type_shortname( $paid_status->{typeid} );
+
+    # doesn't match premium => paid, so allow it
+    return 1 unless $from eq 'premium' && $to eq 'paid';
+
+    # allow if we're within two weeks of expiration
+    return 1 if $paid_status->{expiresin} <= 3600 * 24 * 14;
+
+    return 0;
+}
 
 # override
 sub conflicts {
diff -r f4fd12b8dc1e -r a47859f5df81 htdocs/shop/account.bml
--- a/htdocs/shop/account.bml   Wed Jul 07 12:51:39 2010 +0800
+++ b/htdocs/shop/account.bml   Wed Jul 07 17:58:25 2010 +0800
@@ -95,7 +95,7 @@ body<=
     $ret .= "<table class='shop-table'><tr>";
     $ret .= "<td>" . LJ::Widget::ShopItemOptions->render( option_name => 
'accttype', item => 'prem' ) . "</td>";
     $ret .= "<td>" . LJ::Widget::ShopItemOptions->render( option_name => 
'accttype', item => 'paid' ) . "</td>"
-        unless $for eq 'self' && $account_type eq 'premium';
+        if $for ne 'self' || 
DW::Shop::Item::Account->allow_account_conversion( $remote, 'paid' );
     $ret .= "</tr>";
 
     if ( DW::Pay::num_permanent_accounts_available() > 0 ) {
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to