Пример #1
0
 public function generateInvoiceAction()
 {
     if ($this->getRequest()->isGet()) {
         $sessionid = $this->_getParam('id');
         $config = new Zend_Config_Ini(APPLICATION_PATH . '/forms/session.ini', 'invoice');
         $this->view->form = new Zend_Form($config->session);
         $this->view->form->sessionid->setValue($sessionid);
     } else {
         if ($this->getRequest()->isPost()) {
             $inv = new Model_Invoice();
             $date = new Zend_Date();
             $inv->generationdate = $date->get(Zend_Date::W3C);
             $duedate = $date->add($this->_getParam('daystopay'), Zend_Date::DAY);
             $inv->duedate = $duedate->get(Zend_Date::W3C);
             $inv->amount = $this->_getParam('amount');
             $inv->save();
             $session = Model_Session::findOneById($this->_getParam('id'));
             $session->invoiceid = $inv->id;
             $session->save();
             $this->_redirect('/admin/');
         } else {
             $this->_redirect('/admin/');
         }
     }
 }
 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);
 }
Пример #3
0
 public function testCheckoutCart()
 {
     $cart = new \Model_Cart();
     $cart->loadBean(new \RedBeanPHP\OODBBean());
     $cart->promo_id = rand(1, 100);
     $order = new \Model_ClientOrder();
     $order->loadBean(new \RedBeanPHP\OODBBean());
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('createFromCart', 'isClientAbleToUsePromo', 'rm'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('createFromCart')->will($this->returnValue(array($order, rand(1, 100), array(rand(1, 100)))));
     $serviceMock->expects($this->atLeastOnce())->method('isClientAbleToUsePromo')->will($this->returnValue(true));
     $serviceMock->expects($this->atLeastOnce())->method('rm')->will($this->returnValue(true));
     $eventMock = $this->getMockBuilder('\\Box_EventManager')->getMock();
     $eventMock->expects($this->atLeastOnce())->method('fire');
     $requestMock = $this->getMockBuilder('\\Box_Request')->getMock();
     $requestMock->expects($this->atLeastOnce())->method('getClientAddress')->will($this->returnValue('1.1.1.1'));
     $invoice = new \Model_Invoice();
     $invoice->loadBean(new \RedBeanPHP\OODBBean());
     $invoice->hash = sha1('str');
     $promo = new \Model_Promo();
     $promo->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($promo));
     $client = new \Model_Client();
     $client->loadBean(new \RedBeanPHP\OODBBean());
     $di = new \Box_Di();
     $di['events_manager'] = $eventMock;
     $di['db'] = $dbMock;
     $di['logger'] = $this->getMockBuilder('Box_Log')->getMock();
     $di['request'] = $requestMock;
     $serviceMock->setDi($di);
     $result = $serviceMock->checkoutCart($cart, $client);
     $this->assertInternalType('array', $result);
     $this->assertArrayHasKey('gateway_id', $result);
     $this->assertArrayHasKey('invoice_hash', $result);
     $this->assertArrayHasKey('order_id', $result);
     $this->assertArrayHasKey('orders', $result);
 }
