/** * Creates payment and refund for $payable. * {@inheritdoc} */ public function success(PayableInterface $payable, $reference, MethodInterface $method) { $refund = new OrderRefund(); $refund->method = $method; $refund->amount = $payable->getPayableAmount(); $refund->reference = $reference; $refund->reason = $this->_reason; $refund->payment = $this->get('order.payment.loader')->getByMethodAndReference($method, $reference) ?: null; if ($payable instanceof RefundableInterface) { $refund->setTax($payable->getTax()); } $order = $payable->getOrder(); $order->refunds->append($refund); $transaction = $this->get('db.transaction'); $this->get('order.refund.create')->setTransaction($transaction)->create($refund); if ($transaction->commit()) { $this->addFlash('success', sprintf('Successfully refunded %s %s to customer.', number_format($payable->getPayableAmount(), 2), $payable->getPayableCurrency())); } $successUrl = $this->generateUrl($this->_url, array('orderID' => $payable->getOrder()->id), UrlGeneratorInterface::ABSOLUTE_URL); return new JsonResponse(['url' => $this->get('request')->headers->get('referer')]); }