php api接口 致命错误,条纹 - 致命错误 - 未提供API密钥 - PHP

提交charge.php条带支付页面时,我一直收到以下错误 . 我也没有使用作曲家 . 我不确定为什么会发生这种错误 .

致命错误:未捕获异常'Stripe \ Error \ Authentication',并显示消息'未提供API密钥 . (提示:使用“Stripe :: setApiKey()”设置您的API密钥 . 您可以从Stripe Web界面生成API密钥 . 有关详细信息,请访问https://stripe.com/api,如果您是,请发送电子邮件至support@stripe.com在/home/site/html/test/stripe/lib/ApiRequestor.php:132堆栈跟踪任何问题“:#0 /home/site/html/test/stripe/lib/ApiRequestor.php(64):条纹\ ApiRequestor - > _ requestRaw('post','/ v1 / customers',Array,Array)#1 /home/site/html/test/stripe/lib/ApiResource.php(120):Stripe \ ApiRequestor-> request( 'post','/ v1 / customers',Array,Array)#2 /home/site/html/test/stripe/lib/ApiResource.php(160):Stripe \ ApiResource :: _ staticRequest('post','/ v1 / customers',Array,NULL)#3 /home/site/html/test/stripe/lib/Customer.php(59):Stripe \ ApiResource :: _ create(Array,NULL)#4 / home / site / html /test/charge.php(9):第132行/home/site/html/test/stripe/lib/ApiRequestor.php中引发的Stripe \ Customer :: create(Array)#5

以下是我正在使用的文件:

config.php

require_once('stripe/init.php');

$stripe = array(

"secret_key" => "foobar" /* Actual secret key redacted */,

"publishable_key" => "foobar" /* Actual publishable_key redacted */

);

\Stripe\Stripe::setApiKey($stripe['secret_key']);

?>

Form:

data-description="Access for a year"

data-amount="5000"

data-locale="auto">

charge.php

require_once('config.php');

$token = $_POST['stripeToken'];

$customer = \Stripe\Customer::create(array(

'email' => 'customer@example.com',

'source' => $token

));

$charge = \Stripe\Charge::create(array(

'customer' => $customer->id,

'amount' => 5000,

'currency' => 'usd'

));

echo '

Successfully charged $50.00!

';

?>

这也是ApiRequestor.php函数似乎导致了一个问题:

private function _requestRaw($method, $url, $params, $headers)

{

$myApiKey = $this->_apiKey;

if (!$myApiKey) {

$myApiKey = Stripe::$apiKey;

}

if (!$myApiKey) {

$msg = 'No API key provided. (HINT: set your API key using '

. '"Stripe::setApiKey()". You can generate API keys from '

. 'the Stripe web interface. See https://stripe.com/api for '

. 'details, or email support@stripe.com if you have any questions.';

throw new Error\Authentication($msg);

}

$absUrl = $this->_apiBase.$url;

$params = self::_encodeObjects($params);

$langVersion = phpversion();

$uname = php_uname();

$ua = array(

'bindings_version' => Stripe::VERSION,

'lang' => 'php',

'lang_version' => $langVersion,

'publisher' => 'stripe',

'uname' => $uname,

);

$defaultHeaders = array(

'X-Stripe-Client-User-Agent' => json_encode($ua),

'User-Agent' => 'Stripe/v1 PhpBindings/' . Stripe::VERSION,

'Authorization' => 'Bearer ' . $myApiKey,

);

if (Stripe::$apiVersion) {

$defaultHeaders['Stripe-Version'] = Stripe::$apiVersion;

}

if (Stripe::$accountId) {

$defaultHeaders['Stripe-Account'] = Stripe::$accountId;

}

$hasFile = false;

$hasCurlFile = class_exists('\CURLFile', false);

foreach ($params as $k => $v) {

if (is_resource($v)) {

$hasFile = true;

$params[$k] = self::_processResourceParam($v, $hasCurlFile);

} elseif ($hasCurlFile && $v instanceof \CURLFile) {

$hasFile = true;

}

}

if ($hasFile) {

$defaultHeaders['Content-Type'] = 'multipart/form-data';

} else {

$defaultHeaders['Content-Type'] = 'application/x-www-form-urlencoded';

}

$combinedHeaders = array_merge($defaultHeaders, $headers);

$rawHeaders = array();

foreach ($combinedHeaders as $header => $value) {

$rawHeaders[] = $header . ': ' . $value;

}

list($rbody, $rcode, $rheaders) = $this->httpClient()->request(

$method,

$absUrl,

$rawHeaders,

$params,

$hasFile

);

return array($rbody, $rcode, $rheaders, $myApiKey);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值