[dw-free] Finishing up payment system
[commit: http://hg.dwscoalition.org/dw-free/rev/d48debea245b]
http://bugs.dwscoalition.org/show_bug.cgi?id=116
Fix logging to pp_log. Add stubbed out processing of IPNs. We don't do
anything with them yet, but we log them.
Patch by
mark.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=116
Fix logging to pp_log. Add stubbed out processing of IPNs. We don't do
anything with them yet, but we log them.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- cgi-bin/DW/Shop/Engine/PayPal.pm
- htdocs/shop/pp_notify.bml
-------------------------------------------------------------------------------- diff -r bbe8245e97be -r d48debea245b cgi-bin/DW/Shop/Engine/PayPal.pm --- a/cgi-bin/DW/Shop/Engine/PayPal.pm Sat Apr 25 07:09:23 2009 +0000 +++ b/cgi-bin/DW/Shop/Engine/PayPal.pm Sat Apr 25 07:40:00 2009 +0000 @@ -136,10 +136,10 @@ sub checkout_url { my $cur = 0; foreach my $item ( @{ $cart->items } ) { push @req, "L_NAME$cur" => $item->class_name, + "L_NUMBER$cur" => $cart->id . $item->id, "L_DESC$cur" => $item->short_desc, - "L_NUMBER$cur" => $cart->id . "-" . $item->id, + "L_AMT$cur" => $item->cost; "L_QTY$cur" => 1, - "L_AMT$cur" => $item->cost; $cur++; } @@ -301,12 +301,13 @@ sub _pp_req { # already done the PayPal logic and failing on logging could lead to us # taking money but not crediting accounts, etc ... if ( ref $self && ( my $ppid = $self->ppid ) ) { - my $dbh = DW::Pay::get_db_writer(); - if ( my $dbh ) { + if ( my $dbh = DW::Pay::get_db_writer() ) { $dbh->do( q{ INSERT INTO pp_log (ppid, transtime, req_content, res_content) - VALUES (?, UNIX_TIMESTAMP(), ?) + VALUES (?, UNIX_TIMESTAMP(), ?, ?) }, undef, $ppid, $reqct, $res->content ); + warn $dbh->errstr + if $dbh->err; } } @@ -314,6 +315,25 @@ sub _pp_req { } else { return $self->temp_error( 'paypal.connection' ); } +} + + +# called by someone who gets an IPN from PayPal +sub process_ipn { + my ( $class, $form ) = @_; + + # FIXME: we have to do more than just log it :-) + my $dbh = DW::Pay::get_db_writer() + or die "failed, please retry later\n"; + $dbh->do( + q{INSERT INTO pp_log (ppid, transtime, req_content, res_content) + VALUES (0, UNIX_TIMESTAMP(), ?, '')}, + undef, nfreeze( $form ) + ); + die "failed to insert\n" + if $dbh->err; + + return 1; } diff -r bbe8245e97be -r d48debea245b htdocs/shop/pp_notify.bml --- a/htdocs/shop/pp_notify.bml Sat Apr 25 07:09:23 2009 +0000 +++ b/htdocs/shop/pp_notify.bml Sat Apr 25 07:40:00 2009 +0000 @@ -22,8 +22,9 @@ return BML::redirect( "$LJ::SITEROOT/" ) unless LJ::is_enabled( 'payments' ); - DW::Pay::pp_log_notify( \%FORM ); + return "notified" + if DW::Shop::Engine::PayPal->process_ipn( \%FORM ); - return "notified"; + return "failure"; } _code?> --------------------------------------------------------------------------------
no subject
s/,$/;/
no subject