public function testSetGetProcessedAmount()
 {
     $transaction = new FinancialTransaction();
     $this->assertEquals(0.0, $transaction->getProcessedAmount());
     $transaction->setProcessedAmount(1.2345);
     $this->assertEquals(1.2345, $transaction->getProcessedAmount());
 }
 public function testDeposit()
 {
     $controller = $this->getController(array(), false);
     $controller->addPlugin($plugin = $this->getPlugin());
     $plugin->expects($this->once())->method('deposit');
     $controller->expects($this->once())->method('buildFinancialTransaction')->will($this->returnCallback(function () {
         $transaction = new FinancialTransaction();
         $transaction->setProcessedAmount(123.45);
         $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
         $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
         return $transaction;
     }));
     $payment = $this->getPayment();
     $payment->setState(PaymentInterface::STATE_APPROVED);
     $payment->setApprovedAmount(123.45);
     $instruction = $payment->getPaymentInstruction();
     $instruction->setState(PaymentInstructionInterface::STATE_VALID);
     $instruction->setApprovedAmount(10);
     $result = $this->callDeposit($controller, array($payment, 123.45));
     $this->assertEquals(Result::STATUS_SUCCESS, $result->getStatus(), 'Result status is not success: ' . $result->getReasonCode());
     $this->assertEquals(123.45, $payment->getDepositedAmount());
     $this->assertEquals(123.45, $instruction->getDepositedAmount());
     $this->assertEquals(PaymentInterface::STATE_DEPOSITED, $payment->getState());
     $this->assertEquals(0, $payment->getDepositingAmount());
     $this->assertEquals(0, $instruction->getDepositingAmount());
 }
 public function testDispatchesEvents()
 {
     $controller = $this->getController(array(), false, true);
     $payment = $this->getPayment();
     $instruction = $payment->getPaymentInstruction();
     $instruction->setState(PaymentInstructionInterface::STATE_VALID);
     $plugin = $this->getPlugin();
     $plugin->expects($this->once())->method('approve');
     $controller->addPlugin($plugin);
     $transaction = new FinancialTransaction();
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setProcessedAmount(50.12);
     $controller->expects($this->once())->method('buildFinancialTransaction')->will($this->returnValue($transaction));
     $this->dispatcher->expects($this->at(0))->method('dispatch')->with('payment.state_change', new PaymentStateChangeEvent($payment, PaymentInterface::STATE_NEW));
     $this->dispatcher->expects($this->at(1))->method('dispatch')->with('payment.state_change', new PaymentStateChangeEvent($payment, PaymentInterface::STATE_APPROVING));
     $this->dispatcher->expects($this->at(2))->method('dispatch')->with('payment_instruction.state_change', new PaymentInstructionStateChangeEvent($instruction, PaymentInstructionInterface::STATE_VALID));
     $this->callApprove($controller, array($payment, 100));
     $controller->closePaymentInstruction($instruction);
 }