Web Hosting Talk







View Full Version : Business::PayPal::API Perl ReturnURL and CancelURL issues


acidhoss
01-27-2008, 03:10 AM
Howdy all,

I'm having a big problem.

I need to get this site live by the end of the week and I'm almost there, except for the fact that PayPal is barfing up errors when I try to use Business::PayPal::API and call SetExpressCheckout.

The Ack error is as follows:

[
{
'ErrorCode' => '10471',
'LongMessage' => 'ReturnURL is invalid.'
},
{
'ErrorCode' => '10472',
'LongMessage' => 'CancelURL is invalid.'
}
];

The pertinent Perl code is as follows:


## set up paypal stuff
my $pp = new Business::PayPal::API::ExpressCheckout
(
Username => 'hidden',
Password => 'hidden', ## supplied by PayPal
Signature => 'hidden', ## ditto
sandbox => 1
);

## set up a CGI param for PayPal's object
$self->param('paypal', $pp);

...



sub checkout : Runmode {

my $self = shift;

## set the template name
my $template = 'checkout.tt2';

## session object
my $session = $self->session;

my $q = $self->query;

# getting the cart data from the session
my $cart = $session->param("CART") or return undef;

## get the total
my $total_price = 0;
foreach my $price ( @{ $cart } ) {

$total_price += $price->{price};


}

my $cart_url = "?rm=view_cart";

## stuff to pass to the template
my %template_vars = (
title => 'BuyOrSell.it Storefront!: Checkout',
items => $cart,
total_price => sprintf ( "%.2f", $total_price ),
);

return $self->tt_process( $template, \%template_vars );

}

sub do_checkout : Runmode {

my $self = shift;
use Data::Dumper;
## get the shopping cart info
my $cart = $self->session->param('CART');

## calculate price (needs to go in a separate function
## get the total
my $total_price = 0;
foreach my $price ( @{ $cart } ) {

$total_price += $price->{price};


}

## URLS
my $return_url = uri_escape( "http://storefront.buyorsell.it?rm=checkout_return" );
my $cancel_url = uri_escape( "http://storefront.buyorsell.it?rm=checkout_cancel" );

## PayPal Stuff ######
my $pp = $self->param('paypal'); ## PayPal API object
my %resp = $pp->SetExpressCheckout (

OrderTotal => $total_price, ## defaults to USD
ReturnURL => $return_url,
CancelURL => $cancel_url,

);

## PayPal URLS
my $paypal_sb_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" . $resp{Token}; ## sandbox URL for development
my $paypal_live_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" . $resp{Token}; ## live URL
######################

## now redirect them to paypal
##$self->header_type('redirect');
##$self->header_add(-url=>$paypal_sb_url);
#return "Redirecting to $paypal_sb_url";
## DEBUG
return "<pre>" . Dumper(%resp) . "</pre>" . "<br />" . $return_url . "<br />" . $cancel_url;

}

sub checkout_return : Runmode {

"Yay! Checkout return URL!";

}

sub checkout_cancel : Runmode {

"Yay! Checkout cancel URL!";

}


Please, for the love of little puppy dogs and baby penguins, if you have any knowledge of said topic, help me out.

Thank you in advance.

Xeentech
01-27-2008, 04:52 AM
Just looked at my code.. when I did this I didn't escape the URL.. I'd expect that it would be a good idea to escape it, and I normally do escape URLs, but here I didn't for some reason. There are no comments in my code explaining it.. try it.

acidhoss
01-27-2008, 11:30 PM
No dice Xeentech. PayPal doesn't do much to help you.