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

标签 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 中实现定期付款时总是出错 安全 header 无效

以上例子来自github

我需要在电子商务网站中集成定期付款

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

当我执行 usageExample.php 时出现错误 security header is not valid

谁能帮帮我

最佳答案

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

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

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

对于沙盒帐户:

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

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

点击用于测试的企业帐户,然后点击该帐户下的“个人资料”链接。 然后单击“API 凭据”选项卡,您将找到 API 凭据。

对于真实账户:

登录 www.paypal.com,进入个人资料->销售工具->API 访问,点击“请求 API 凭据”链接, 然后选择“请求API签名”,点击“同意并提交”。 然后你可以在最后一页找到你的API用户名、API密码和API签名。

关于php - Paypal - 尝试实现定期付款时出现付款问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32005681/

相关文章:

php - Laravel、Behat 和 Faker 的隐藏属性问题

javascript - 使用本地 HTML 文件获取远程 JSON 数据(使用 JavaScript - jQuery)

php - 使用PHP在Twitter上发布时加剧问题

PayPal - 如果已经批准了一些计费协议(protocol),则计费计划处于非事件状态怎么办?

ios - 具有实时 appID 的 iphone 应用程序的 Paypal 集成

php - 更新 mysql 表中的第二个重复值?

php - 未经授权的谷歌访问 token

php - 我对 PHP Post/Redirect/Get 感到困惑

c# - 我可以使用 eBay API 获取 eBay 订单的 PayPal 交易 ID 吗?

php - PDO 获取数组的数组。外部有数字索引。内部有关联索引