NAME

Dancer::Plugin::PaypalExpressRoutes

VERSION

Version 0.12, April 2014

CHANGES

v 0.12: updated installation files

DESCRIPTION

This is a Dancer interface for Business::PayPal::API::ExpressCheckout. It calls ExpressCheckout with the three requests involved in a transaction, and also makes available the customer data and transaction data returned in hashes from Paypal for possible use on a receipt page or logging.

CONFIGURATION

Your config.yml would contain something like this:

  plugins:
		PaypalExpressRoutes:
		  pp_id: xxx
		  pp_password: xxx
		  pp_signature: xxx
		  pp_returnurl: http://mysite.tld/paypalgetrequest
		  pp_cancelurl: http://mysite.tld

FUNCTIONS

Your site.pm would include:

use Dancer::Plugin::PaypalExpressRoutes;

and the following routes:

    post '/paypalsetrequest' => sub {
	     $pptotal = params->{'total_cost'}; # or your method
	     ppsetrequest( $pptotal );
     };

This will transfer the customer to the Paypal site. When he hits the 'confirm' button, Paypal will invoke the configured return url which will invoke the next route:

    get '/paypalgetrequest' => sub {
       ppgetrequest(); 
	   return redirect '/paypalcheckout'; # or your preferred page
     };

The paypalcheckout page should include whatever data you want the customer to see before finalising the order. Optionally you may populate the page with the details hash returned from the previous request, eg [% details.FirstName %] and so on, as found in the ppgetrequest() sub above.

     get '/paypalcheckout' => sub {
       template 'checkout/paypalcheckout', {
    	   $details = getppdetails(), # customer details
		   # order details
		  }
      };

The 'finalise order' button should then invoke the following route:

    post '/paypaldorequest' => sub  {
	
		my $ok = ppdorequest( $pp_order_total );

		if ($ok eq 'success') {
		# complete order process
		return  redirect  '/paypalreceipt'; 
			}
		else {
		  # some sort of error message or page
		}
		
		return redirect '/checkout' if ! $ppresult{Token};
                                           
	};

And this then invokes the final route to display the receipt:

     get '/paypalreceipt' => sub {
	    return template 'checkout/paypalreceipt', {
    	   $details = getppdetails(), # customer details
		   # other details to display
		   }
     };

CONVENIENCE FUNCTIONS

getppdetails(); 

will access all customer data returned in the details hash from the 'ppgetrequest' upon the customer returning from Paypal

getppresult(); 

will access all the transaction data in the results hash returned from the 'ppdorequest' finalising the transaction.

AUTHOR

Lyn St George, lyn@zolotek.net

LICENCE AND COPYRIGHT

Copyright Lyn St George

This module is free software and is published under the same terms as Perl itself.

See http://dev.perl.org/licenses/ for more information.