/** * Complete a order purchase by creating an order and generating a * success url to redirect the customer towards. * * {@inheritDoc} */ public function success(PayableInterface $payable, $reference, MethodInterface $method) { // Build the payment and add it to the order $payment = new Payment(); $payment->method = $method; $payment->amount = $payable->getPayableAmount(); $payment->reference = $reference; $payable->payments->append(new OrderPayment($payment)); // Create the order $payable = $this->get('order.create')->setUser($payable->user)->create($payable); // Generate a success url $salt = $this->get('cfg')->payment->salt; $successful = $this->generateUrl('ms.ecom.checkout.payment.successful', array('orderID' => $payable->id, 'hash' => $this->get('checkout.hash')->encrypt($payable->id, $salt)), UrlGeneratorInterface::ABSOLUTE_URL); // Save gateway against payment $gateway = $this->get('http.session')->get('gateway.current'); // If gateway is not set on session, get default gateway if (null === $gateway) { $gatewayNames = $this->get('cfg')->payment->gateway; $gatewayName = is_array($gatewayNames) ? array_shift($gatewayNames) : $gatewayNames; $gateway = $this->get('gateway.collection')->get($gatewayName); } $this->get('payment.gateway.edit')->save($payment, $gateway); // Create json response with the success url return new JsonResponse(['url' => $successful]); }
/** * Complete an exchange balance payment reducing the return's remaining * balance by the amount paid and appending a new payment to the * related order. * * {@inheritDoc} */ public function success(PayableInterface $payable, $reference, MethodInterface $method) { // Get the amount before adjusting the balance to ensure we can use it // afterwards $amount = $payable->getPayableAmount(); $this->get('return.edit')->addPayment($payable, $method, $amount, $reference); // Generate the successful url $salt = $this->get('cfg')->payment->salt; $hash = $this->get('checkout.hash')->encrypt($payable->id, $salt); $successful = $this->generateUrl('ms.ecom.return.balance.successful', ['returnID' => $payable->id, 'hash' => $hash], UrlGeneratorInterface::ABSOLUTE_URL); // Return a JSON response with the successful url $response = new JsonResponse(); $response->setData(['url' => $successful]); return $response; }
public function getAmountBySmallestCurrencyUnit(PayableInterface $payable) { return in_array($payable->getPayableCurrency(), $this->_zeroDecimalCurrencies) ? (int) $payable->getPayableAmount() : (int) ($payable->getPayableAmount() * 100); }
public function failure(PayableInterface $payable) { $this->addFlash('error', sprintf('Could not refund %s %s to customer. Please refund the amount manually.', number_format($payable->getPayableAmount(), 2), $payable->getPayableCurrency())); return $this->redirectToRoute($this->_url, ['orderID' => $payable->getOrder()->id]); }