public function testtoApiArray()
 {
     $subscriptionModel = new \Model_Subscription();
     $subscriptionModel->loadBean(new \RedBeanPHP\OODBBean());
     $clientModel = new \Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $gatewayModel = new \Model_PayGateway();
     $gatewayModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('load')->will($this->onConsecutiveCalls($clientModel, $gatewayModel));
     $clientServiceMock = $this->getMockBuilder('\\Box\\Mod\\Client\\Service')->getMock();
     $clientServiceMock->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array()));
     $payGatewayService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServicePayGateway')->getMock();
     $payGatewayService->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array()));
     $di = new \Box_Di();
     $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($clientServiceMock, $payGatewayService) {
         if ($serviceName == 'Client') {
             return $clientServiceMock;
         }
         if ($sub == 'PayGateway') {
             return $payGatewayService;
         }
     });
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $expected = array('id' => '', 'sid' => '', 'period' => '', 'amount' => '', 'currency' => '', 'status' => '', 'created_at' => '', 'updated_at' => '', 'client' => array(), 'gateway' => array());
     $result = $this->service->toApiArray($subscriptionModel);
     $this->assertInternalType('array', $result);
     $this->assertInternalType('array', $result['client']);
     $this->assertInternalType('array', $result['gateway']);
     $this->assertEquals($expected, $result);
 }
 /**
  * @dataProvider paymentsAdapterProvider_withprocessTransaction
  */
 public function testprocessTransaction_supportProcessTransaction($adapter)
 {
     $id = 1;
     $transactionModel = new \Model_Transaction();
     $transactionModel->loadBean(new \RedBeanPHP\OODBBean());
     $transactionModel->gateway_id = 2;
     $transactionModel->ipn = '{}';
     $payGatewayModel = new \Model_PayGateway();
     $payGatewayModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('load')->will($this->onConsecutiveCalls($transactionModel, $payGatewayModel));
     $paymentAdapterMock = $this->getMockBuilder($adapter)->disableOriginalConstructor()->getMock();
     $paymentAdapterMock->expects($this->atLeastOnce())->method('processTransaction');
     $payGatewayService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServicePayGateway')->getMock();
     $payGatewayService->expects($this->atLeastOnce())->method('getPaymentAdapter')->will($this->returnValue($paymentAdapterMock));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function () use($payGatewayService) {
         return $payGatewayService;
     });
     $di['api_system'] = new \Api_Handler(new \Model_Admin());
     $this->service->setDi($di);
     $this->service->processTransaction($id);
 }
 public function testgetServiceUrl_InvoiceTypeDeposit()
 {
     $di = new \Box_Di();
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $payGatewayModel = new \Model_PayGateway();
     $payGatewayModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('findOne')->with('PayGateway')->willReturn($payGatewayModel);
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('load')->with('Invoice')->willReturn($invoiceModel);
     $di['db'] = $dbMock;
     $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
     $invoiceServiceMock->expects($this->atLeastOnce())->method('isInvoiceTypeDeposit')->with($invoiceModel)->willReturn(true);
     $di['mod_service'] = $di->protect(function ($serviceName) use($invoiceServiceMock) {
         if ('Invoice' == $serviceName) {
             return $invoiceServiceMock;
         }
     });
     $adapter = new \Payment_Adapter_ClientBalance();
     $adapter->setDi($di);
     $this->setExpectedException('Payment_Exception', 'Forbidden to pay deposit invoice with this gateway', 302);
     $adapter->getServiceUrl();
 }
 public function testgetDescriptionEmptyDescription()
 {
     $payGatewayModel = new \Model_PayGateway();
     $payGatewayModel->loadBean(new \RedBeanPHP\OODBBean());
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServicePayGateway')->setMethods(array('getAdapterConfig'))->getMock();
     $config = array();
     $serviceMock->expects($this->atLeastOnce())->method('getAdapterConfig')->will($this->returnValue($config));
     $result = $serviceMock->getDescription($payGatewayModel);
     $this->assertInternalType('null', $result);
 }
Example #5
0
 public function testprocessInvoice()
 {
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->setMethods(array('getPaymentInvoice'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('getPaymentInvoice')->willReturn(new \Payment_Invoice());
     $data = array('hash' => 'hashString', 'gateway_id' => 2);
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $payGatewayModel = new \Model_PayGateway();
     $payGatewayModel->loadBean(new \RedBeanPHP\OODBBean());
     $payGatewayModel->enabled = true;
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('findOne')->willReturn($invoiceModel);
     $dbMock->expects($this->atLeastOnce())->method('load')->willReturn($payGatewayModel);
     $subcribeService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceSubscription')->getMock();
     $subcribeService->expects($this->atLeastOnce())->method('isSubscribable')->will($this->returnValue(true));
     $payGatewayService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServicePayGateway')->getMock();
     $payGatewayService->expects($this->atLeastOnce())->method('canPerformRecurrentPayment')->will($this->returnValue(true));
     $adapterMock = $this->getMockBuilder('\\Payment_Adapter_Dummy')->disableOriginalConstructor()->getMock();
     $adapterMock->expects($this->atLeastOnce())->method('setDi');
     $adapterMock->expects($this->atLeastOnce())->method('getConfig')->willReturn(array());
     $payGatewayService->expects($this->atLeastOnce())->method('getPaymentAdapter')->will($this->returnValue($adapterMock));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($payGatewayService, $subcribeService) {
         if ($sub == 'PayGateway') {
             return $payGatewayService;
         }
         if ($sub == 'Subscription') {
             return $subcribeService;
         }
     });
     $di['api_admin'] = new \Api_Handler(new \Model_Admin());
     $di['logger'] = new \Box_Log();
     $serviceMock->setDi($di);
     $result = $serviceMock->processInvoice($data);
     $this->assertInternalType('array', $result);
     $this->assertArrayHasKey('type', $result);
     $this->assertArrayHasKey('service_url', $result);
     $this->assertArrayHasKey('subscription', $result);
     $this->assertArrayHasKey('result', $result);
 }
Example #6
0
 public function testsubscription_createCurrencyMismatch()
 {
     $data = array('client_id' => 1, 'gateway_id' => 1, 'currency' => 'EU');
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray');
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $model = new \Model_PayGateway();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $client = new \Model_Client();
     $client->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->onConsecutiveCalls($client, $model));
     $di = new \Box_Di();
     $di['validator'] = $validatorMock;
     $di['db'] = $dbMock;
     $this->api->setDi($di);
     $this->setExpectedException('\\Box_Exception', 'Client currency must match subscription currency. Check if clients currency is defined.');
     $this->api->subscription_create($data);
 }