Paypal - 尝试实施定期付款时出现付款问题

时间:2015-08-14 08:33:17

标签: php post paypal get

paypalrecurring.php

private $test = false;
private $liveServer = 'https://api-3t.paypal.com/nvp'; # https://api.paypal.com/nvp
private $testServer = 'https://api-3t.sandbox.paypal.com/nvp'; # https://api.sandbox.paypal.com/nvp
private $methodName = 'CreateRecurringPaymentsProfile';

public function sendRequest()
{
    $nvpreq = '';

    foreach ($this->request as $fldname => $val)
        if($val != '') $nvpreq .= strtoupper($fldname) . "=" . urlencode($val) . "&";

    $url = ($this->test) ? $this->testServer : $this->liveServer;
    $post = "METHOD=" . $this->methodName . "&" . $nvpreq . "&VERSION=56.0";
    $retstr = $this->sendAPIRequest($url . "?" . $post);
    $retarrtmp = explode("&",$retstr);
    $retarr = array();

    for($i=0;$i<count($retarrtmp);$i++)
    {
        $sparr = explode("=",$retarrtmp[$i]);
        $txt = urldecode($sparr[0]);
        $val = urldecode($sparr[1]);
        $retarr[$txt] = $val;
    }

    return $retarr;
}

/**
 * True for test server. False for production.
 * @param bool $isTest
 */
public function setIsTest($isTest)
{
    $this->test = $isTest;
}

private function sendAPIRequest($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);

    if(curl_errno($ch))
        $response = curl_error($ch);

    curl_close($ch);
    return $response;
}
}

Usageexample.php

<?php
require_once 'PaypalRecurring.php';

$pp = new PayPalRecurring();

$pp->setIsTest(true); // PayPal test sandbox or live server

// Your PayPal account credentials go here
$pp->request['user'] = 'xxx';
$pp->request['pwd'] = 'xxx';
$pp->request['signature'] = 'xxx';
// End PayPal account credentials

// User info
$pp->request['firstname'] = 'The users first name';
$pp->request['lastname'] = 'The users last name';
$pp->request['email'] = 'The users email address';

$pp->request['creditcardtype'] = 'Visa'; // Visa, Mastercard, Discover, Amex
$pp->request['acct'] = ''; // Credit card number
$pp->request['expdate'] = str_pad('8',2,'0', STR_PAD_LEFT)  .'2020'; // Expiration month and full year. Pad the month with 0. Month should be 1-12. This example is 8/2020.
// End user info

// Product info
$pp->request['countrycode'] = 'US';
$pp->request['billingperiod'] = 'Month'; // Bill per month
$pp->request['billingfrequency'] = 1; // How many times to bill per billing period.. This example is once per month
$pp->request['currencycode'] = 'USD';
$pp->request['amt'] = 9.95; // Amount to bill every month
$pp->request['initamt'] = 0.00; // Setup fee.. One time on account creation
$pp->request['taxamt'] = $pp->request['amt'] * .07; // Replace .07 with your tax percentage. 0 for no tax.
$pp->request['desc'] = 'Super Deluxe Package'; // The description of your product for reporting in your account
$pp->request['profilestartdate'] = gmdate('Y-m-d\TH:i:s\Z');
$pp->request['totalbillingcycles'] = '3'; // How many billing cycles. 0 for no expiration. This example is for 3 total months of billing.
$pp->request['payerstatus'] = 'verified';
// End product info

$ppResponse = $pp->sendRequest();

if(isset($ppResponse['L_ERRORCODE0']))
    echo "Error: {$ppResponse['L_LONGMESSAGE0']}";
else if(isset($ppResponse['ACK']) && $ppResponse['ACK'] == ('Success' || 'SuccessWithWarning'))
    echo "Success: {$ppResponse['ACK']}";
else
    print_r($ppResponse);

每当我尝试在paypal中实施定期付款时总会出错 security header is not valid

以上示例来自github

我需要在电子商务网站中整合定期付款

我有两个文件paypalrecurring.php&amp; usageExample.php

当我执行usageExample.php时,我收到错误security header is not valid

任何人都可以帮助我

1 个答案:

答案 0 :(得分:0)

这是因为以下代码中的API凭据不正确。

$pp->request['user'] = 'xxx';
$pp->request['pwd'] = 'xxx';
$pp->request['signature'] = 'xxx';

您可以按照以下步骤查找您的API凭据:

对于沙盒帐户:

访问https://developer.paypal.com/并登录,然后访问以下网址:

https://developer.paypal.com/developer/accounts

点击用于测试的商家帐户,然后点击&#34;个人资料&#34;帐户下的链接。 然后单击&#34; API凭据&#34;选项卡,您将找到API凭据。

对于真实账户:

登录www.paypal.com,转到个人资料 - >销售工具 - &gt; API访问,点击&#34;请求API凭据&#34;链接, 然后选择&#34;请求API签名&#34;然后单击&#34;同意并提交&#34;。 然后,您可以在最后一页找到您的API用户名,API密码和API签名。