/** * @param $driver * * @return \Illuminate\Http\JsonResponse */ public function destroy($driver = NULL) { try { \DB::beginTransaction(); if (is_null($driver)) { $driver = $this->getAuthenticatedDriver(); } if ($notifications = $driver->notifications) { $notifications->map(function ($notification) { if (EloquentNotificationTypeRepository::find($notification->type_id)->type == 'sales') { if (Payment::find($notification->value)->status == 0) { return; } } $notification->delete(); }); \DB::commit(); return $this->setStatusCode(204)->respond(['success' => true, 'message' => $this->translator->trans('notifications.deleted')]); } return $this->setStatusCode(404)->respondWithError($this->translator->trans('notifications.no_available_resources')); } catch (\Exception $e) { return $this->errorInternalError(); } }
/** * @param $notification * * @return array */ public function transformSales($notification) { $payment = Payment::find($notification->value); $payment_status = strtolower($payment->status); // get the payment type. switch ($payment->payment_method()->first()->name) { case 'paypal': $translation = "notifications.sales.paypal.completed"; $sales = ['message' => $this->translator->trans($translation, ['currency' => $notification->driver->currency, 'amount' => $payment->order->total_sales]), 'type' => 'sales', 'status' => $payment_status, 'payment' => $payment]; break; default: if ($payment_status == 0) { $status = 'waiting'; } if ($payment_status == -1) { $status = 'canceled'; } if ($payment_status == 1) { $status = 'received'; } $translation = "notifications.sales.cash." . $status; $sales = ['message' => $this->translator->trans($translation, ['currency' => $notification->driver->currency, 'amount' => $payment->order->total_sales]), 'type' => 'sales', 'status' => $payment_status, 'payment' => $payment]; } return $sales; }