jjzjj

php - Paypal 响应获取 "Fail"

coder 2024-04-14 原文

我正在将 Paypal 整合到我的购物车中 这是我的值(value)转移表

      <h3>By Paypal</h3><hr/>
       <label>Click Here</label>
       <br/>
     <?php
      include 'controller/connection.php';
      $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
      $paypal_id = 'my-sellerID_biz@yahoo.com';                                                                                                                                $cancel_url = 'http://my-website/index.php?action=cancel';
      $return_url = 'http://my-website/store.php';
      $i = 0;
      $products = array();
      $qry = mysql_query("select * from temp_cart where tokenId='$token'");
      while ($row = mysql_fetch_array($qry)) {
      $pid = $row[0];
      $pname = $row[1];
      $qty = $row[3];
      $price = $row[4];
      $amount = $row[5];
      $products[] = array('pid' => $pid, 'pname' => $pname, 'qty' => $qty, 'price' => $price, 'amount' => $amount);
       }
    ?>
     <form action="<?php echo $paypal_url;?>" method="post">
     <input type="hidden" name="cmd" value="_cart">
     <input type="hidden" name="upload" value="1">
     <input type="hidden" name="add" value="1">
     <input type="hidden" name="business" value="<?php echo $paypal_id;?>">
             <?php
             foreach ($products as $product) {
             $i++;
              //echo $product['amount'];
              ?>
             <input type="hidden" name="item_name_<?php echo $i;?>" value="<?php echo $product['pname']?>">
             <input type='hidden' name='item_number_<?php echo $i;?>' value='<?php echo $product['pid'] ?>' />

             <input type="hidden" name="amount_<?php echo $i;?>" value="<?php echo $product['amount']?>">
            <?php
              }
             ?>

        <input type='image' src='https://www.sandbox.paypal.com/en_US/i/btn/btn_buynow_SM.gif' name='submit' style='display:{$display_button}' />
   </form>

这工作正常。 但是当我从 paypal 重定向付款后,我收到失败响应。但在我的发送箱帐户中,它显示我已完成。并显示购物车。我从 paypal 获取响应的代码是:-

<?php
session_start();

//include('connection.php');
/*
 update: 06/27/2011
  - updated to use cURL for better security, assumes PHP version 5.3
*/

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];

$pp_hostname = "www.sandbox.paypal.com"; 

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];
$auth_token = "MY API TOKEN";
$req .= "&tx=$tx_token&at=$auth_token";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
$res = curl_exec($ch);
curl_close($ch);

if(!$res){
    //HTTP ERROR
}else{
     // parse the data
    $lines = explode("\n", $res);
    $keyarray = array();
    echo $lines[0];

    echo "<br>";
    if (strcmp ($lines[0], "SUCCESS") == 0) {
       echo $lines[0];
        for ($i=1; $i<count($lines);$i++){
        list($key,$val) = explode("=", $lines[$i]);
        $keyarray[urldecode($key)] = urldecode($val);
    }
    //echo "skjdhckh";
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct




    $user_email = 'myID@gmail.com';

     $site_name = 'Company name';
     $eol = "\r\n";
     $headers  = 'MIME-Version: 1.0' . $eol;
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . $eol;
     $headers .= 'From:' . $site_name . ' <mailID@gmail.com>'. $eol;
     $headers .= 'Reply-To:' . $site_name . ' <mailID@gmail.com>' . $eol;
     $headers .= 'Return-Path:' . $site_name . ' <mailID@gmail.com>' . $eol;

     $eol = "\r\n<br />";
     $thanks_text = $eol.$eol.'Thanks!'. $eol;
    if(isset($_SESSION['user']) && ($_SESSION['token']))
        {
                include('connection.php');

                $user=$_SESSION['user'];
                $_SESSION['user']=$user;
                $token=$_SESSION['token'];
                $_SESSION['token']=$token;
                //$sub=$_SESSION['coursename'];
                date_default_timezone_set('Australia/Melbourne'); 
                $date = date('y-m-d h:i:s a', time());
                $qry="update allorder set status='completed',date='$date'  where token='$token' and name1='$user'";
                $run_qry=mysql_query($qry);

                    if($run_qry)
                    {

    /*$select_id="select email from register where username='$username'";
    $run_qry2=mysql_query($select_id);
     if($row=mysql_fetch_row($run_qry2))
    {   */
      $email=$row[0];   
      $email_tpl = 'Hello Buyer,' . $eol;
      $email_tpl .= "We have received your payment of $amount $cc." . $eol;
      $email_tpl .= "Thanks for the purchase." . $eol;
      $email_tpl .= $eol . $thanks_text;

    mail ($email, 'Payment Received', $email_tpl, $headers);
    echo $email;
    $_SESSION['username']=$user;
                ?>
                 <script language="javascript" type="text/javascript">
            // Print a message
            alert('Thank you for your purchase! your Payment was successfull. Now You can print and download your certificate');
                // Redirect to some page of the site.
            window.location = 'index.php';
                </script>
                <?php
    //}

                }

                    else
                    {
                    echo mysql_error();
                    }

    }

    }
    else if (strcmp ($lines[0], "FAIL") == 0) {
       echo 'Transaction Failed';
    }
}

