Symfony2控制器中Stripe的错误使用语句

时间:2016-12-14 10:08:24

标签: php symfony stripe-payments libraries

我正在使用Stripe为我的Symfony2网络应用付款,并在尝试使用条带方法时遇到错误。

Attempted to load class "Stripe_Charge" from namespace "UserBundle\Controller".
Did you forget a "use" statement for another namespace?

我使用composer来包含Stripe librarie,如下所示:

作曲家:

"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.8.*",
    [...]
    "stripe/stripe-php": "dev-master"
}

在我的控制器中,我有executePaymentAction函数,但是我在使用Stripe时出错。

这是我的控制器:

<?
namespace UserBundle\Controller;

use Stripe\Stripe;

class RegistrationSellerController extends Controller
{
    public function executePaymentAction(Request $request){

        $data = $request->request->all();

        Stripe::setApiKey('pk_test_***');
        try {
            Stripe_Charge::create([
                'amount' => 2000, // this is in cents: $20
                'currency' => 'usd',
                'card' => $_POST['stripeToken'],
                'description' => 'product description'
            ]);
        } catch (Stripe_CardError $e) {
            // Declined. Don't process their purchase.
            // Go back, and tell the user to try a new card
        }
    }
}

1 个答案:

答案 0 :(得分:0)

错误消息非常明显:您忘记了类Stripe_Charge

的use语句