2017-10-18 51 views
0

我使用laravel-spark處理我的網站上的條形支付,用戶可以在其訂閱上應用優惠券,以便他們享有折扣,現在我想向用戶展示折扣在個人資料頁面上。
我搜索了關於如何檢索當前折扣的火花文檔,他們沒有在任何地方提及。
我發現laravel火花有電流()

CouponController此功能在CouponController方法來實現:獲得laravel-spark中給定用戶的當前折扣

/** 
* Get the current discount for the given user. 
* 
* @param Request $request 
* @param string $userId 
* @return Response 
*/ 
public function current(Request $request, $userId) 
{ 
    $user = Spark::user()->where('id', $userId)->firstOrFail(); 

    if ($coupon = $this->coupons->forBillable($user)) { 
     return response()->json($coupon->toArray()); 
    } 

    abort(204); 
} 

我試圖調用此方法在我與Vue的觀點如下:

axios.get('/coupon/user/'+ this.user.id).then(response => { 
    console.log("response : ", response); 
    coupon = response.data.data; 
    if (coupon) { 
     //do something 
    } 
}, error => { 
    console.log("some error occurred", error); 
}); 

但是,即使用戶在他的條帶帳戶上有有效的優惠券,其響應始終爲空,並顯示204狀態碼。 有什麼建議?!

回答

0

最後我發現,優惠券控制器內這種方法獲取適用於客戶沒有有效的優惠券到訂閱, 因此,所有你需要的是每股認購併不適用於每條紋客戶優惠券。
或者你可以編寫你的邏輯來檢索通過條紋API的折扣,你可以在這裏找到所有的細節:https://stripe.com/docs/api#discounts 希望這會對你有所幫助。