public function executeDotpayPayment($payment) { $account = $payment->getAccount(); if ($payment->isCharge()) { $transaction = new Transaction($account); $transaction->setAmount($payment->getAmount()); $transaction->setCurrency(CurrencyCode::PLN); // @todo better information, extensionable $transaction->setInformation("Doładowanie konta"); $transaction->enableLogging(); $this->bank->deposit($transaction); } else { $service = $this->finder->code($payment->getService()); $this->addServiceToAccount($service, $account); } $payment->setStatus(DotpayPaymentStatus::FINISHED); $this->updateDotpayPayment($payment); }
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 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); }
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); }