Пример #4
0
 public function testdelete()
 {
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray');
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('deleteInvoiceByClient')->will($this->returnValue(true));
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $model = new \Model_Invoice();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('findOne')->will($this->returnValue($model));
     $di = new \Box_Di();
     $di['validator'] = $validatorMock;
     $di['db'] = $dbMock;
     $di['logger'] = new \Box_Log();
     $this->api->setDi($di);
     $this->api->setService($serviceMock);
     $identity = new \Model_Client();
     $identity->loadBean(new \RedBeanPHP\OODBBean());
     $this->api->setIdentity($identity);
     $data['hash'] = md5(1);
     $result = $this->api->delete($data);
     $this->assertInternalType('bool', $result);
     $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);
 }
 public function testgetInvoiceTitle_MultipleItems()
 {
     $queryResult = array(array('title' => 'Hosting premium'), array('title' => 'Domain name'));
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getAll')->willReturn($queryResult);
     $di['db'] = $dbMock;
     $adapter = new Payment_Adapter_Stripe($this->defaultConfig);
     $adapter->setDi($di);
     $model = new \Model_Invoice();
     $model->loadBean(new RedBeanPHP\OODBBean());
     $model->nr = 1;
     $model->serie = 'BOX';
     $result = $adapter->getInvoiceTitle($model);
     $expectedTitle = sprintf('Payment for invoice %s%05s', $model->serie, $model->nr);
     $this->assertEquals($expectedTitle, $result);
 }
 /**
  * @dataProvider amountsProvider
  */
 public function testenoughInBalanceToCoverInvoice($inBalance, $invoiceSum, $expectedResult)
 {
     $di = new \Box_Di();
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $clientModel = new Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('load')->with('Client')->willReturn($clientModel);
     $di['db'] = $dbMock;
     $clientBalanceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Client\\ServiceBalance')->getMock();
     $clientBalanceServiceMock->expects($this->atLeastOnce())->method('getClientBalance')->with($clientModel)->willReturn($inBalance);
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
     $invoiceServiceMock->expects($this->atLeastOnce())->method('getTotalWithTax')->with($invoiceModel)->willReturn($invoiceSum);
     $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($invoiceServiceMock, $clientBalanceServiceMock) {
         if ('Invoice' == $serviceName) {
             return $invoiceServiceMock;
         }
         if ('Client' == $serviceName && $sub == 'Balance') {
             return $clientBalanceServiceMock;
         }
     });
     $adapter = new Payment_Adapter_ClientBalance();
     $adapter->setDi($di);
     $result = $adapter->enoughInBalanceToCoverInvoice($invoiceModel);
     $this->assertEquals($expectedResult, $result);
 }
 public function testgetPaymentAdapter_PaymentGatewayNotFound()
 {
     $payGatewayModel = new \Model_PayGateway();
     $payGatewayModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServicePayGateway')->setMethods(array('getConfig', 'getAdapterClassName'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('getAdapterClassName')->will($this->returnValue(null));
     $toolsMock = $this->getMockBuilder('\\Box_Tools')->getMock();
     $toolsMock->expects($this->atLeastOnce())->method('decodeJ')->willReturn(array());
     $urlMock = $this->getMockBuilder('\\Box_Url')->getMock();
     $urlMock->expects($this->atLeastOnce())->method('link');
     $di = new \Box_Di();
     $di['config'] = array('url' => 'http://boxbilling.vm/', 'debug' => true);
     $di['tools'] = $toolsMock;
     $di['url'] = $urlMock;
     $serviceMock->setDi($di);
     $this->setExpectedException('\\Box_Exception', 'Payment gateway  was not found');
     $serviceMock->getPaymentAdapter($payGatewayModel, $invoiceModel);
 }
Пример #9
0
 public function testisInvoiceTypeDeposit_EmptyArray()
 {
     $di = new \Box_Di();
     $invoiceItems = array();
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('find')->with('InvoiceItem')->willReturn($invoiceItems);
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $modelInvoice = new \Model_Invoice();
     $modelInvoice->loadBean(new \RedBeanPHP\OODBBean());
     $result = $this->service->isInvoiceTypeDeposit($modelInvoice);
     $this->assertFalse($result);
 }
Пример #10
0
 public function testcreditInvoiceItem()
 {
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceInvoiceItem')->setMethods(array('getTotalWithTax'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('getTotalWithTax')->will($this->returnValue(11.2));
     $invoiceItemModel = new \Model_InvoiceItem();
     $invoiceItemModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $clientModel = new \Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $clientBalanceModel = new \Model_Client();
     $clientBalanceModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->onConsecutiveCalls($invoiceModel, $clientModel));
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($clientBalanceModel));
     $dbMock->expects($this->atLeastOnce())->method('store');
     $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
     $invoiceServiceMock->expects($this->atLeastOnce())->method('addNote');
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function () use($invoiceServiceMock) {
         return $invoiceServiceMock;
     });
     $serviceMock->setDi($di);
     $serviceMock->creditInvoiceItem($invoiceItemModel);
 }
