2017-04-05 107 views
0

我首次在Laravel 5.1中整合條帶支付,並且我參考了本教程Simple Payments with Stripe and Laravel並完成了所有步驟。在Laravel 5.1中存儲條帶支付詳細信息

付款後,我收到此錯誤:

enter image description here

在條紋的日誌,它告訴我做成功付款。

我在這個函數收到此錯誤:

public function createStripeCustomer($token) 
{ 
    \Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); 

    $customer = \Stripe\Customer::create(array(
     "description" => Auth::user()->email, <-- Error at this line 
     "source" => $token 
    )); 

    //Auth::user()->stripe_id = $customer->id; 
    Auth::user()->save(); 

    return $customer; 
} 

我已經創建了波紋管架構的用戶,但不明白其中的細節需要存儲:

Schema::table('users', function ($table) { 
    $table->string('stripe_id')->nullable(); 
    $table->string('card_brand')->nullable(); 
    $table->string('card_last_four')->nullable(); 
    $table->timestamp('trial_ends_at')->nullable(); 
}); 
+0

因爲您還沒有授權用戶,並且Auth :: user()返回false,請登錄並重試。 –

+0

@VaheGalstyan我正在嘗試,因爲你解釋了我,但你能告訴我哪些細節我必須存儲在這個領域:'stripe_id,card_brand,card_last_four,trial_ends_at'。 –

+0

使用教程,我在答案中添加。 –

回答

0

保護您的使用途徑Auth中間件:

Route::get('stripepayment', [ 
    'middleware' => 'auth', 
    'uses' => '[email protected]' 
]); 

它會自動檢查Auth :: user()並將您重定向到lo杜松子酒頁面,如果偶然,你註銷。

你的代碼給出錯誤,因爲它沒有得到Auth :: user(),因爲你沒有登錄。

+0

我正在嘗試,因爲你解釋了我,但你能告訴我哪些細節我必須存儲在這個領域:'stripe_id,card_brand,card_last_four,trial_ends_at'。 –

+0

@先生在stripe_id中您需要存儲$ customer-> id,card_brand是用戶選擇的一個,從card_last_four中獲取輸入卡號的最後4個字符而trial_ends_at是卡的到期日期 –