/** * {@inheritdoc} */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); /** @var Payment $payment */ $payment = $request->getModel(); if ($payment->getDetails()) { return; } $invoice = $payment->getInvoice(); $details = []; $details['PAYMENTREQUEST_0_INVNUM'] = $invoice->getId() . '-' . $payment->getId(); $details['PAYMENTREQUEST_0_CURRENCYCODE'] = $payment->getCurrencyCode(); $details['PAYMENTREQUEST_0_AMT'] = number_format($this->formatter->toFloat($invoice->getTotal()), 2); $details['PAYMENTREQUEST_0_ITEMAMT'] = number_format($this->formatter->toFloat($invoice->getTotal()), 2); $counter = 0; foreach ($invoice->getItems() as $item) { /* @var \CSBill\InvoiceBundle\Entity\Item $item */ $details['L_PAYMENTREQUEST_0_NAME' . $counter] = $item->getDescription(); $details['L_PAYMENTREQUEST_0_AMT' . $counter] = number_format($this->formatter->toFloat($item->getPrice()), 2); $details['L_PAYMENTREQUEST_0_QTY' . $counter] = $item->getQty(); ++$counter; } if (null !== $invoice->getDiscount()) { $discount = $invoice->getBaseTotal()->multiply($invoice->getDiscount()); $details['L_PAYMENTREQUEST_0_NAME' . $counter] = 'Discount'; $details['L_PAYMENTREQUEST_0_AMT' . $counter] = '-' . number_format($this->formatter->toFloat($discount), 2); $details['L_PAYMENTREQUEST_0_QTY' . $counter] = 1; } if (null !== ($tax = $invoice->getTax())) { $details['L_PAYMENTREQUEST_0_NAME' . $counter] = 'Tax Total'; $details['L_PAYMENTREQUEST_0_AMT' . $counter] = number_format($this->formatter->toFloat($tax), 2); $details['L_PAYMENTREQUEST_0_QTY' . $counter] = 1; } /*$notifyUrl = $this->tokenFactory->createNotifyToken( $request->getToken()->getGatewayName(), $payment )->getTargetUrl(); $details['PAYMENTREQUEST_0_NOTIFYURL'] = $notifyUrl;*/ $payment->setDetails($details); $details = ArrayObject::ensureArrayObject($payment->getDetails()); try { $request->setModel($details); $this->gateway->execute($request); $payment->setDetails($details); $request->setModel($payment); } catch (\Exception $e) { $payment->setDetails($details); $request->setModel($payment); throw $e; } }
/** * @param JsonSerializationVisitor $visitor * @param Money $money * @param array $type * @param Context $context * * @return float */ public function serializeMoney(JsonSerializationVisitor $visitor, Money $money, array $type, Context $context) { return $this->formatter->toFloat($money); }