Hi,

I am trying to make a shopping cart using paypal payment gateway.

Here is a scenario:

A customer visits my site, adds an item to the cart, clicks on the "checkout" button, he is then redirected to the paypal payment page, now would could I track if he has payed for the item?


Thanx

Dani AI

Generated

As described, the reliable way to deliver a download link automatically is to have your server receive a confirmed, server-to-server notification from PayPal and then send the link from your backend. pointed in the right direction and offered help — below is a concise, practical flow and a small PHP skeleton to make it concrete.

  1. Before redirecting a buyer to PayPal, create a local order row with a unique order_id, expected amount and status pending. Pass that order_id in PayPal’s custom or invoice field so you can match the notification back to your DB.
  2. Implement an IPN/Webhook listener on your server. On receipt, verify the notification with PayPal (do not trust the raw POST without verification). Confirm payment_status is Completed, receiver_email matches your account, mc_gross and currency match the order, and the txn_id is unused. Only then mark the order paid.
  3. Generate a one-time, time-limited download token/URL (random token, stored with expiry and single-use flag) and send it server-side (use a reliable mailer like PHPMailer rather than depending on client redirects). Update the order record and log the transaction.

A minimal PHP IPN verification skeleton:

<?php
// ipn-listener.php (trimmed)
$req = 'cmd=_notify-validate';
foreach ($_POST as $k => $v) $req .= "&$k=" . urlencode($v);

$ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$res = curl_exec($ch);
curl_close($ch);

if (strcmp(trim($res), "VERIFIED") == 0) {
    // verify payment_status, receiver_email, mc_gross, txn_id uniqueness
    // create one-time token, email download link, update DB
} else {
    // log and ignore
}
?>

Test everything in the PayPal sandbox, log raw notifications for debugging, and write your IPN handler to be idempotent (IPNs can be retried). For modern implementations consider PayPal Webhooks/REST as an alternative; see PayPal’s docs and the sandbox tools for current endpoints and best practices: PayPal IPN docs and Sandbox tools. Use HTTPS for download links, expire them, and avoid exposing direct file paths.

Recommended Answers

All 4 Replies

Hi cancer10,

I couldn't quite understand your question, are you trying to say that how will you know if the customer paid? or do you want to know how to set the paypal gateway up?

well, i am sorry for not being specific about my question.

actually i want to send a download link automatically to my customer as soon as he buys my product.

So my question would be, is there a way to tell my script that that customer has just finished with his payment and that my script would now send him the download link to his email.

I do know that paypal has a feature that allows you to do that, however I can't help you with that. you would have to sign into your paypal account and there are a list of development tools there that can help you out with what you are trying to accomplish. The paypal support are also great in this respect and will be more than happy to assist you. I am sorry I can't be much more of a help to you as I have really never had much to do with paypal.

I wish you will and best of luck:)

I can set this up for you. Message me and we can discuss it together.

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.