/** * @param PaymentCompleteEvent $event */ public function onPaymentComplete(PaymentCompleteEvent $event) { $payment = $event->getPayment(); $status = (string) $payment->getStatus(); $this->addFlashMessage($status, $payment->getMessage()); if ('credit' === $payment->getMethod()->getPaymentMethod()) { $creditRepository = $this->manager->getRepository('CSBillClientBundle:Credit'); $creditRepository->deductCredit($payment->getClient(), new Money($payment->getTotalAmount(), $this->currency)); } if (null !== ($invoice = $event->getPayment()->getInvoice())) { if ($status === Status::STATUS_CAPTURED && $this->invoiceManager->isFullyPaid($invoice)) { $this->invoiceManager->pay($invoice); } else { $paymentRepository = $this->manager->getRepository('CSBillPaymentBundle:Payment'); $totalPaid = $paymentRepository->getTotalPaidForInvoice($invoice); $invoice->setBalance($invoice->getTotal()->subtract($totalPaid)); $this->manager->persist($invoice); $this->manager->flush(); } $event->setResponse(new RedirectResponse($this->router->generate('_view_invoice_external', array('uuid' => $invoice->getUuid())))); } }
/** * @param PaymentCompleteEvent $event */ public function onPaymentCapture(PaymentCompleteEvent $event) { $notification = new PaymentReceivedNotification(array('payment' => $event->getPayment())); $this->notification->sendNotification('payment_made', $notification); }