使用PayPal付款的信用卡失败

时间:2014-07-05 08:39:12

标签: php paypal

我使用信用卡付款代码来自以下网站 -

http://code.tutsplus.com/tutorials/how-to-process-credit-cards-with-paypal-payments-pro-using-php--net-25397

从这里获得我的api证书 -

https://www.paypal.com/uk/cgi-bin/webscr?cmd=_profile-api-signature

我正在输入我的API USAername,API密码和签名,但它正在返回" ACK =失败"。我跟着它的评论,但没有得到正确的解决方案,我的代码是 -
包括/ config.php的

// Set sandbox (test mode) to true/false.
$sandbox = TRUE;
// Set PayPal API version and credentials.
$api_version = '85.0';
$api_endpoint = $sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
$api_username = $sandbox ? 'SANDBOX_USERNAME_GOES_HERE' : 'LIVE_USERNAME_GOES_HERE';
$api_password = $sandbox ? 'SANDBOX_PASSWORD_GOES_HERE' : 'LIVE_PASSWORD_GOES_HERE';
$api_signature = $sandbox ? 'SANDBOX_SIGNATURE_GOES_HERE' : 'LIVE_SIGNATURE_GOES_HERE';

过程信用-card.php

// Include config file
require_once('includes/config.php');

// Store request params in an array
$request_params = array
                    (
                    'METHOD' => 'DoDirectPayment', 
                    'USER' => $api_username, 
                    'PWD' => $api_password, 
                    'SIGNATURE' => $api_signature, 
                    'VERSION' => $api_version, 
                    'PAYMENTACTION' => 'Sale',                   
                    'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
                    'CREDITCARDTYPE' => 'MasterCard', 
                    'ACCT' => '5522340006063638',                        
                    'EXPDATE' => '022013',           
                    'CVV2' => '456', 
                    'FIRSTNAME' => 'Tester', 
                    'LASTNAME' => 'Testerson', 
                    'STREET' => '707 W. Bay Drive', 
                    'CITY' => 'Largo', 
                    'STATE' => 'FL',                     
                    'COUNTRYCODE' => 'US', 
                    'ZIP' => '33770', 
                    'AMT' => '100.00', 
                    'CURRENCYCODE' => 'USD', 
                    'DESC' => 'Testing Payments Pro'
                    );

// Loop through $request_params array to generate the NVP string.


$nvp_string = '';
foreach($request_params as $var=>$val)
{
    $nvp_string .= '&'.$var.'='.urlencode($val);    
}




// Send NVP string to PayPal and store response
$curl = curl_init();
        curl_setopt($curl, CURLOPT_VERBOSE, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_URL, $api_endpoint);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);

$result = curl_exec($curl);     
curl_close($curl);

var_dump($result);

// Parse the API response
$nvp_response_array = parse_str($result);




// Function to convert NTP string to an array
function NVPToArray($NVPString)
{
    $proArray = array();
    while(strlen($NVPString))
    {
        // name
        $keypos= strpos($NVPString,'=');
        $keyval = substr($NVPString,0,$keypos);
        // value
        $valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
        $valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
        // decoding the respose
        $proArray[$keyval] = urldecode($valval);
        $NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
    }
    return $proArray;
}

错误

ACK=Failure
L_SHORTMESSAGE0=Security error
L_LONGMESSAGE0=Security header is not valid

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

非常简单的谷歌搜索提出了这个: http://www.prestashop.com/forums/topic/125029-security-header-is-not-valid-read-first/

其中说:

  

[...] 凭据不正确或 [...] 您正在使用   具有生产模式(或生产凭证)的SandBox凭证   使用沙箱模式)。如果你正在制作,你必须检查   SandBox模式不活动(请务必填写配置表单   您的生产凭据而不是您的沙盒凭证。)

并补充说:

  

如果问题不是来自测试模式,则意味着您的凭据不正确。

所以我会从那里开始。

也不是使用foreach构造手动创建该查询字符串,而是尝试查看http-build-query()函数:http://php.net/manual/en/function.http-build-query.php