Esempio n. 1
0
 /**
  * Cash Payment.
  *
  * @param $order
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function payment($order)
 {
     try {
         \DB::beginTransaction();
         $type = \Input::get('type', 'cash');
         /**
          * ! Todo:: Optimize the payment creation logic.
          *
          * Check if the order payment is exist;
          * If exist and has the same payment type, return the payment.
          * If don't have the same payment type, delete the old payment.
          * Create a new payment for this order.
          */
         if ($order->payment) {
             if ($order->payment->payment_method()->get()->first()->name == $type) {
                 return $this->setStatusCode(200)->respondWithItem($order->payment);
             } else {
                 $order->payment->delete();
                 // Fire delete sales event.
                 \Event::fire('paxifi.notifications.sales.delete', [$order->payment]);
             }
         }
         $newPayment = ['payment_method_id' => PaymentMethods::getMethodIdByName($type), 'order_id' => $order->id, 'details' => $this->translator->trans("payments.{$type}.create")];
         if ($payment = Payment::create($newPayment)) {
             \DB::commit();
             return $this->setStatusCode(200)->respondWithItem($payment);
         }
         return $this->setStatusCode(500)->respondWithError('Payment create failed, please try it later.');
     } catch (ValidationException $e) {
         return $this->errorWrongArgs($e->getErrors());
     } catch (\Exception $e) {
         return $this->errorInternalError();
     }
 }
 /**
  * Register a saved model event with the dispatcher.
  *
  * @param  $payment
  */
 public function created($payment)
 {
     $payment_method = PaymentMethods::find($payment->payment_method_id);
     if ($payment_method->name != 'paypal') {
         $payment->type = "sales";
         \Event::fire('paxifi.notifications.sales', [$payment]);
     }
 }
 public function run()
 {
     DB::table('payment_methods')->truncate();
     EloquentPaymentMethodsRepository::create(array('name' => 'cash', 'description' => 'Pay by cash', 'enabled' => true));
     EloquentPaymentMethodsRepository::create(array('name' => 'paypal', 'description' => 'Pay by paypal', 'enabled' => false));
 }