/** * {@inheritdoc} * * @param $request Capture */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); /** @var $payment SyliusPaymentInterface */ $payment = $request->getModel(); /** @var OrderInterface $order */ $order = $payment->getOrder(); $this->gateway->execute($status = new GetStatus($payment)); if ($status->isNew()) { try { $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken())); $payment->setDetails($convert->getResult()); } catch (RequestNotSupportedException $e) { $totalAmount = $order->getTotal(); $payumPayment = new PayumPayment(); $payumPayment->setNumber($order->getNumber()); $payumPayment->setTotalAmount($totalAmount); $payumPayment->setCurrencyCode($order->getCurrencyCode()); $payumPayment->setClientEmail($order->getCustomer()->getEmail()); $payumPayment->setClientId($order->getCustomer()->getId()); $payumPayment->setDescription(sprintf('Payment contains %d items for a total of %01.2f', $order->getItems()->count(), round($totalAmount / 100, 2))); $payumPayment->setDetails($payment->getDetails()); $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken())); $payment->setDetails($convert->getResult()); } } $details = ArrayObject::ensureArrayObject($payment->getDetails()); try { $request->setModel($details); $this->gateway->execute($request); } finally { $payment->setDetails((array) $details); } }
/** * {@inheritDoc} */ public function onPostExecute(Context $context) { if ($context->getPrevious()) { return; } /** @var Generic $request */ $request = $context->getRequest(); if (false === $request instanceof Generic) { return; } if (false === $request instanceof GetStatusInterface) { return; } /** @var PaymentInterface $payment */ $payment = $request->getFirstModel(); if (false === $payment instanceof PaymentInterface) { return; } $context->getGateway()->execute($status = new GetStatus($payment)); if ($payment->getState() !== $status->getValue()) { $this->updatePaymentState($payment, $status->getValue()); } }