?>

一切正常,但我收到失败响应。 如果我忘记了什么,请帮助我。

提前致谢

最佳答案

如果您使用沙盒进行测试,请确保您使用的是来自测试沙盒卖家账户的 PDT token 。

失败原因、4002 或 4003 响应

  • 确保回发“tx”、“cmd”和 Auth 值 要让 PayPal 返回成功和交易详情,您的 PDT 脚本需要使用命令“_notify-synch”将从返回字符串中提取的“tx”变量、您账户中的 Auth token 发布到 PayPal。

  • 无效的身份验证 token 检查 token 以确保它是准确的并且被正确传回。确保您的 token 是一个连续的字符串,并且脚本中没有换行符。对于某些语言,这可能会有所不同。

  • 确保您没有发回错误的 URL。 如果您在沙盒中进行测试,则需要确保您的脚本回发到 www.sandbox.paypal.com。如果您在实时站点上,脚本应该回发到 www.paypal.com。如果您在沙盒中进行测试并且您的脚本回传到实时站点(反之亦然),您将收到失败消息

  • 验证同一个“tx”超过 5 次 检查用户行为。获得失败的另一种方法是,如果您引用相同的“tx”超过 5 次。示例:如果用户在看到详细信息后刷新 PDT 页面 5 次,他们将在最后一次刷新时看到 FAIL。这不是错误。这样做是为了安全,因此不能无限期地访问 PDT 创建的 URL 以检索交易特定数据。

  • 无效或缺失“tx”值 “tx”值是用于收集支付信息的交易 ID。如果这无效或不存在,您将收到失败响应,因为无法检索付款数据。

未收到 PDT

  • 与付款关联的电子邮件地址 要使 PDT 正常工作,您必须确认在您的按钮代码中用作业务值(value)的电子邮件地址。如果未确认此电子邮件地址,PDT 将无法工作,因为您将看不到附加到返回 URL 的 PDT 查询字符串。

  • 确保您使用的是格式正确的返回 URL。 启用 PDT 时,用作默认自动返回 URL 的 URL 必须是有效的主机名或 IP 地址,而不是内部 Intranet URL,否则用户将不会自动返回到该 URL。确保使用有效的 URL 作为您希望用户返回的 URL,否则您将看不到预期的结果。

  • 订阅式付款按钮 PDT 不适用于订阅,因为如果您有免费试用的订阅,您将不会在返回页面/PDT 过程中看到任何数据。这是因为 PDT 传输付款数据,如果在注册时没有付款,则说明没有要传输的付款数据。

  • 用户行为 PDT 是客户通过返回方法激活的,方法是选择返回按钮或在客户登录其 PayPal 帐户进行支付时不选择任何内容。这意味着买家可以更改返回流程或退出浏览器,并且不会传输任何数据。

关于php - Paypal 响应获取 "Fail",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15137401/

有关php - Paypal 响应获取 "Fail"的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  4. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  5. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  6. ruby - 简单获取法拉第超时 - 2

    有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url

  7. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  8. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  9. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

  10. ruby - 从 Ruby 中的主机名获取 IP 地址 - 2

    我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge

随机推荐