Php 需要关于使用paypal IPN创建自定义订单的建议/示例吗

Php 需要关于使用paypal IPN创建自定义订单的建议/示例吗,php,paypal,paypal-ipn,Php,Paypal,Paypal Ipn,我需要使用paypal的IPN在客户网站上创建订单。他为他的客户制作kydex枪套,所以我需要在订单上有多个选项。此外,交易完成后,我需要向客户以及我的客户发送一封包含发票的电子邮件。我对paypal IPN几乎没有任何经验,所以我希望这里的任何人都能为我提供任何建议、指导或示例。我在谷歌搜索时运气不太好 有两个非常好的选择,其中不包括手动操作。为什么要重新发明轮子?这方面已经有很多很好的免费例子了 将CMS与电子商务平台(drupal+ubercart或其他,wordpress+woocomm

我需要使用paypal的IPN在客户网站上创建订单。他为他的客户制作kydex枪套,所以我需要在订单上有多个选项。此外,交易完成后,我需要向客户以及我的客户发送一封包含发票的电子邮件。我对paypal IPN几乎没有任何经验,所以我希望这里的任何人都能为我提供任何建议、指导或示例。我在谷歌搜索时运气不太好

有两个非常好的选择,其中不包括手动操作。为什么要重新发明轮子?这方面已经有很多很好的免费例子了

  • 将CMS与电子商务平台(drupal+ubercart或其他,wordpress+woocommerce或其他,magento)结合使用,包括定制PayPal订购

  • PayPal建议我们这样做的方式是在他们的网站上生成一个非常复杂、完整的按钮,然后通过php copy->paste将其捕捉到客户端网站。这是一个非常确定的火(双关语)付款+选项+发票选项,直接从贝宝


  • 除非你能很快地完成帖子,否则你将在几周的时间里努力完成一些已经掌握并多次反馈给社区的东西。

    如果我是你,我会从developer.paypal.com开始,从那里你可以设置你的ipn内容并查看集成方法。简单介绍一下它的工作原理:

  • 客户从网站订购
  • 网站在重定向到paypal以确认付款时将产品信息发送到paypal
  • Paypal通知您的ipn交易信息以及您从第2步发送给他们的所有信息
  • 现在,您的ipn将要做和应该做的是: 1.检查“已验证”状态,如果是,则继续,如果不是,则不记入贷方 2.检查重复的事务,因为你应该存储这些事务,因为人们喜欢尝试在你身上拉一个快速的事务 3.检查正确的货币,因为您只想使用美元而不是日元等汇率


    现在,如果一切顺利,你可以开始赊账,从他们那里你可以向管理层和买家发送电子邮件,即使paypal也这样做

    以下是你可以遵循的步骤

    步骤1创建IPN表单。确保将IPN URL(通知URL)传递给paypal

    对于表单变量,您可以参考

    <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>
    
    $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\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $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);
    }