voucherifyClient = createVoucherifyClient(); } /** * @param User $user * @param int $amount * @return null|object * @throws \Voucherify\ClientException */ public function execute(User $user, int $amount) { $startDate = Carbon::now(); $expirationDate = $startDate->copy()->addMonths(12)->endOfDay(); try { $result = $this->voucherifyClient->vouchers->create([ "code" => Str::random(10), "type" => "DISCOUNT_VOUCHER", "discount" => [ "type" => "AMOUNT", "amount_off" => $amount * 100, ], "redemption" => [ "quantity" => 1 ], "metadata" => [ "email" => $user->email ], "start_date" => $startDate->format('Y-m-d H:i:s'), "expiration_date" => $expirationDate->format('Y-m-d H:i:s') ]); return $result; } catch (\Voucherify\ClientException $e) { Log::error($e); return null; } } }