/**
  * {@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;
     }
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function shouldKeepOrderEvenIfExceptionThrown()
 {
     $details = array('foo' => 'fooVal');
     $order = new Order();
     $order->setDetails($details);
     $paymentMock = $this->createPaymentMock();
     $paymentMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\Notify'))->will($this->throwException(new \Exception()));
     $action = new NotifyOrderAction();
     $action->setPayment($paymentMock);
     $this->setExpectedException('Exception');
     $action->execute($capture = new Notify($order));
     $this->assertSame($order, $capture->getModel());
 }
    /**
     * @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']);
    }
    /**
     * @test
     */
    public function shouldSetDetailsBackToOrderEvenIfExceptionThrown()
    {
        $expectedDetails = array('foo' => 'fooVal');

        $order = new Order();
        $order->setDetails($expectedDetails);

        $paymentMock = $this->createPaymentMock();
        $paymentMock
            ->expects($this->at(0))
            ->method('execute')
            ->with($this->isInstanceOf('Payum\Core\Request\GetHumanStatus'))
            ->will($this->returnCallback(function (GetHumanStatus $request) {
                $request->markPending();
            }))
        ;
        $paymentMock
            ->expects($this->at(1))
            ->method('execute')
            ->with($this->isInstanceOf('Payum\Core\Request\Capture'))
            ->will($this->returnCallback(function (Capture $request) {
                $details = $request->getModel();
                $details['bar'] = 'barVal';

                throw new \Exception();
            }))
        ;

        $action = new CaptureOrderAction();
        $action->setPayment($paymentMock);

        $this->setExpectedException('Exception');
        $action->execute($capture = new Capture($order));

        $this->assertSame($order, $capture->getFirstModel());
        $this->assertInstanceOf('ArrayAccess', $capture->getModel());
        $this->assertEquals(array('foo' => 'fooVal', 'bar' => 'barVal'), $order->getDetails());
    }
Exemplo n.º 5
0
 /**
  * @test
  */
 public function shouldKeepOrderEvenIfExceptionThrown()
 {
     $details = array('foo' => 'fooVal');
     $order = new Order();
     $order->setDetails($details);
     $paymentMock = $this->createPaymentMock();
     $paymentMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\GetHumanStatus'))->will($this->returnCallback(function (GetHumanStatus $request) {
         $request->markPending();
     }));
     $paymentMock->expects($this->at(1))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\Capture'))->will($this->throwException(new \Exception()));
     $action = new CaptureOrderAction();
     $action->setPayment($paymentMock);
     $this->setExpectedException('Exception');
     $action->execute($capture = new Capture($order));
     $this->assertSame($order, $capture->getModel());
 }