public function testdebitTransaction()
 {
     $currency = 'EUR';
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceModel->currency = $currency;
     $clientModdel = new \Model_Client();
     $clientModdel->loadBean(new \RedBeanPHP\OODBBean());
     $clientModdel->currency = $currency;
     $transactionModel = new \Model_Transaction();
     $transactionModel->loadBean(new \RedBeanPHP\OODBBean());
     $transactionModel->amount = 11;
     $clientBalanceModel = new \Model_ClientBalance();
     $clientBalanceModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('load')->will($this->onConsecutiveCalls($invoiceModel, $clientModdel));
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($clientBalanceModel));
     $dbMock->expects($this->atLeastOnce())->method('store');
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $this->service->debitTransaction($transactionModel);
 }
 public function testprocessTransaction_invoiceIdIsNotSet()
 {
     $adapterMock = $this->getMockBuilder('Payment_Adapter_ClientBalance')->disableOriginalConstructor()->setMethods(array('isIpnValid'))->getMock();
     $adapterMock->expects($this->atLeastOnce())->method('isIpnValid')->willReturn(true);
     $di = new \Box_Di();
     $transactionModel = new \Model_Transaction();
     $transactionModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('load')->withConsecutive(array('Transaction'), array('Invoice'))->willReturnOnConsecutiveCalls($transactionModel, $invoiceModel);
     $dbMock->expects($this->atLeastOnce())->method('store')->with($transactionModel);
     $di['db'] = $dbMock;
     $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
     $invoiceServiceMock->expects($this->atLeastOnce())->method('isInvoiceTypeDeposit')->with($invoiceModel)->willReturn(false);
     $invoiceServiceMock->expects($this->never())->method('payInvoiceWithCredits')->with($invoiceModel);
     $invoiceServiceMock->expects($this->once())->method('doBatchPayWithCredits');
     $di['mod_service'] = $di->protect(function ($serviceName) use($invoiceServiceMock) {
         if ('Invoice' == $serviceName) {
             return $invoiceServiceMock;
         }
     });
     $transactionId = 1;
     $data = array('get' => array());
     $gatewayId = 1;
     $adapterMock->setDi($di);
     $result = $adapterMock->processTransaction(null, $transactionId, $data, $gatewayId);
     $this->assertTrue($result);
 }
 public function testprocessTransaction_IpnDuplicate()
 {
     $adapterMock = $this->getMockBuilder('\\Payment_Adapter_Interkassa')->disableOriginalConstructor()->setMethods(array('isIpnValid', 'isIpnDuplicate'))->getMock();
     $adapterMock->expects($this->atLeastOnce())->method('isIpnValid')->willReturn(true);
     $adapterMock->expects($this->atLeastOnce())->method('isIpnDuplicate')->willReturn(true);
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $transactionModel = new \Model_Transaction();
     $transactionModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $clientModel = new \Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('load')->withConsecutive(array('Transaction'), array('Invoice'), array('Client'))->willReturnOnConsecutiveCalls($transactionModel, $invoiceModel, $clientModel);
     $dbMock->expects($this->atLeastOnce())->method('store')->with($transactionModel);
     $clientServiceMock = $this->getMockBuilder('\\Box\\Mod\\Client\\Service')->getMock();
     $clientServiceMock->expects($this->never())->method('addFunds');
     $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
     $invoiceServiceMock->expects($this->never())->method('payInvoiceWithCredits')->with($invoiceModel);
     $invoiceServiceMock->expects($this->never())->method('doBatchPayWithCredits');
     $di = new \Box_Di();
     $di['mod_service'] = $di->protect(function ($serviceName) use($clientServiceMock, $invoiceServiceMock) {
         if ($serviceName == 'Client') {
             return $clientServiceMock;
         }
         if ($serviceName == 'Invoice') {
             return $invoiceServiceMock;
         }
     });
     $di['db'] = $dbMock;
     $adapterMock->setDi($di);
     $adminModel = new \Model_Admin();
     $api_admin = new \Api_Handler($adminModel);
     $transaction_id = 1;
     $invoice_id = 22;
     $data = array('post' => array('ik_x_iid' => $invoice_id, 'ik_trn_id' => 2, 'ik_inv_st' => 'success', 'ik_am' => 1.0, 'ik_cur' => 'USD'), 'get' => array('bb_invoice_id' => $invoice_id));
     $gateway_id = 1;
     $this->setExpectedException('Payment_Exception', 'IPN is duplicate');
     $adapterMock->processTransaction($api_admin, $transaction_id, $data, $gateway_id);
 }
Example #4
0
 public function testtransaction_get()
 {
     $data = array('id' => 1);
     $transactionService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceTransaction')->getMock();
     $transactionService->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array()));
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray');
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $model = new \Model_Transaction();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model));
     $di = new \Box_Di();
     $di['validator'] = $validatorMock;
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function () use($transactionService) {
         return $transactionService;
     });
     $this->api->setDi($di);
     $result = $this->api->transaction_get($data);
     $this->assertInternalType('array', $result);
 }