我试图整合贝宝,但我没有得到正确的东西。当网站被重定向到贝宝,它显示网页(图片我已经添加了这篇文章)。
请任何人帮我摆脱困境,因为我是第一次这样做。
请任何人告诉我哪里可能是错的。alt text http://img341.imageshack.us/img341/6920/captureqt.jpg
我用这个课程把PayPal整合到我的网站上,但是不知道为什么我没有得到想要的东西。
/*******************************************************************************
*php paypal ipn集成类
作者:米卡·卡里克
电子邮箱:email@micahcarrick.com
网站:http://www.micahcarrick.com
*
文件:PayPal.Copy.PHP
版本:1.3.0
版权所有:(c)2005-Micha Carrick
您可以自由使用、分发和修改此软件
根据GNU通用公共许可的条款。见
包含license.txt文件。
Verion历史:
v1.3.0[10.10.2005]-修复了它,以便处理单引号
正确的方法,而不是简单的剥离他们。这个
因为用户仍然可以输入
引用。
v1.2.1[06.05.2005]-修正了先前修正的打字错误:)
*
v1.2.0[05.31.2005]-添加了删除所有引号的可选功能
从PayPal帖子。IPN会回来的
在certian中使用引号时有时无效
领域。
*
V1.1.0[05.1553]——修改SupmithPayPalp职务中的表单输出
允许非JavaScript浏览器的方法
提供手动提交表格的方法。
*
v1.0.0[04.16.2005]-初始版本
*
说明:
*
注:该类的最新版本请参见www.micahcarrick.com
以及任何适用的样本文件和其他文件。
*
这个文件提供了一个简洁而简单的方法与PayPal接口。
PayPal即时支付通知(IPN)接口。这个文件是
不打算让PayPal集成“插件”播放。它仍然
需要开发人员(应该是你)了解贝宝
处理和知道你想要/需要传递给贝宝的变量
实现你想要的。
*
这个类处理订单提交给贝宝以及
正在处理即时付款通知。
这个代码是基于PayPal的PHP工具包的。我拿了
基本原则,并把它放到一个类中,这样它就有点
更容易——至少对我来说——使用。php工具包可以从
http://sourceforge.net/projects/paypal。
向PayPal提交订单,将您的订单表格邮寄到:
*
$P=新PayPall类;
$p->添加字段('business','someone@domain.com');
$P->添加字段('first_name',$_post['first_name']);
…(把你所有的田地都加在同一个庄园里)
$P> >提交PayPalpPh();
*
要处理IPN,请使IPN处理文件包含:
*
$P=新PayPall类;
如果($p->validate_ipn()){
…(IPN已验证。详细信息在ipn_data()数组中)
}
*
*
如果你对PayPal是新的,这里有一些信息可以帮助你:
*
从下载并阅读商户用户手册和集成指南
http://www.paypal.com/en_US/pdf/integration_guide.pdf。这给了
您需要的所有信息,包括可以传递到的字段
PayPal(使用AdjiFieldFor(具有此类))以及所有字段
在IPN post中返回的(存储在
这堂课)。它还绘制了整个事务流程图。
*
为买家和卖家创建一个“沙盒”帐户。这只是
一个测试帐户,允许您从
卖方和买方的观点。这方面的说明是可用的
以及一个很棒的论坛
可以问你所有的PayPal集成问题。一定要跟上
设置沙盒测试环境的所有说明,包括
伪造银行账户和信用卡。
*/
类PayPall类{
var$last_error;//保存最后遇到的错误
var$ipn_log;//bool:将ipn结果记录到文本文件?
var$ipn_log_file;//ipn日志的文件名
VaR IPNNY响应;/ /持有PayPal的IPN响应
var$ipn_data=array();//array包含ipn的post值
var $field =数组();//数组保持提交给Paypal的字段
函数PayPall类(){
// initialization constructor. Called when class is created.
$this->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$this->last_error = '';
$this->ipn_log_file = 'ipn_results.log';
$this->ipn_log = true;
$this->ipn_response = '';
// populate $fields array with a few default values. See the paypal
// documentation for a list of fields and their data types. These defaul
// values can be overwritten by the calling script.
$this->add_field('rm','2'); // Return method = POST
$this->add_field('cmd','_xclick');
}
函数add_field($field,$value){
// adds a key=>value pair to the fields array, which is what will be
// sent to paypal as POST variables. If the value is already in the
// array, it will be overwritten.
$this->fields["$field"] = $value;
}
函数SupMITPayPalpPASH(){
// this function actually generates an entire HTML page consisting of
// a form with hidden elements which is submitted to paypal via the
// BODY element's onLoad attribute. We do this so that you can validate
// any POST vars from you custom form before submitting to paypal. So
// basically, you'll have your own form which is submitted to your script
// to validate the data, which in turn calls this function to create
// another hidden form and submit to paypal.
// The user will briefly see a message on the screen that reads:
// "Please wait, your order is being processed..." and then immediately
// is redirected to paypal.
echo "<html>\n";
echo "<head><title>Processing Payment...</title></head>\n";
echo "<body onLoad=\"document.forms['paypal_form'].submit();\">\n";
echo "<center><h2>Please wait, your order is being processed and you";
echo " will be redirected to the paypal website.</h2></center>\n";
echo "<form method=\"post\" name=\"paypal_form\" ";
echo "action=\"".$this->paypal_url."\">\n";
foreach ($this->fields as $name => $value) {
echo "<input type=\"hidden\" name=\"$name\" value=\"$value\"/>\n";
}
echo "<center><br/><br/>If you are not automatically redirected to ";
echo "paypal within 5 seconds...<br/><br/>\n";
echo "<input type=\"submit\" value=\"Click Here\"></center>\n";
echo "</form>\n";
echo "</body></html>\n";
}
//————————————————————————————————————————--
//设置状态
/*函数setStatus()
{
$db = new Connection();
$con = $db->getConnection();
$query="insert into paypal_Result(`mc_gross`,`protection_eligibility`) values ('1','2')";
$rs=mysql_query($query,$con);
if($rs != "")
{
return true;
}
else
{
return false;
}
}*/
//————————————————————————————————————————--
函数validate_ipn(){
// parse the paypal URL
$url_parsed=parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_string = '';
foreach ($_POST as $field=>$value) {
$this->ipn_data["$field"] = $value;
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
$post_string.="cmd=_notify-validate"; // append ipn command
// open the connection to paypal
$fp = fsockopen($url_parsed[host],"80",$err_num,$err_str,30);
if(!$fp) {
// could not open the connection. If loggin is on, the error message
// will be in the log.
$this->last_error = "fsockopen error no. $errnum: $errstr";
$this->log_ipn_results(false);
return false;
} else {
// Post the data back to paypal
fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
// loop through the response from the server and append to variable
while(!feof($fp)) {
$this->ipn_response .= fgets($fp, 1024);
}
fclose($fp); // close connection
}
if (eregi("VERIFIED",$this->ipn_response)) {
// Valid IPN transaction.
$this->log_ipn_results(true);
return true;
} else {
// Invalid IPN transaction. Check the log for details.
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results(false);
return false;
}
}
函数日志ipn结果($success){
if (!$this->ipn_log) return; // is logging turned off?
// Timestamp
$text = '['.date('m/d/Y g:i A').'] - ';
// Success or failure being logged?
if ($success) $text .= "SUCCESS!\n";
else $text .= 'FAIL: '.$this->last_error."\n";
// Log the POST variables
$text .= "IPN POST Vars from Paypal:\n";
foreach ($this->ipn_data as $key=>$value) {
$text .= "$key=$value, ";
}
// Log the response from the paypal server
$text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response;
// Write to log
$fp=fopen($this->ipn_log_file,'a');
fwrite($fp, $text . "\n\n");
fclose($fp); // close file
}
函数dump_fields(){
// Used for debugging, this function will output all the field/value pairs
// that are currently defined in the instance of the class using the
// add_field() function.
echo "<h3>paypal_class->dump_fields() Output:</h3>";
echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
<tr>
<td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
<td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
</tr>";
ksort($this->fields);
foreach ($this->fields as $key => $value) {
echo "<tr><td>$key</td><td>".urldecode($value)." </td></tr>";
}
echo "</table><br>";
}
}
最佳答案
不知道您的代码有什么问题,但是使用内置类来避免代码中出现任何问题总是一个好主意,因此我建议您使用这个paypal class,这将提高您的工作效率。
关于php - 卡在 Paypal 集成中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2214180/