Editing
Portal:Payment Processing
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example Dancer Handler for PayPal IPNs== Paypal IPNs are old school webhooks that tell Paypal to hit an URL whenever you receive a payment. We will not cover how to set this up through PP, but here's a sketch snippet that will create a Dancer2 app that handles IPNs. package Application::ppipnd; use Dancer2; use HTTP::Tiny (); use Util::H2O::More qw/h2o/; our $VERSION = '1.0'; #my $PP_WEBSRC = q{<nowiki>https://www.sandbox.paypal.com/YOURTEST/webscr}</nowiki>; my $PP_WEBSRC = q{<nowiki>https://www.paypal.com/cgi-bin/webscr}</nowiki>; post '/ipn' => sub { my %body = params('body'); my $http = HTTP::Tiny->new; # handshake back to PayPal (this here you confirm it is actually from PayPal) my $resp = $http->post( $PP_WEBSRC, {%body} ); #... if you trust what $resp tells you, then process the request # save raw body $body{raw} = JSON::XS::encode_json( \%body ); # now process IPN (e.g.,...) my $ipn = h2o \%body, qw/raw txn_type subscr_id parent_txn_id option_selection1 option_selection2 txn_id first_name/; # hard pass if {txn_type} is not defined in %body if ( not $ipn->txn_type ) { printf qq{%s: %s request that contained no txn_type field. Replied as Teapot (418).\n}, INFO, REJECTED; status q{i_m_a_teapot}; #418 send_as html => q{I'm a teapot.}; } return q{ok}; # 200 OK is also required by PayPal's IPN sender to assume success }; === Notes === * PayPal IPNs require HTTPS * There is an IPN generator to test at PayPal's developer site, but you can also employ a curl script, provided you get all the IPN variables correct; see an example [https://github.com/The-Perl-Cottage-Guild/ppipnd/blob/master/curl-tests/basic-account-lifecycle.sh\ here]. * PayPal has a button generator also - see [https://www.sandbox.paypal.com/buttons/ this].
Summary:
Please note that all contributions to Perl Guilds - Getting Medieval with Perl may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Perl Guilds - Getting Medieval with Perl:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information