Пример #11
0
 public function testcanChangeCurrencyHasInvoice()
 {
     $currency = 'EUR';
     $model = new \Model_Client();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $model->id = rand(1, 100);
     $model->currency = 'USD';
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $database = $this->getMockBuilder('\\Box_Database')->getMock();
     $database->expects($this->at(0))->method('findOne')->will($this->returnValue($invoiceModel));
     $di = new \Box_Di();
     $di['db'] = $database;
     $clientService = new \Box\Mod\Client\Service();
     $clientService->setDi($di);
     $this->setExpectedException('\\Box_Exception', 'Currency can not be changed. Client already have invoices issued.');
     $clientService->canChangeCurrency($model, $currency);
 }
Пример #12
0
 public function testsend_reminder()
 {
     $data = array('id' => 1);
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('sendInvoiceReminder')->will($this->returnValue(true));
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray');
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $model = new \Model_Invoice();
     $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;
     $this->api->setDi($di);
     $this->api->setService($serviceMock);
     $result = $this->api->send_reminder($data);
     $this->assertInternalType('bool', $result);
     $this->assertTrue($result);
 }
 public function testgetSubscriptionPeriod()
 {
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceSubscription')->setMethods(array('isSubscribable'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('isSubscribable')->will($this->returnValue(true));
     $period = '1W';
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getCell')->will($this->returnValue($period));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $serviceMock->setDi($di);
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $result = $serviceMock->getSubscriptionPeriod($invoiceModel);
     $this->assertInternalType('string', $result);
     $this->assertEquals($period, $result);
 }
Пример #14
0
 public function testgetTax()
 {
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceModel->taxrate = 15;
     $invoiceItemModel = new \Model_InvoiceItem();
     $invoiceItemModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceItemModel->quantity = 1;
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('find')->willReturn(array($invoiceItemModel));
     $invoiceItemService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceInvoiceItem')->getMock();
     $invoiceItemService->expects($this->atLeastOnce())->method('getTax')->willReturn(21);
     $di = new \Box_Di();
     $di['mod_service'] = $di->protect(function () use($invoiceItemService) {
         return $invoiceItemService;
     });
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $result = $this->service->getTax($invoiceModel);
     $this->assertInternalType('int', $result);
 }
Пример #15
0
 public function testupdateInvoiceIsPaid()
 {
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray');
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $model = new \Model_Invoice();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $model->status = 'paid';
     $dbMock->expects($this->atLeastOnce())->method('findOne')->will($this->returnValue($model));
     $di = new \Box_Di();
     $di['validator'] = $validatorMock;
     $di['db'] = $dbMock;
     $this->api->setDi($di);
     $this->api->setIdentity(new \Model_Admin());
     $data['hash'] = md5(1);
     $this->setExpectedException('\\Box_Exception', 'Paid Invoice can not be modified');
     $this->api->update($data);
 }
Пример #16
0
 public function doVerifyTransaction(array $options = array())
 {
     $this->setOptions($options);
     $this->_checkRequiredOptions(array('referenceId', 'merchantCode'));
     try {
         $soapClient = new SoapClient($this->getWSDL());
         $invoice = Model_Invoice::id($this->getInvoiceId());
         $pin = $this->_config['merchantCode'];
         $au = $this->_config['referenceId'];
         $amount = $invoice->price;
         $status = 1;
         $res = $soapClient->PaymentVerification($pin, $au, $amount, $status);
     } catch (SoapFault $e) {
         $this->log($e->getMessage());
         throw new Exception('SOAP Exception: ' . $e->getMessage());
     }
     if ($res == 1) {
         return 1;
     } else {
         return $res;
     }
     // VerifyError
 }