需要有关使用paypal IPN创建自定义订单表单的建议/示例

I need to use paypal's IPN to create an order form on a client's website. He creates kydex holsters for his customers, so I need to have multiple options on the order form. In addition, I need to send an email containing an invoice to the customers, as well as my client, after the transaction is completed. I have literally ZERO experience with paypal IPN so I am looking for any advice, guidance, or examples anyone here has to offer me. I haven't had too much luck googling.

There are two really good options for this which don't include you doing it by hand. Why reinvent the wheel? Lots of really good, free examples of this exist already.

  1. Use a CMS with e-commerce platform (drupal + ubercart or other, wordpress + woocommerce or other, magento) which include custom PayPal ordering.

  2. The way PayPal recommends we do this is to generate a very complex, complete button on their website and then just snap this into a client site via php copy -> paste. This is a pretty sure-fire (pun) option for payment + options + invoicing, direct from PayPal.

Unless you're quick with POST, you'll be slogging for weeks on something that's been mastered and given back to the community several times.

If I were you I would get started at developer.paypal.com and from there you can set up your ipn stuff from there and look through the integration methods. Just a simple run down of how it works is:

  1. Client orders from the site
  2. Site sends product info over to paypal on redirection to paypal to confirm payment
  3. Paypal notifies your ipn with transaction info along with all the stuff you sent them from step 2

Now what your ipn is going to do and should do is: 1. check for "VERIFIED" status and if so continue and if not DO NOT credit 2. check for duplicate transactions because you should store these because people like to try and pull a fast one on you 3. check for the correct currency because of exchange rates you want to only use for example USD and not Yen.

Now if everything is all good in the hood you can then begin to credit and from their you can provide emails to the administration and buyer even though paypal does that as well

Here are the steps you can follow.

Step1 Create IPN Form. make sure to pass IPN URL (notify URL) to paypal.

For Form variables, you can refer https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="business" value="seller@designerfotos.com">
    <input type="hidden" name="item_name" value="hat">
    <input type="hidden" name="item_number" value="123">
    <input type="hidden" name="amount" value="15.00">
    <input type="hidden" name="first_name" value="John">
    <input type="hidden" name="last_name" value="Doe">
    <input type="hidden" name="address1" value="9 Elm Street">
    <input type="hidden" name="address2" value="Apt 5">
    <input type="hidden" name="city" value="Berwyn">
    <input type="hidden" name="state" value="PA">
    <input type="hidden" name="zip" value="19312">
    <input type="hidden" name="night_phone_a" value="610">
    <input type="hidden" name="night_phone_b" value="555">
    <input type="hidden" name="night_phone_c" value="1234">
    <input type="hidden" name="email" value="jdoe@zyzzyu.com">
    <input type="hidden" name="return" value="https//www.mysite.com/order/return">
    <input type="hidden" name="cancel_return" value="https//www.mysite.com/order/cancel" id="cancel_return">
    <input type="hidden" name="notify_url" value="https//www.mysite.com/ipn">
</form>

Step 2 Create IPN controller. For detailed understanding review https://developer.paypal.com/docs/classic/ipn/gs_IPN/

$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) { $_POST[$key] = mysql_real_escape_string($value); }         

foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

$header = ''; 
$header .= "POST /cgi-bin/webscr HTTP/1.0
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "

";
$fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

// assign posted variables to local variables

$content['payment_status']      = $_POST['payment_status'];
$content['payment_amount']      = $_POST['mc_gross'];
$content['payment_currency']    = $_POST['mc_currency'];
$content['txn_id']              = $_POST['txn_id'];
$content['receiver_email']      = $_POST['receiver_email'];
$content['payer_email']         = $_POST['payer_email'];    
$content['txn_type']            = $_POST['txn_type'];        
$content['paydate']             = date('Y-m-d H:i:s');


if (!$fp)
{
    // HTTP ERROR
}
else
{

    fputs ($fp, $header . $req);
    if (!feof($fp))
    {
        $res = fgets ($fp, 1024);

        if(strcasecmp($content['txn_type'], "subscr_payment") == 0)
        {
            //Action            
        }
        else if(strcasecmp($content['payment_status'], "Completed") == 0)
        {
            //Action            
        }
        else if(strcasecmp($content['txn_type'], "subscr_cancel") == 0)
        {
           //Action            
        }
    }
    fclose ($fp);
}