我使用了一个普通的类作为 API,并且你正在将所有参数传递给 paypal,并且我获得了成功。
我唯一缺少的是没有从沙盒帐户中扣除金额。
如果我使用 使用 paypal 结帐
支付购买产品的金额,实际金额会在我的沙盒帐户中扣除。
可能是什么原因?有没有其他替代方法,我可以使用 paypal 通过付款明细表中传递的参数收款。
在我这样调用的 drupal 表单的提交函数中。
$paypalDoDirect = new PaypalDoDirect();
// passing all parameters to $paypalDoDirect
$response= $paypalDoDirect->MakePayment();
我得到交易成功,每个参数都成功传递。
这是我的类 api-
class PaypalDoDirect
{
/**Declared all fields **/
function MakePayment()
{
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if ("sandbox" === $this->environment || "beta-sandbox" === $this->environment) {
$API_Endpoint = "https://api-3t.$this->environment.paypal.com/nvp";
}
// Add request-specific fields to the request string.
$nvpStr = "&PAYMENTACTION=$this->paymentType&AMT=$this->amount&CREDITCARDTYPE=$this->cc_type&ACCT=$this->cc_number" .
"&EXPDATE=$this->expdate_month$this->expdate_year&CVV2=$this->cvv2_number&FIRSTNAME=$this->first_name&LASTNAME=$this->last_name&EMAIL=$this->email" .
"&STREET=$this->address1&CITY=$this->city&STATE=$this->state&ZIP=$this->zip&COUNTRYCODE=$this->country&CURRENCYCODE=$this->currencyID";
//$httpParsedResponseAr = PPHttpPost('DoDirectPayment', $nvpStr);
$methodName_ = 'DoDirectPayment';
$nvpStr_ = $nvpStr;
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$this->version&PWD=$this->API_Password&USER=$this->API_UserName&SIGNATURE=$this->API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if (!$httpResponse) {
return ("$methodName_ failed: " . curl_error($ch) . '(' . curl_errno($ch) . ')');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if (sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if ((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
return "success";
} else {
return (urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]));
}
}
}
最佳答案
是的,有一个 paypal API drupal中的模块。这是一个很好的结构化模块,可以在一些自定义模块中扩展 paypal IPN。
如果您使用此模块,IPN 回调将由此模块处理,您可以在您的实例中通过 hook_paypal_api_ipn()
获得通知。如果您浏览了有关使用 paypal 处理付款的 paypal 文档并查看了模块代码,您将理解如何很好地使用它的机制。我会推荐你使用这个模块。
虽然您可以创建自己的模块来处理 paypal 付款,无论是 express 还是转发用户。我很久以前用 drupal 实例做过一次。您将必须在您帐户的给定 URL 向用户或数据(用于快速)发送一些信息以及其中发生的事情(通过/失败/终止), Paypal 将通过您提到的实例回调 URL 通知您。接收信息并相应地做工作..
关于forms - 使用带有 Paypal API 的 Drupal Form 为选定的计划类型单独支付集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18678728/