Пример #1
0
 /**
  * Add operation's transaction and bind transactions ids to references (orders or customers ids).
  *
  * @param $operId
  * @param $trans
  * @param $datePerformed
  * @param $asRef
  *
  * @return array
  * @throws \Exception
  */
 public function transactions($operId, $trans, $datePerformed, $asRef = null)
 {
     $result = [];
     foreach ($trans as $one) {
         if (!$one instanceof Transaction) {
             $one = new Transaction($one);
         }
         $dateApplied = $one->getDateApplied();
         $dateApplied = $dateApplied ? $dateApplied : $datePerformed;
         $req = new AddTransactionRequest();
         $req->setOperationId($operId);
         $req->setDebitAccId($one->getDebitAccId());
         $req->setCreditAccId($one->getCreditAccId());
         $req->setValue($one->getValue());
         $req->setDateApplied($dateApplied);
         /** @var  $resp AddTransactionResponse */
         $resp = $this->_callTransaction->add($req);
         if (!$resp->isSucceed()) {
             throw new \Exception("Transaction (debit acc. #{$req->getDebitAccId()}, credit acc. " . "#{$req->getCreditAccId()}) cannot be inserted . ");
         }
         $tranId = $resp->getTransactionId();
         $ref = $one->getData($asRef);
         if (!is_null($asRef) && isset($ref)) {
             /* bind new transaction ID to the reference from request */
             $result[$tranId] = $ref;
         } else {
             /* new transaction ID is bound by 'add transaction' requests order */
             $result[] = $resp->getTransactionId();
         }
     }
     return $result;
 }
 public function test_accessors()
 {
     /** === Test Data === */
     $CREDIT_ACC_ID = 'credit_acc_id';
     $DATE_APPLIED = 'date_applied';
     $DEBIT_ACC_ID = 'debit_acc_id';
     $ID = 'id';
     $OPERATION_ID = 'operation_id';
     $VALUE = 'value';
     /** === Call and asserts  === */
     $this->obj->setCreditAccId($CREDIT_ACC_ID);
     $this->obj->setDateApplied($DATE_APPLIED);
     $this->obj->setDebitAccId($DEBIT_ACC_ID);
     $this->obj->setId($ID);
     $this->obj->setOperationId($OPERATION_ID);
     $this->obj->setValue($VALUE);
     $this->assertEquals($CREDIT_ACC_ID, $this->obj->getCreditAccId());
     $this->assertEquals($DATE_APPLIED, $this->obj->getDateApplied());
     $this->assertEquals($DEBIT_ACC_ID, $this->obj->getDebitAccId());
     $this->assertEquals($ID, $this->obj->getId());
     $this->assertEquals($OPERATION_ID, $this->obj->getOperationId());
     $this->assertEquals($VALUE, $this->obj->getValue());
 }