gpt4 book ai didi

php - Paypal "Authorization Failed"

转载 作者:搜寻专家 更新时间:2023-10-31 21:37:59 24 4
gpt4 key购买 nike

(这是我第一次使用 PayPal API,所以请多多包涵。)

我正在尝试使用 BMCreateButton API 动态创建加密按钮,使用来自 this page 的稍微修改的代码.不幸的是,我似乎无法正常工作,因为我在 PHP 错误日志中收到“身份验证/授权失败”消息。 (我也在 PayPal 开发者论坛上问过这个问题,但没有得到答案。)

这段代码:

function createButton($name, $price) {
// Check to make sure that our version of PHP supports SOAP.
if((PHP_VERSION_ID < 50101) || !in_array("soap", get_loaded_extensions())) {
error_log("PHP not running with SOAP");
} else {
include_once("config.php"); //this file holds the credentials and whether it's running in sandbox mode or not
//basic variable validation
$price = floatval($price);

// Import the PayPal WSDL.
$location = $sandbox ? "https://api-3t.sandbox.paypal.com/2.0/" : "https://api-3t.paypal.com/2.0/";
$soapClient = new SoapClient("https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl", array(
location => $location
));

// Set our API credentials.
$credentials->Credentials->Username = $username;
$credentials->Credentials->Password = $password;
$credentials->Credentials->Signature = $signature;
$soapClient->__setSoapHeaders(new SoapHeader("urn:ebay:api:PayPalAPI", "RequesterCredentials", $credentials));

// Start creating our BMCreateButtonReq object. For full details about this object, see
// http://tinyurl.com/3mxau6j .
$BMCreateButtonReq->BMCreateButtonRequest->Version = "71.0";

$BMCreateButtonReq->BMCreateButtonRequest->ButtonCode = "ENCRYPTED";

// What type of button are we creating?
$BMCreateButtonReq->BMCreateButtonRequest->ButtonType = "CART";

// Specific variables for this button. For the full list of options, see
// http://tinyurl.com/6qyanl . For a basic payment, these two should be enough.

$BMCreateButtonReq->BMCreateButtonRequest->ButtonVar[] = "amount=$price";
$BMCreateButtonReq->BMCreateButtonRequest->ButtonVar[] = "item_name=$name";

// Run the API call.
$response = $soapClient->BMCreateButton($BMCreateButtonReq);

if($response->Ack == "Success" || $response->Ack == "SuccessWithWarning") {
// If successful, the button code will be in the Website element of $response.
// It'll be a full HTML form, so don't wrap it in any <form> tags -- just
// display it as-is.
echo $response->Website;
} else {
error_log("Could not create PayPal button. " . serialize($response->Errors));
echo "<p class=\"note\">Cannot create button</p>";

}
}
}

在错误日志中给出:

Could not create PayPal button. O:8:"stdClass":4:{s:12:"ShortMessage";s:35:"Authentication/Authorization Failed";s:11:"LongMessage";s:49:"You do not have permissions to make this API call";s:9:"ErrorCode";s:5:"10002";s:12:"SeverityCode";s:5:"Error";}

我已经检查了凭据,它们是正确的,但沙盒和实时 API 都失败了。我是否遗漏了一些基本的东西,或者我可能忽略了代码中的错误?

最佳答案

我记得这个!

$username$password$signature 是在函数内部定义的吗?如果没有,则需要在函数顶部添加 global $username, $password, $signature

关于php - Paypal "Authorization Failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com