[dw-free] Fix major bug in the IPN processor that didn't verify the amount received. Fix another ma
[commit: http://hg.dwscoalition.org/dw-free/rev/1cf60d4ac4e7]
Fix major bug in the IPN processor that didn't verify the amount received.
Fix another major bug that was, in the end, because we forgot to keep
memcached carts in sync. For now, let's just not memcache them. These are
small queries, and it's worth us making sure we always get the current data.
Patch by
mark.
Files modified:
Fix major bug in the IPN processor that didn't verify the amount received.
Fix another major bug that was, in the end, because we forgot to keep
memcached carts in sync. For now, let's just not memcache them. These are
small queries, and it's worth us making sure we always get the current data.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- cgi-bin/DW/Shop/Cart.pm
- cgi-bin/DW/Shop/Engine/CheckMoneyOrder.pm
- cgi-bin/DW/Shop/Engine/PayPal.pm
- htdocs/shop/receipt.bml
-------------------------------------------------------------------------------- diff -r 0f82cd2636b7 -r 1cf60d4ac4e7 cgi-bin/DW/Shop/Cart.pm --- a/cgi-bin/DW/Shop/Cart.pm Sun May 17 17:46:00 2009 +0000 +++ b/cgi-bin/DW/Shop/Cart.pm Mon May 18 00:06:12 2009 +0000 @@ -36,8 +36,6 @@ sub get { my $uniq = LJ::UniqCookie->current_uniq or return undef; - # FIXME: we should memcache carts for people who aren't logged in - $sql = 'uniq = ? AND userid IS NULL'; @bind = ( $uniq ); @@ -47,11 +45,6 @@ sub get { # return this cart if loaded already return $u->{_cart} if $u->{_cart}; - - # see if this user has an active cart in memcache - my $cart = $u->memc_get( 'cart' ); - return $u->{_cart} = $cart - if $cart; # faaail, have to load it $sql = 'userid = ?'; @@ -75,7 +68,6 @@ sub get { my $cart = $class->_build( thaw( $dbcart->{cartblob} ) ); if ( $u ) { $u->{_cart} = $cart; - $u->memc_set( cart => $cart ); } return $cart; } @@ -226,8 +218,6 @@ sub save { sub save { my ( $self, %opts ) = @_; - my $memcache_data = $opts{no_memcache} ? 0 : 1; - # we store the payment method id in the db my $paymentmethod_id = $DW::Shop::PAYMENTMETHODS{$self->paymentmethod}->{id} || 0; @@ -242,14 +232,6 @@ sub save { # bail if error return 0 if $dbh->err; - - # also toss this in memcache - my $u = LJ::load_userid( $self->{userid} ); - if ( $memcache_data && LJ::isu( $u ) ) { - $u->memc_set( cart => $self ); - } - - # success! return 1; } @@ -335,13 +317,13 @@ sub get_item { # get/set state sub state { - my ( $self, $newstate, %opts ) = @_; + my ( $self, $newstate ) = @_; return $self->{state} unless defined $newstate; $self->{state} = $newstate; - $self->save( no_memcache => $opts{no_memcache} ); + $self->save; return $self->{state}; } @@ -349,13 +331,13 @@ sub state { # get/set payment method sub paymentmethod { - my ( $self, $newpaymentmethod, %opts ) = @_; + my ( $self, $newpaymentmethod ) = @_; return $self->{paymentmethod} unless defined $newpaymentmethod; $self->{paymentmethod} = $newpaymentmethod; - $self->save( no_memcache => $opts{no_memcache} ); + $self->save; return $self->{paymentmethod}; } @@ -363,13 +345,13 @@ sub paymentmethod { # get/set email address sub email { - my ( $self, $newemail, %opts ) = @_; + my ( $self, $newemail ) = @_; return $self->{email} unless defined $newemail; $self->{email} = $newemail; - $self->save( no_memcache => $opts{no_memcache} ); + $self->save; return $self->{email}; } diff -r 0f82cd2636b7 -r 1cf60d4ac4e7 cgi-bin/DW/Shop/Engine/CheckMoneyOrder.pm --- a/cgi-bin/DW/Shop/Engine/CheckMoneyOrder.pm Sun May 17 17:46:00 2009 +0000 +++ b/cgi-bin/DW/Shop/Engine/CheckMoneyOrder.pm Mon May 18 00:06:12 2009 +0000 @@ -100,9 +100,6 @@ sub confirm_order { } ), } ); - # delete cart from memcache - $u->memc_delete( 'cart' ) if LJ::isu( $u ); - return 2; } diff -r 0f82cd2636b7 -r 1cf60d4ac4e7 cgi-bin/DW/Shop/Engine/PayPal.pm --- a/cgi-bin/DW/Shop/Engine/PayPal.pm Sun May 17 17:46:00 2009 +0000 +++ b/cgi-bin/DW/Shop/Engine/PayPal.pm Mon May 18 00:06:12 2009 +0000 @@ -259,9 +259,6 @@ sub confirm_order { } ), } ); - # delete cart from memcache - $u->memc_delete( 'cart' ) if LJ::isu( $u ); - return 1; } @@ -281,9 +278,6 @@ sub confirm_order { sitename => $LJ::SITENAME, } ), } ); - - # delete cart from memcache - $u->memc_delete( 'cart' ) if LJ::isu( $u ); return 2; } @@ -413,11 +407,10 @@ sub process_ipn { return 1 unless $cart && $cart->state == $DW::Shop::STATE_PEND_PAID && - $cart->paymentmethod eq 'creditcardpp'; + $cart->paymentmethod eq 'creditcardpp' && $cart->display_total == $form->{payment_gross}; - # looks good, mark it paid - $cart->paymentmethod( 'creditcardpp' ); + # looks good, mark it paid so it gets processed $cart->state( $DW::Shop::STATE_PAID ); } diff -r 0f82cd2636b7 -r 1cf60d4ac4e7 htdocs/shop/receipt.bml --- a/htdocs/shop/receipt.bml Sun May 17 17:46:00 2009 +0000 +++ b/htdocs/shop/receipt.bml Mon May 18 00:06:12 2009 +0000 @@ -75,7 +75,7 @@ _c?> if ( LJ::did_post() && $POST{setpaid } ) { return "invalid form post\n" unless LJ::check_form_auth(); - $cart->state( $DW::Shop::STATE_PAID, no_memcache => 1 ); + $cart->state( $DW::Shop::STATE_PAID ); return BML::redirect( "$LJ::SITEROOT/shop/receipt?ordernum=" . $cart->ordernum ); } --------------------------------------------------------------------------------