I have implemented it recently using HTTP::Server::Simple. I think the process should be similar on Dancer2.

(Also your server's IPN URL must use HTTPS and must not contain an IP address or a port number.)

The code is something like this:
my $USE_SIMULATOR = 0; # 0 = live, 1 = sandbox / simulator my $LIVE_URL = 'https://www.paypal.com/cgi-bin/webscr'; # live my $SANDBOX_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; # s +andbox my $PAYPAL_HOST_HEADER = ($USE_SIMULATOR ? 'www.sandbox.paypal.com' : +'www.paypal.com'); my $RESPONSE_URL = ($USE_SIMULATOR ? $SANDBOX_URL : $LIVE_URL); # read POST params my $postdata = read_all ($content_length, $server->stdin_handle); my $post = (length ($postdata) > 0) ? CGI->new ($postdata)->Vars : {}; # extract some transaction details my $txn_type = $post->{txn_type}; my $txn_id = $post->{txn_id}; my $payment_status = lc ($post->{payment_status}); # respond to Paypal's initial HTTP request print "HTTP/1.1 200 OK\r\n\r\n"; # send back the original POST data with our extra field "cmd=_notify-v +alidate" to get an INVALID or VERIFIED response # this makes a new HTTP request my $ua = LWP::UserAgent->new (ssl_opts => { verify_hostname => 1 }); my $req = HTTP::Request->new ('POST', $RESPONSE_URL); $req->content_type('application/x-www-form-urlencoded'); $req->header(Host => $PAYPAL_HOST_HEADER); $postdata = 'cmd=_notify-validate&' . $postdata; $req->content($postdata); my $res = $ua->request($req); # process the response if ($res->is_error) { # connection error ... } elsif ($res->content eq 'VERIFIED') { # ok ... ( further processing ) } elsif ($res->content eq 'INVALID') { # error ... } else { # unexpected error ... }

In reply to Re: How do you use Paypal IPN with Dancer2? by lancer
in thread How do you use Paypal IPN with Dancer2? by MorayJ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.