public function testGetReverseCreditTransactions()
 {
     $credit = new Credit($this->getInstruction(), 100);
     $this->assertEquals(0, count($credit->getReverseCreditTransactions()));
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT);
     $credit->addTransaction($transaction);
     $this->assertEquals(1, count($credit->getReverseCreditTransactions()));
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT);
     $credit->addTransaction($transaction);
     $this->assertEquals(2, count($credit->getReverseCreditTransactions()));
     $transaction = new FinancialTransaction();
     $credit->addTransaction($transaction);
     $this->assertEquals(2, count($credit->getReverseCreditTransactions()));
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT);
     $credit->addTransaction($transaction);
     $this->assertEquals(3, count($credit->getReverseCreditTransactions()));
     $transaction = new FinancialTransaction();
     $credit->addTransaction($transaction);
     $this->assertEquals(3, count($credit->getReverseCreditTransactions()));
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT);
     $credit->addTransaction($transaction);
     $this->assertEquals(4, count($credit->getReverseCreditTransactions()));
 }
 public function testApproveAndDepositPluginReturnsSuccessfulResponseInRetryTransaction()
 {
     $controller = $this->getController();
     $payment = $this->getPayment();
     $payment->setState(PaymentInterface::STATE_APPROVING);
     $payment->setApprovingAmount(100);
     $payment->setDepositingAmount(100);
     $instruction = $payment->getPaymentInstruction();
     $instruction->setState(PaymentInstructionInterface::STATE_VALID);
     $instruction->setApprovedAmount(30);
     $instruction->setDepositedAmount(20);
     $instruction->setApprovingAmount(110);
     $instruction->setDepositingAmount(110);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransactionInterface::TRANSACTION_TYPE_APPROVE_AND_DEPOSIT);
     $transaction->setState(FinancialTransactionInterface::STATE_PENDING);
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setProcessedAmount(50);
     $payment->addTransaction($transaction);
     $plugin = $this->getPlugin();
     $plugin->expects($this->once())->method('approveAndDeposit');
     $controller->addPlugin($plugin);
     $result = $this->callApproveAndDeposit($controller, array($payment, 100));
     $this->assertInstanceOf('JMS\\Payment\\CoreBundle\\PluginController\\Result', $result);
     $this->assertSame($transaction, $result->getFinancialTransaction());
     $this->assertSame(Result::STATUS_SUCCESS, $result->getStatus());
     $this->assertSame(PluginInterface::REASON_CODE_SUCCESS, $result->getReasonCode());
     $this->assertSame(PaymentInterface::STATE_APPROVED, $payment->getState());
     $this->assertEquals(0, $payment->getApprovingAmount());
     $this->assertEquals(0, $payment->getDepositingAmount());
     $this->assertEquals(50, $payment->getApprovedAmount());
     $this->assertEquals(50, $payment->getDepositedAmount());
     $this->assertEquals(10, $instruction->getApprovingAmount());
     $this->assertEquals(10, $instruction->getDepositingAmount());
     $this->assertEquals(80, $instruction->getApprovedAmount());
     $this->assertEquals(70, $instruction->getDepositedAmount());
 }
 /**
  * Creates a payment with sample financial transactions:
  * - 1 APPROVE transaction
  * - 3 DEPOSIT transactions
  * - 2 REVERSE_APPROVAL transactions
  * - 4 REVERSE_DEPOSIT transactions
  * 
  * @return Payment
  */
 protected function getPayment()
 {
     $payment = new Payment($this->getInstruction(), 123.45);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_APPROVE);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_DEPOSIT);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_DEPOSIT);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_DEPOSIT);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_APPROVAL);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_APPROVAL);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT);
     $payment->addTransaction($transaction);
     $transaction = new FinancialTransaction();
     $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT);
     $payment->addTransaction($transaction);
     return $payment;
 }