2016-12-14 38 views
-1

我使用Stripe爲我的Symfony2 Web應用程序支付款項,並嘗試使用Stripe方法時出現錯誤。Symfony2控制器中Stripe的使用錯誤聲明

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

我用composer爲包括條紋librarie這樣的:

作曲:

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

在我的控制,我有executePaymentAction功能,但我在它使用條紋有一個錯誤。

這裏是我的控制器:

<? 
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 
     } 
    } 
} 

回答

0

錯誤消息是很明顯的:你忘了上課Stripe_Charge

+0

Actualy使用聲明,我沒有這樣做的corect使用語句,但它用工作正常\ Stripe \ Charge :: create(發現答案後發現它2分鐘)...對不起 – Gauthier

+0

'使用Stripe \ Charge',然後在您的代碼中:'Charge :: create'。與'Stripe \ CardError'一樣 – dev0