private function _transferToCustomer($custId, $value)
 {
     $req = new RequestTransferCreditToCustomer();
     $req->setConditionForceAll(true);
     $req->setToCustomerId($custId);
     $req->setValue($value);
     $resp = $this->_callTransfer->creditToCustomer($req);
     $this->assertTrue($resp->isSucceed());
 }
 /**
  * Add PV to every customer. PV amount is equal to (350 - 25 * customer #) (in the tree, not Magento ID!).
  *
  * @param $dsBegin string date stamp for first day of the period (YYYYMMDD).
  */
 private function _addPvToCustomers($dsBegin)
 {
     $PV_STEP = 25;
     $PV_MAX = 350;
     $dsToday = $dsBegin;
     $reqAddPv = new PvTransferCreditToCustomerRequest();
     foreach ($this->_mapCustomerMageIdByIndex as $ref => $custId) {
         $pvToAdd = $PV_MAX - $ref * $PV_STEP;
         $ts = $this->_toolPeriod->getTimestampTo($dsToday);
         $reqAddPv->setData(PvTransferCreditToCustomerRequest::TO_CUSTOMER_ID, $custId);
         $reqAddPv->setData(PvTransferCreditToCustomerRequest::VALUE, $pvToAdd);
         $reqAddPv->setData(PvTransferCreditToCustomerRequest::DATE_APPLIED, $ts);
         $respAddPv = $this->_callPvTransfer->creditToCustomer($reqAddPv);
         if ($respAddPv->isSucceed()) {
             $this->_logger->debug("'{$pvToAdd}' PV have been added to customer #{$ref} (mageID: {$custId}).");
         } else {
             $this->_logger->debug("Cannot add '{$pvToAdd}' PV to customer #{$ref} (mageID: {$custId}).");
         }
         $dsToday = $this->_toolPeriod->getPeriodNext($dsToday);
     }
 }
Beispiel #3
0
 public function creditToCustomer(Request\CreditToCustomer $request)
 {
     $result = new Response\CreditToCustomer();
     /* get representative customer account for PV asset */
     $reqRepres = new AccountGetRepresentativeRequest();
     $reqRepres->setAssetTypeCode(Cfg::CODE_TYPE_ASSET_PV);
     $respRepres = $this->_callAccount->getRepresentative($reqRepres);
     /* extract input parameters */
     $requestData = $request->getData();
     $requestData[Request\BetweenCustomers::FROM_CUSTOMER_ID] = $respRepres->getData(Account::ATTR_CUST_ID);
     $requestData[Request\BetweenCustomers::COND_FORCE_ALL] = true;
     $reqBetween = new Request\BetweenCustomers($requestData);
     $respBetween = $this->betweenCustomers($reqBetween);
     if ($respBetween->isSucceed()) {
         $result->setOperationId($respBetween->getOperationId());
         $result->setTransactionsIds($respBetween->getTransactionsIds());
         $result->markSucceed();
     }
     return $result;
 }
 public function test_creditToCustomer()
 {
     /** === Test Data === */
     $custIdFrom = 123;
     $custIdTo = 321;
     $value = '23.34';
     $accFrom = new Account([Account::ATTR_CUST_ID => $custIdFrom]);
     /** === Mock object itself === */
     $this->obj = \Mockery::mock(Call::class . '[betweenCustomers]', $this->objArgs);
     /** === Setup Mocks === */
     // $respRepres = $this->_callAccount->getRepresentative($reqRepres);
     $this->mCallAccount->shouldReceive('getRepresentative')->once()->andReturn($accFrom);
     // $respBetween = $this->betweenCustomers($reqBetween);
     $mRespBetween = new Response\BetweenCustomers();
     $this->obj->shouldReceive('betweenCustomers')->once()->andReturn($mRespBetween);
     // if ($respBetween->isSucceed()) {
     $mRespBetween->markSucceed();
     /** === Call and asserts  === */
     $req = new Request\CreditToCustomer();
     $req->setToCustomerId($custIdTo);
     $req->setValue($value);
     $res = $this->obj->creditToCustomer($req);
     $this->assertTrue($res->isSucceed());
     /* coverage for accessors */
     $req->getToCustomerId();
 }
 private function _createPvBalances()
 {
     $csv = $this->_readCsvFile($path = __DIR__ . '/data/pv_balances.csv');
     $reqAddPv = new PvTransferCreditToCustomerRequest();
     $ts = $this->_toolPeriod->getTimestampTo(self::DS_CUSTOMER_ADDED);
     $reqAddPv->setData(PvTransferCreditToCustomerRequest::DATE_APPLIED, $ts);
     foreach ($csv as $item) {
         $mlmId = $item[0];
         $pv = $this->_formatCsvNum($item[1]);
         $custNdx = $this->_mapCustomerIndexByMlmId[$mlmId];
         if (is_null($custNdx)) {
             $this->_logger->error("Cannot find customer index for MLM ID {$mlmId}.");
         }
         $custId = $this->_mapCustomerMageIdByIndex[$custNdx];
         $reqAddPv->setData(PvTransferCreditToCustomerRequest::TO_CUSTOMER_ID, $custId);
         $reqAddPv->setData(PvTransferCreditToCustomerRequest::VALUE, $pv);
         $respAddPv = $this->_callPvTransfer->creditToCustomer($reqAddPv);
         if ($respAddPv->isSucceed()) {
             $this->_logger->debug("'{$pv}' PV have been added to customer #{$mlmId} (mageID: #{$custId}).");
         } else {
             $this->_logger->debug("Cannot add '{$pv}' PV to customer #{$mlmId} (mageID: #{$custId}).");
         }
     }
 }