2016-12-15 80 views
0

我使用Laravel 5.2,並且在部署我的應用程序後,條紋結帳無法正常工作。在本地主機模式下,它工作並創建一個訂閱的客戶,但在生產中它會拋出「InvalidRequest」錯誤,並且只在Stripe中創建一個客戶,但沒有訂閱。Laravel收銀臺創建客戶,但不訂閱

apikeys設置在services,stripe和.env中,並且它獲取stripeToken。

   try { 
        // Use Stripe's library to make requests... 

        $user = new User; 

        $user->name = $request->input('name'); 
        $user->email = $request->input('email'); 
        $user->password = Hash::make($request->input('password')); 
        $user->created_at = Carbon::now(); 
        $user->save(); 

        $creditCardToken = $request->input('stripeToken'); 

        $user->newSubscription('Silver', 'Silver')->create($creditCardToken); 


       } catch(\Stripe\Error\Card $e) { 
        // Since it's a decline, \Stripe\Error\Card will be caught 

        $error = 'Det verkade vara något fel med ditt kreditkort. Vänligen testa igen.'; 
        return redirect()->back()->with('error', $error); 

       } catch (\Stripe\Error\RateLimit $e) { 
        // Too many requests made to the API too quickly 

        $error = 'Vi upplever för tillfälligt ett högt tryck. Vänligen försök igen om en liten stund.'; 
        return redirect()->back()->with('error', $error); 

       } catch (\Stripe\Error\InvalidRequest $e) { 
        // Invalid parameters were supplied to Stripe's API 

        $error = 'Ops! Något gick fel. Vänligen testa igen'; 
        return redirect()->back()->with('error', $error); 

       } catch (\Stripe\Error\Authentication $e) { 
        // Authentication with Stripe's API failed 
        // (maybe you changed API keys recently) 

        $error = 'Ops! Något gick fel. Vänligen konktakta kundtjänst så vi kan fixa problemet. Tack!'; 
        return redirect()->back()->with('error', $error); 

       } catch (\Stripe\Error\ApiConnection $e) { 
        // Network communication with Stripe failed 
        $error = 'Ops! Servern är för tillfälligt nere. Vänligen testa inom kort igen.'; 
        //return redirect()->back()->with('error', $error); 

       } catch (\Stripe\Error\Base $e) { 
        // Display a very generic error to the user, and maybe send 
        // yourself an email 
        $error = 'Ops! Något gick fel.'; 
        //return redirect()->back()->with('error', $error); 
       } catch (Exception $e) { 
        // Something else happened, completely unrelated to Stripe 
        $error = 'Ops! Något gick fel. Vänligen kontakta kundtjänst.'; 
        //return redirect()->back()->with('error', $error); 
       } 

        $name = $request->input('name'); 

        return view('checkout.confirmation', compact('plan', 'name')); 

回答

2

它應該是一個評論,但我沒有聲望去做。所以......

catch (\Stripe\Error\InvalidRequest $e) {包括dd($e->getMessage());

我相信它會給你有關該問題的一個更好的提示。

+0

我得到了...「沒有這樣的標記:在測試模式下存在類似的對象,但是使用了現場模式鍵來提出此請​​求。」 – mattesj

+0

這是一個愚蠢的問題,但是你是否在現場模式中創建了銀色計劃?你確定你的鑰匙是正確的嗎? –

+0

該錯誤代碼幫助了我。忘了保存從測試關鍵改變爲現場的觀點......菜鳥的錯誤。 – mattesj