diff --git a/bin/upgrading/proplists.dat b/bin/upgrading/proplists.dat index 72244ebe00..763372773c 100644 --- a/bin/upgrading/proplists.dat +++ b/bin/upgrading/proplists.dat @@ -1142,6 +1142,14 @@ userproplist.shop_points: multihomed: 0 prettyname: How many shop points the user has available +userproplist.shop_refund_time: + cldversion: 0 + datatype: num + des: Unix time at which a refund to points was last applied to this account + indexed: 0 + multihomed: 0 + prettyname: Last refund time + userproplist.sidx_bdate: cldversion: 0 datatype: char diff --git a/cgi-bin/DW/Controller/Shop.pm b/cgi-bin/DW/Controller/Shop.pm index 2f7aeac44a..819da5e75d 100644 --- a/cgi-bin/DW/Controller/Shop.pm +++ b/cgi-bin/DW/Controller/Shop.pm @@ -334,8 +334,9 @@ sub shop_refund_to_points_handler { $rv->{status} = DW::Pay::get_paid_status( $rv->{remote} ); $rv->{rate} = DW::Pay::get_refund_points_rate( $rv->{remote} ); $rv->{type} = DW::Pay::get_account_type_name( $rv->{remote} ); + $rv->{can_refund} = DW::Pay::can_refund_points( $rv->{remote} ); - if ( ref $rv->{status} eq 'HASH' && $rv->{rate} > 0 ) { + if ( $rv->{can_refund} && ref $rv->{status} eq 'HASH' && $rv->{rate} > 0 ) { $rv->{blocks} = int($rv->{status}->{expiresin} / (86400 * 30)); $rv->{days} = $rv->{blocks} * 30; $rv->{points} = $rv->{blocks} * $rv->{rate}; @@ -343,7 +344,7 @@ sub shop_refund_to_points_handler { my $r = DW::Request->get; return DW::Template->render_template( 'shop/refundtopoints.tt', $rv ) - unless $r->did_post; + unless $r->did_post && $rv->{can_refund}; # User posted, so let's refund them if we can. die "Should never get here in a normal flow.\n" @@ -358,6 +359,7 @@ sub shop_refund_to_points_handler { $rv->{remote}->give_shop_points( amount => $rv->{points}, reason => sprintf('refund %d days of %s time', $rv->{days}, $rv->{type}) ) or die "Failed to refund points.\n"; + $rv->{remote}->set_prop( "shop_refund_time", time() ); DW::Pay::update_paid_status( $rv->{remote}, expiretime => $rv->{status}->{expiretime} - ($rv->{days} * 86400) ); diff --git a/cgi-bin/DW/Pay.pm b/cgi-bin/DW/Pay.pm index fbb9d59f8f..f4d46aecee 100644 --- a/cgi-bin/DW/Pay.pm +++ b/cgi-bin/DW/Pay.pm @@ -7,7 +7,7 @@ # Authors: # Mark Smith # -# Copyright (c) 2008-2009 by Dreamwidth Studios, LLC. +# Copyright (c) 2008-2013 by Dreamwidth Studios, LLC. # # This program is free software; you may redistribute it and/or modify it under # the same terms as Perl itself. For a copy of the license, please reference @@ -283,6 +283,24 @@ sub get_refund_points_rate { return $LJ::CAP{$typeid}->{_refund_points} || 0; } + +################################################################################ +# DW::Pay::can_refund_points +# +# ARGUMENTS: uuserid +# +# uuserid required user object or userid to get refundable status of +# +# RETURN: 1/0 +# +sub can_refund_points { + my $u = LJ::want_user( $_[0] ); + return 0 unless LJ::isu( $u ); + + my $secs_since_refund = time() - ( $u->prop( "shop_refund_time" ) || 0 ); + return $secs_since_refund > 86400 * 30 ? 1 : 0; +} + ################################################################################ # DW::Pay::get_account_type_name # diff --git a/views/shop/refundtopoints.tt b/views/shop/refundtopoints.tt index 241cfe864f..659b397b3f 100644 --- a/views/shop/refundtopoints.tt +++ b/views/shop/refundtopoints.tt @@ -12,16 +12,20 @@

[% '.about' | ml(sitename = site.nameshort) %]

-

[% '.about2' | ml %]

+

[% '.about3' | ml %]

-[% IF rate == 0 %] +[% IF NOT rate %]

[% '.noteligible' | ml %]

-[% ELSIF points == 0 %] +[% ELSIF NOT points %]

[% '.toofew' | ml %]

+[% ELSIF NOT can_refund %] + +

[% '.toosoon' | ml %]

+ [% ELSE %]

[% '.refund' | ml(sitename = site.nameshort, points = points, days = days, type = type) %]

diff --git a/views/shop/refundtopoints.tt.text b/views/shop/refundtopoints.tt.text index 83584f6a29..cabbc295c2 100644 --- a/views/shop/refundtopoints.tt.text +++ b/views/shop/refundtopoints.tt.text @@ -1,7 +1,7 @@ ;; -*- coding: utf-8 -*- .about=This page allows you to convert your personal account's paid time back to [[sitename]] Points. -.about2=Exchanges can only be done if you have at least 30 days of paid time. We will only convert time in multiples of 30 days. In other words, if your account has 40 days of paid time left, this page will let you get an exchange for only 30 days of that. +.about3=Exchanges can only be done if you have at least 30 days of paid time, and can only be done once every 30 days. We will only convert time in multiples of 30 days. In other words, if your account has 40 days of paid time left, this page will let you get an exchange for only 30 days of that. .addtocart=Convert Paid Time to [[points]] Points @@ -18,3 +18,5 @@ .title=[[sitename]] Convert to Points Tool .toofew=Sorry, you have less than 30 days of paid time on your account. + +.toosoon=Sorry, you can only refund paid time once every thirty days. \ No newline at end of file