Пример #1
0
 public function createCoupon(StripeCouponRequest $request)
 {
     //dd($request->all());
     $coupon_id = $request->coupon_id;
     $coupon_name = $request->coupon_name;
     $duration = $request->duration;
     $duration_in_month = $duration == 'repeating' ? (int) $request->duration_in_months : NULL;
     $max_redemption = (int) $request->max_redemptions;
     $redeem_by = Carbon::parse($request->redeem_by);
     if ($request->amount_off_checked) {
         $percent_off = NULL;
         $coupon_currency = $request->coupon_currency;
         $amount_off = (int) ($request->amount_off * 100);
     } else {
         $percent_off = (int) $request->percent_off;
         $coupon_currency = NULL;
         $amount_off = NULL;
     }
     Stripe::setApiKey(getenv('STRIPE_SECRET'));
     $coupon = Coupon::create(array("id" => $coupon_id, "duration" => $duration, "duration_in_months" => $duration_in_month, "max_redemptions" => $max_redemption, "percent_off" => $percent_off, "amount_off" => $amount_off, "currency" => $coupon_currency, "redeem_by" => $redeem_by->timestamp));
     $coupon_local = StripeCoupon::create(["coupon_id" => $coupon_id, "coupon_name" => $coupon_name, "duration" => $duration, "duration_in_months" => $duration_in_month, "max_redemptions" => $max_redemption, "percent_off" => $percent_off, "amount_off" => $amount_off, "currency" => $coupon_currency, "redeem_by" => $redeem_by]);
     if ($coupon_local) {
         flash('Your Coupon (' . $coupon_local->coupon_name . ') is successfully created.');
     } else {
         flash('Your Coupon (' . $coupon_local->coupon_name . ') is failed to create. Please contact your administrator for assistance.');
     }
     return redirect()->back();
 }