我正试图为我的Stripe客户创建一个临时密钥,但是由于某种原因,我的php后端抛出以下错误?
致命错误:找不到“ Stripe \ EphemeralKey”类 /var/www/html/myFile.php在第21行
知道为什么会这样吗?
<?php // Create a customer using a Stripe token
require_once('vendor/autoload.php');
// If you're using Composer, use Composer's autoload:
ini_set('display_errors',1);
error_reporting(E_ALL);
// Be sure to replace this with your actual test API key
// (switch to the live key later)
\Stripe\Stripe::setApiKey("MYLIVEKEY");
if (!isset($_POST['api_version']))
{
header('HTTP/1.1 400 Bad Request');
}
// Create Stripe Customer
try {
$key = \Stripe\EphemeralKey::create(array(
"customer" => $customerId, // Convert amount in cents to dollar
"stripe_version" => $_POST['api_version']
)
);
header('Content-Type: application/json');
exit(json_encode($key));
} catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
}
?>
编辑:下面添加了Composer.json文件。
composer.json
{
"name": "stripe/stripe-php",
"description": "Stripe PHP Library",
"keywords": [
"stripe",
"payment processing",
"api"
],
"homepage": "https://stripe.com/",
"license": "MIT",
"authors": [
{
"name": "Stripe and contributors",
"homepage": "https://github.com/stripe/stripe-php/contributors"
}
],
"require": {
"php": ">=5.4.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"php-coveralls/php-coveralls": "1.*",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": { "Stripe\\" : "lib/" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
}
}