0

我昨天也有这个问题,但是对于沙盒,但有人建议我沙盒有问题,我应该用 live paypal 进行测试。

这是条件——

我有一个 Drupal 表单,我在其中收集一些数据,我从中进行查询并将其发送到带有如下 URL 的贝宝——

$form_state['redirect'] = 'https://www.paypal.com/cgi-bin/webscr?' .$query;

其中查询变量的结果携带——

cmd=_xclick&business=ctaep.austin%40gmail.com&page_style=Primary&bn=PP-DonationsBF&item_name=Membership¤cy_code=USD&no_shipping=1&tax=0&lc=US&rm=1&return=http%3A%2F%2Fctaep-test.kr001.us%2F%3Fq%3Dpaypal%2Fpayment&cancel_return=http%3A%2F%2Fctaep-test.kr001.us%2F%3Fq%3Duser%2Fregister&uname=Raj_vm&email=rajeevkr.dei%40gmail.com&user_type=General&first_name=Rajeev&last_name=Kumar&comp_name=&address1=sector+27&address2=&city=noida&state=ca&zip=201301&phone=9650361380&mobile=&fax=&amount=0.01&item_number=1

填写表格并提交后,我被转发到贝宝,我在那里付款,然后我不得不按下返回按钮(虽然我也通过查询发送了返回路径),

状态为无效,因为被调用以处理 IPN 的函数中的条件始终处于无效条件。这是代码 -

function paypal_payment_paypal_ipn_callback(){  
  header("Content-type: text/html");
  header("Expires: Wed, 29 Jan 1975 04:15:00 GMT");
  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  header("Cache-Control: no-cache, must-revalidate");
  header("Pragma: no-cache");

  watchdog('paypal', '1');


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

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

  // post back to PayPal system to validate
  $header = '';
  $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  $header .= "Host: www.paypal.com\r\n";
  $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  $fp =  fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

  if (!$fp) {
    watchdog('paypal', 'HTTP error');
  } 
  else 
  {
    fputs ($fp, $header . $req);
    watchdog('paypal-fp-else-', $header . $req);
    dpm($_POST['uname']);
    dpm($_POST['user_type']);
    while (!feof($fp)) {
      watchdog('paypal', '3');
      watchdog('pay_status',$res);      
      if (strcmp ($res, "VERIFIED") == 0) {
        watchdog("verified");
        watchdog('paypal', '4');

        //Information about you:
        $receiver_email = $_POST['business'];

        //Information about the transaction:
        $item_name = $_POST['item_name'];
        $item_number = $_POST['item_number'];
        $payment_status = $_POST['payment_status'];
        $payment_amount = $_POST['mc_gross'];
        $payment_currency = $_POST['mc_currency'];
        $txn_id = $_POST['txn_id'];
        $receiver_email = $_POST['receiver_email'];
        $payer_email = $_POST['payer_email'];

        $user_name = $_POST['uname'];
        $user_email = $_POST['email'];
        $user_type = $_POST['user_type'];
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $company_name = $_POST['comp_name'];
        $address_address_line_1 = $_POST['address1'];
        $address_address_line_2 = $_POST['address2'];
        $address_city = $_POST['city'];
        $address_state = $_POST['state'];
        $address_zip = $_POST['zip'];
        $user_phone = $_POST['phone'];
        $user_mobile = $_POST['mobile'];
        $user_fax = $_POST['fax'];        

        // process payment
        $password = user_password(8);
        $fields = array(
          'name' => $user_name,
          'mail' => $user_email,
          'pass' => $password,
          'status' => 1,
          'init' => $user_email,
          'roles' => array(
            DRUPAL_AUTHENTICATED_RID => $user_type,),
          'field_first_name' => array(
              LANGUAGE_NONE => array(
                  array('value' => $first_name))),
          'field_last_name' => array(
              LANGUAGE_NONE => array(
                  array('value' => $last_name))),
          'field_company_name' => array(
              LANGUAGE_NONE => array(
                  array('value' => $company_name))),
          'field_address_line_1' => array(
              LANGUAGE_NONE => array(
                  array('value' => $address_address_line_1))),
          'field_address_line_2' => array(
              LANGUAGE_NONE => array(
                  array('value' => $address_address_line_2))),
          'field_user_city' => array(
              LANGUAGE_NONE => array(
                  array('value' => $address_city))),
          'field_user_state' => array(
              LANGUAGE_NONE => array(
                  array('value' => $address_state))),
          'field_user_zip' => array(
              LANGUAGE_NONE => array(
                  array('value' => $address_zip))),
          'field_phone_number_' => array(
              LANGUAGE_NONE => array(
                  array('value' => $user_phone))),
          'field_mobile_number_' => array(
              LANGUAGE_NONE => array(
                  array('value' => $user_mobile))),
          'field_fax_number_' => array(
              LANGUAGE_NONE => array(
                  array('value' => $user_fax))),
       );
      $account = user_save('', $fields);
      watchdog("user registered");
      }
      elseif (stripos($res, "INVALID") == 0) {
        watchdog('Res value--', stripos($res, "INVALID"));
        watchdog('paypal', 'INVALID');
      }
      else{
        watchdog("Not Verified nor Invalid");
      }
    }
    fclose ($fp);
  }
  return 'Transaction Complete';
}

我相信,即使状态是无效的,我也应该得到我发送到那里的数据作为回报,但是,当我试图通过**$_POST**(你可以在 else 部分的 while 循环之前看到它)来获取它时,我收到错误“未定义指数”。

编辑 - -

我尝试转储 $_POST 变量,它只是在数组中返回我返回路径,该路径为 14 个字符。

我不知道该怎么办..

我可以从任何人那里得到任何帮助吗?

4

1 回答 1

0

根据https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro中的“IPN 消息和响应示例”段落,您需要 POST 与您相同的字符串已收到。IE

对于 Express Checkout 进行的 19.95 美元购买,PayPal 会发送一条类似于以下消息的消息:

mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name =Test+User¬ify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id =S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00

在您可以信任邮件的内容之前,您必须首先验证邮件来自 PayPal。要验证消息,您必须按照接收到的确切顺序发回内容,并在其前面加上命令 _notify-validate,如下所示:

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate&mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&...&payment_gross=19.95&shipping=0.00

所以:在尝试验证之前不要更改您收到的数据。

于 2013-04-01T19:08:05.733 回答