public function createTransactionLog(Transaction $transaction) { $log = $this->createLog(); $log->setAccount($transaction->getAccount()); $log->setAmount($transaction->getVirtualAmount()); $log->setInformation($transaction->getInformation()); $transaction->setLog($log); return $log; }
protected function afterTransaction(Transaction $transaction) { // @change me into event $this->em->persist($transaction->getAccount()); if ($transaction->isLogginEnabled()) { $this->blm->persistTransactionLog($transaction); } if ($transaction->isInvoiceEnabled()) { $this->im->createFromTransaction($transaction); } }
public function finishSmsPayment(Account $account, SmsPayment $payment) { if ($payment->isFinished()) { return; } $transaction = new Transaction($account); $transaction->setAmount($payment->getAmount()); $transaction->setCurrency(CurrencyCode::VIRTUAL); $transaction->setInformation('Doładowanie poprzez sms'); $this->bank->deposit($transaction); $payment->setStatus(DotpayPaymentStatus::FINISHED); $this->updateSmsPayment($payment); }
public function testCreateLogFromTransaction() { $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $blm = $this->getManager($em); $account = new Account(); $t = new Transaction($account); $t->setAmount(1000); $t->setInformation('Test information'); $log = $blm->createLog($t); $this->assertInstanceOf('Hatimeria\\BankBundle\\Model\\BankLog', $log); $this->assertEquals('Test information', $log->getInformation()); $this->assertEquals($account, $log->getAccount()); $this->assertEquals(1000, $log->getAmount()); }
public function testDeposit() { $account = $this->getAccount(135); $exchanger = $this->getMock('\\Hatimeria\\BankBundle\\Bank\\CurrencyExchanger'); $exchanger->expects($this->atLeastOnce())->method('exchange')->with(45, CurrencyExchanger::PLN)->will($this->returnValue(450)); $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->atLeastOnce())->method('persist'); $bl = $this->getMock('\\Hatimeria\\BankBundle\\Model\\BankLog'); $blm = $this->getMockBuilder('\\Hatimeria\\BankBundle\\Model\\BankLogManager', array('createLog'))->disableOriginalConstructor()->getMock(); $blm->expects($this->atLeastOnce())->method('createLog')->will($this->returnValue($bl)); $blm->expects($this->atLeastOnce())->method('updateLog'); $t = new Transaction($account); $t->setAmount(45); $t->setCurrency(CurrencyExchanger::PLN); $t->setInformation('Test deposit'); $bank = new Bank($exchanger, $em, $blm); $bank->deposit($t); $this->assertBalance(585, $account); }
public function createFromTransaction(Transaction $transaction) { if (!$transaction->getAccount()->getUser()->isAccountable()) { return; } $invoice = new $this->class(); $invoice->setAccount($transaction->getAccount()); $invoice->setAmount($transaction->getAmount()); $invoice->setTitle($transaction->getInformation()); $invoice->generateNumber($this, $transaction); $this->em->persist($invoice); }
public function testExecuteDotpayPayment() { $account = new Account(); $t = new Transaction($account); $t->setAmount(431); $t->setCurrency(CurrencyCode::PLN); $t->setInformation('Doładowanie poprzez dotpay 3'); $dp = $this->getMock('Hatimeria\\BankBundle\\Tests\\TestEntity\\DotpayPayment'); $dp->expects($this->atLeastOnce())->method('isFinished')->will($this->returnValue(false)); $dp->expects($this->once())->method('getAccount')->will($this->returnValue($account)); $dp->expects($this->once())->method('setStatus')->with(DotpayPaymentStatus::FINISHED); $repository = $this->getMockBuilder('\\Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('findOneBy')->with(array('control' => 'test1234'))->will($this->returnValue($dp)); $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->once())->method('getRepository')->with('Hatimeria\\BankBundle\\Tests\\TestEntity\\DotpayPayment')->will($this->returnValue($repository)); $bank = $this->getMockBuilder('\\Hatimeria\\BankBundle\\Bank\\Bank')->disableOriginalConstructor()->getMock(); $bank->expects($this->atLeastOnce())->method('deposit')->with($t); $response = $this->getMock('\\Hatimeria\\DotpayBundle\\Response\\Response'); $response->expects($this->atLeastOnce())->method('getControl')->will($this->returnValue('test1234')); $response->expects($this->atLeastOnce())->method('isStatusMade')->will($this->returnValue(true)); $response->expects($this->once())->method('getTransactionId')->will($this->returnValue(3)); $response->expects($this->atLeastOnce())->method('getAmount')->will($this->returnValue(431)); $event = $this->getMockBuilder('\\Hatimeria\\DotpayBundle\\Event\\Event')->disableOriginalConstructor()->getMock(); $event->expects($this->atLeastOnce())->method('getSubject')->will($this->returnValue($response)); $event->expects($this->atLeastOnce())->method('setResult')->with(true); $pm = $this->getManager($em, $bank); $pm->executeDotpayPayment($event); }
/** * @todo move to better place * * @param type $service * @param type $account */ public function addServiceToAccount($service, $account) { if ($service instanceof VirtualPackage) { $transaction = new Transaction($account); $transaction->enableInvoice(); $transaction->enableLogging(); $transaction->setAmount($service->getCost()); $transaction->setVirtualAmount($service->getAmount()); $transaction->setInformation($service->getDescription()); $transaction->disableExchange(); $this->bank->deposit($transaction); } elseif ($service instanceof SubscriptionService) { $this->sa->add($service, $account); } else { throw new BankException("Unsupported service object class"); } }