コード例 #1
0
 protected function _populateCustomerData()
 {
     $result[self::CFG_CUST_BALANCE] = 0;
     if ($this->sessionCustomer) {
         $customerId = $this->sessionCustomer->getCustomerId();
         $assetTypeId = $this->repoAssetType->getIdByCode(\Praxigento\Wallet\Config::CODE_TYPE_ASSET_WALLET_ACTIVE);
         $account = $this->repoAccount->getByCustomerId($customerId, $assetTypeId);
         if ($account) {
             $balance = $account->getBalance();
             $result[self::CFG_CUST_BALANCE] = $balance;
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * Get account data or create new account if customer has no account for the requested asset.
  *
  * @param Request\Get $request
  *
  * @return Response\Get
  */
 public function get(Request\Get $request)
 {
     $result = new Response\Get();
     $this->_logger->info("'Get account' operation is called.");
     $accountId = $request->getAccountId();
     $customerId = $request->getCustomerId();
     $assetTypeId = $request->getAssetTypeId();
     $assetTypeCode = $request->getAssetTypeCode();
     $createNewAccIfMissed = $request->getCreateNewAccountIfMissed();
     /* accountId has the highest priority */
     if ($accountId) {
         $data = $this->_repoAccount->getById($accountId);
     } else {
         /* try to look up by customer id & asset type id */
         if (!$assetTypeId) {
             /* get asset type ID by asset code */
             $assetTypeId = $this->_repoTypeAsset->getIdByCode($assetTypeCode);
         }
         /* get account by customerId & assetTypeId */
         $data = $this->_repoAccount->getByCustomerId($customerId, $assetTypeId);
     }
     /* analyze found data */
     if ($data) {
         $result->setData($data);
         $result->markSucceed();
     } else {
         if ($createNewAccIfMissed) {
             /* not found - add new account */
             $data = [Account::ATTR_CUST_ID => $customerId, Account::ATTR_ASSET_TYPE_ID => $assetTypeId, Account::ATTR_BALANCE => 0];
             $accId = $this->_repoAccount->create($data);
             $data[Account::ATTR_ID] = $accId;
             $result->setData($data);
             $result->markSucceed();
             $this->_logger->info("There is no account for customer #{$customerId} and asset type #{$assetTypeId}. New account #{$accId} is created.");
         }
     }
     $this->_logger->info("'Get account' operation is completed.");
     return $result;
 }
コード例 #3
0
 public function getRepresentativeAccountId($assetTypeId)
 {
     /* TODO: add cache for accounts ids */
     $result = null;
     $custId = $this->getRepresentativeCustomerId();
     if ($custId) {
         $found = $this->_repoAccount->getByCustomerId($custId, $assetTypeId);
         if ($found) {
             $result = $found->getId();
         }
     }
     return $result;
 }