I want to integrate PayPal IPN and payment getaway on my website. I want my website users to be able to sell ad space through my website using PayPal. I want the payment to be from my user (Advertiser) to my user (Publisher). Here is what I have done so far ... 1. I created a sandbox account to test payments. 2. I have created the PayPal button on my website with a custom variable. All I have left is the IPN part. I searched through this forum and the PayPal developer doc but it wasn't clear. All I want is to build the IPN page. I don't understand the PHP concept of CURL. I have read the PHP doc and it doesn't explain it well. I also have searched through YouTube for toturials but didn't find anything usful. Can some one please show me how can I build the IPN page and how to update the database when a transaction is successful. Thanks a million, Farris

Dani AI

Generated

Quick summary and practical path: IPN is an asynchronous POST from PayPal to a URL you host — you must accept the POST, immediately return HTTP 200, then validate the payload by POSTing it back to PayPal (prefix the body with cmd=_notify-validate). After PayPal replies with VERIFIED you run your business checks and update the database. is right that PayPal publishes sample listeners, but focus first on the three logistics: (1) receive and acknowledge, (2) validate, (3) run idempotent processing. (developer.paypal.com)

If cURL feels unclear, here is a minimal PHP option that uses stream contexts instead (works when allow_url_fopen is enabled). Post back to the sandbox endpoint when testing, swap to the live endpoint for production.

<?php
$raw = file_get_contents('php://input');
parse_str($raw, $data);

$req = 'cmd=_notify-validate';
foreach ($data as $k => $v) { $req .= '&' . $k . '=' . urlencode($v); }

$paypal = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'; // production: https://ipnpb.paypal.com/cgi-bin/webscr
$opts = [
  'http' => [
    'method'  => 'POST',
    'header'  => "Content-Type: application/x-www-form-urlencoded\r\nUser-Agent: PHP-IPN-Listener\r\n",
    'content' => $req,
    'timeout' => 30
  ]
];
$ctx = stream_context_create($opts);
$res = @file_get_contents($paypal, false, $ctx);

if (trim($res) === 'VERIFIED') {
  // check txn_id not processed, payment_status == 'Completed',
  // receiver_email matches your account, amounts/currency match expected, then update DB.
} else {
  // log raw input for manual review
}
header("HTTP/1.1 200 OK");
exit;
?>

If file_get_contents + streams aren’t available, use PHP’s cURL extension (it’s the standard tool for server-to-server HTTP). Always set a clear User-Agent, use SSL verification, and keep a raw IPN log so you can reconcile missed notifications. (php.net)

Critical checks and marketplace note: after PayPal returns VERIFIED perform idempotent checks (avoid double-processing by storing and checking txn_id), confirm payment_status == Completed, verify receiver_email, and that mc_gross/mc_currency match your pricing before changing account state. For buyer→seller flows, Adaptive Payments (parallel/chained) is no longer available for new integrations — PayPal now expects platform/marketplace integrations to use the PayPal Commerce Platform (multiparty) or to collect payments and disburse with the Payouts API; both have onboarding/approval requirements. Plan for audit logs and reconciliation with PayPal reports. (developer.paypal.com)

Short troubleshooting checklist: use the IPN simulator and IPN History while testing, confirm your listener returns HTTP 200 within ~30s, check firewall/proxy (Cloudflare/proxies can interfere), and log every raw IPN for later reconciliation. (developer.paypal.com)

Recommended Answers

All 4 Replies

Hi, in practice this is a page that waits for a POST form submission, made by the PayPal service. An example can be found in their GitHub account:

You receive data and send it back to check if it's valid, then you can use save it.

Source:

By the way, I prefer using Guzzle instead of cURL, if you want to consider it here's the documentation:

Thanks, but I have one more question ...
Can I let my users receive money buy replacing business email with their email?
If not how can I do that?

Do you mean a payment from user A to user B without involving your account? Check the Adaptive Payments API:

Thanks a lot cereal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.