Ejemplo n.º 1
0
 public function betweenCustomers(Request\BetweenCustomers $request)
 {
     $result = new Response\BetweenCustomers();
     /* constraints validation results */
     $isCountriesTheSame = false;
     $isTargetInDownline = false;
     /* extract input parameters */
     $custIdDebit = $request->getFromCustomerId();
     $custIdCredit = $request->getToCustomerId();
     $date = $request->getDateApplied();
     $value = $request->getValue();
     $condForceAll = $request->getConditionForceAll();
     $condForceCountry = $request->getConditionForceCountry();
     $condForceDownline = $request->getConditionForceDownline();
     if (is_null($date)) {
         $date = $this->_toolDate->getUtcNowForDb();
     }
     /* validate conditions */
     if (!$condForceAll) {
         /* validate customer countries */
         $downDebit = $this->_repoMod->getDownlineCustomerById($custIdDebit);
         $downCredit = $this->_repoMod->getDownlineCustomerById($custIdCredit);
         /* countries should be equals */
         $countryDebit = $downDebit->getCountryCode();
         $countryCredit = $downCredit->getCountryCode();
         if ($countryDebit == $countryCredit || $condForceCountry) {
             $isCountriesTheSame = true;
         }
         /* transfer is allowed to own subtree only */
         $path = $downCredit->getPath();
         $key = Cfg::DTPS . $downDebit->getCustomerId() . Cfg::DTPS;
         if (strpos($path, $key) !== false || $condForceDownline) {
             $isTargetInDownline = true;
         }
     }
     /* check validation results and perform transfer */
     if ($condForceAll || $isTargetInDownline && $isCountriesTheSame) {
         /* get PV-accounts */
         $reqAccGet = new AccountGetRequest();
         $reqAccGet->setCustomerId($custIdDebit);
         $reqAccGet->setAssetTypeCode(Cfg::CODE_TYPE_ASSET_PV);
         $reqAccGet->setCreateNewAccountIfMissed(true);
         $respAccDebit = $this->_callAccount->get($reqAccGet);
         $reqAccGet->setCustomerId($custIdCredit);
         $respAccCredit = $this->_callAccount->get($reqAccGet);
         /* add transfer operation */
         $reqAddOper = new OperationAddRequest();
         $reqAddOper->setOperationTypeCode(Cfg::CODE_TYPE_OPER_PV_TRANSFER);
         $reqAddOper->setDatePerformed($date);
         $reqAddOper->setTransactions([[Transaction::ATTR_DEBIT_ACC_ID => $respAccDebit->getId(), Transaction::ATTR_CREDIT_ACC_ID => $respAccCredit->getId(), Transaction::ATTR_VALUE => $value]]);
         $respAddOper = $this->_callOperation->add($reqAddOper);
         if ($respAddOper->isSucceed()) {
             $result->markSucceed();
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function test_betweenCustomers()
 {
     /** === Test Data === */
     $custIdFrom = 123;
     $custIdTo = 321;
     $countryFrom = 'lv';
     $countryTo = 'ru';
     $pathTo = '/1/2/5/';
     $dateApplied = '2015-06-23 13:23:34';
     $value = '23.34';
     $accIdFrom = 43;
     $accIdTo = 65;
     $custDebit = new Customer([Customer::ATTR_CUSTOMER_ID => $custIdFrom, Customer::ATTR_COUNTRY_CODE => $countryFrom]);
     $custCredit = new Customer([Customer::ATTR_CUSTOMER_ID => $custIdTo, Customer::ATTR_COUNTRY_CODE => $countryTo, Customer::ATTR_PATH => $pathTo]);
     $accFrom = new Account([Account::ATTR_ID => $accIdFrom]);
     $accTo = new Account([Account::ATTR_ID => $accIdTo]);
     /** === Setup Mocks === */
     // $date = $this->_toolDate->getUtcNowForDb();
     $this->mToolDate->shouldReceive('getUtcNowForDb')->once()->andReturn($dateApplied);
     // $downDebit = $this->_repoMod->getDownlineCustomerById($custIdDebit);
     $this->mRepoMod->shouldReceive('getDownlineCustomerById')->once()->with($custIdFrom)->andReturn($custDebit);
     // $downCredit = $this->_repoMod->getDownlineCustomerById($custIdCredit);
     $this->mRepoMod->shouldReceive('getDownlineCustomerById')->once()->with($custIdTo)->andReturn($custCredit);
     // $respAccDebit = $this->_callAccount->get($reqAccGet);
     $this->mCallAccount->shouldReceive('get')->once()->andReturn($accFrom);
     // $respAccCredit = $this->_callAccount->get($reqAccGet);
     $this->mCallAccount->shouldReceive('get')->once()->andReturn($accTo);
     // $respAddOper = $this->_callOperation->add($reqAddOper);
     $mRespAddOper = new \Praxigento\Accounting\Service\Operation\Response\Add();
     $mRespAddOper->markSucceed();
     $this->mCallOperation->shouldReceive('add')->once()->andReturn($mRespAddOper);
     /** === Call and asserts  === */
     $req = new Request\BetweenCustomers();
     $req->setFromCustomerId($custIdFrom);
     $req->setToCustomerId($custIdTo);
     $req->setValue($value);
     $req->setConditionForceCountry(true);
     $req->setConditionForceDownline(true);
     $resp = $this->obj->betweenCustomers($req);
     $this->assertTrue($resp->isSucceed());
     /* code coverage */
     $req->setConditionForceAll(true);
     $req->setDateApplied(null);
 }
Ejemplo n.º 3
0
 public function test_betweenCustomers()
 {
     $obm = \Magento\Framework\App\ObjectManager::getInstance();
     /** @var  $toolbox \Praxigento\Core\IToolbox */
     $toolbox = $obm->get('Praxigento\\Core\\Lib\\IToolbox');
     $toolDate = $toolbox->getDate();
     $toolFormat = $toolbox->getFormat();
     /** Test data  */
     $dateNow = $toolDate->getUtcNow();
     $formattedNow = $toolFormat->dateTimeForDb($dateNow);
     /** @var  $call Call */
     $call = $obm->get('Praxigento\\Pv\\Service\\Transfer\\Call');
     $req = new Request\BetweenCustomers();
     $req->setData(Request\BetweenCustomers::FROM_CUSTOMER_ID, 1);
     $req->setData(Request\BetweenCustomers::TO_CUSTOMER_ID, 2);
     $req->setData(Request\BetweenCustomers::VALUE, 25.43);
     $req->setData(Request\BetweenCustomers::DATE_APPLIED, $formattedNow);
     /** @var  $resp Response\BetweenCustomers */
     $resp = $call->betweenCustomers($req);
     $this->assertTrue($resp->isSucceed());
 }