/**
  * {@inheritDoc}
  *
  * @param $request Capture
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     /** @var $payment PaymentInterface */
     $payment = $request->getModel();
     $order = $payment->getOrder();
     $payumOrder = new Order();
     $payumOrder->setNumber($order->getNumber());
     $payumOrder->setTotalAmount($order->getTotal());
     $payumOrder->setCurrencyCode($order->getCurrency());
     $payumOrder->setClientEmail($order->getEmail());
     $payumOrder->setClientId($order->getUser() ? $order->getUser()->getId() : $order->getEmail());
     $payumOrder->setDescription(sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100));
     $payumOrder->setDetails($payment->getDetails());
     try {
         $request->setModel($payumOrder);
         $this->payment->execute($request);
         $payment->setDetails($payumOrder->getDetails());
         $request->setModel($payment);
     } catch (\Exception $e) {
         $payment->setDetails($payumOrder->getDetails());
         $request->setModel($payment);
         throw $e;
     }
 }
    /**
     * @test
     */
    public function shouldNotOverwriteAlreadySetExtraDetails()
    {
        $order = new Order();
        $order->setCurrencyCode('USD');
        $order->setTotalAmount(123);
        $order->setDescription('the description');
        $order->setDetails(array(
            'foo' => 'fooVal',
        ));

        $action = new FillOrderDetailsAction();

        $action->execute(new FillOrderDetails($order));

        $details = $order->getDetails();

        $this->assertNotEmpty($details);

        $this->assertArrayHasKey('foo', $details);
        $this->assertEquals('fooVal', $details['foo']);
    }