我正在使用laravel-spark在我的网站上处理条纹付款,用户可以在他们的订阅上应用优惠券,这样他们就可以享受折扣,现在我想在个人资料页面上显示用户折扣。
我搜索了关于如何检索当前折扣的spark文档,他们没有在任何地方提到它
我发现laravel-spark在CouponController方法中实现了这个功能 current()
CouponController :
/**
* 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 :(得分:0)
最后,我发现优惠券控制器中的这种方法可以获得适用于客户而不是订阅的有效优惠券,
所以你需要的是按照每个客户而不是每个订阅应用优惠券。
或者您可以编写逻辑以通过条带API检索折扣,您可以在此处找到所有详细信息:https://stripe.com/docs/api#discounts
希望这会对你有所帮助。