【问题标题】:Laravel 4 - Class 'Stripe' not foundLaravel 4 - 找不到类“条纹”
【发布时间】:2015-08-11 13:00:53
【问题描述】:

我正在尝试将 Stripe 安装到我的项目中,但遇到了问题。我收到了错误

找不到类“条纹”

我用过

composer 需要 stripe/stripe-php

一切安装正常,但我仍然遇到问题。

这是导致问题的行:

Stripe::setApiKey(Config::get('stripe.secret_key'));

这是我的 composer.json 文件:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*",
        "intervention/image": "dev-master",
        "moltin/laravel-cart": "dev-master",
        "stripe/stripe-php": "~2.0@dev"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/libs",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"

        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

我的 app/config/app.php 文件中没有关于 Stripe 的内容...我不确定是否应该有 Stripe 的服务提供商。

【问题讨论】:

  • 您要在哪里设置 API 密钥?你试过composer dump吗?

标签: laravel composer-php


【解决方案1】:

查看at packagist,可以看到composer包stripe/stripe-php指向the following GitHub repository。基于that repository's codeStripe API documentation,看起来没有定义一个名为Stripe 的全局类。所以当你说

Stripe::setApiKey(Config::get('stripe.secret_key'));

PHP 说

找不到类“条纹”

PHP 告诉你真相。 一个名为 Stripe\Stripe 的类——所以你可能想要这样做

\Stripe\Stripe::setApiKey(Config::get('stripe.secret_key'));

或使用use 语句将该类导入您当前的 PHP 文件

<?php
//...
use Stripe\Stripe;
//...
Stripe::setApiKey(Config::get('stripe.secret_key'));

【讨论】:

  • 是的。它以前 \Stripe,这可能是导致混乱的原因。但是,v2.0 added proper namespacing。随着该更新,课程从\Stripe 更改为\Stripe\Stripe\Stripe_Charge 更改为\Stripe\Charge 等。
  • @cmcg,Alan Strom 你得到以下问题的答案了吗?我面临着同样的问题。如果有人可以帮忙!
猜你喜欢
  • 2021-08-03
  • 1970-01-01
  • 2015-08-06
  • 2012-12-13
  • 2017-02-09
  • 2018-02-03
  • 1970-01-01
  • 2013-03-20
  • 1970-01-01
相关资源
最近更新 更多