/**
  * Process logic by payment Type
  *
  * @throws ProcessorException
  */
 private function doProcessType()
 {
     $type = new Type($this->payment->type, $this->payment->toArray());
     switch ($type->sid()) {
         case Type::CITY:
             break;
         case Type::FEE:
             break;
         case Type::CHECK:
             // todo check 'check' request
             // register check request
             $this->payment->status = Status::ENABLED;
             break;
         case Type::PAY:
             // pay after 'check' request
             $payment = self::findCheck($this->payment->term, $this->payment->city, $this->payment->amount, $this->payment->to, Status::ENABLED);
             if (!$payment) {
                 throw new ProcessorException(ProcessorException::RC_CHECK_NOT_FOUND);
             }
             // close 'check' request
             $payment->status = Status::PAY;
             $payment->saveByType();
             // processed 'payment' request
             $this->payment->status = Status::PROCESSED;
             $this->payment->code = uniqid();
             break;
         case Type::CANCEL:
             // find pay in status 'processed'
             $payment = self::findPayTo($this->payment->term, $this->payment->code, $this->payment->to, Status::PROCESSED);
             if ($payment) {
                 // cancel 'pay' request
                 $payment->status = Status::CANCELED;
                 $payment->saveByType();
                 // save cancel request in 'processed'
                 $this->payment->status = Status::PROCESSED;
                 $this->payment->amount = $payment->amount;
                 $this->payment->name = $payment->name;
                 $this->payment->to = $payment->to;
             } else {
                 throw new ProcessorException(ProcessorException::RC_PAY_NOT_FOUND);
             }
             break;
         case Type::STATUS:
             // status for pay
             $payment = self::findPayTo($this->payment->term, $this->payment->code, $this->payment->to);
             // init data from 'pay' request into current 'status' request
             if ($payment) {
                 $this->payment->id = $payment->id;
                 $this->payment->status = $payment->status;
                 $this->payment->amount = $payment->amount;
                 $this->payment->to = $payment->to;
                 $this->payment->name = $payment->name;
             } else {
                 throw new ProcessorException(ProcessorException::RC_PAY_NOT_FOUND);
             }
             break;
     }
     return '00';
 }
Ejemplo n.º 2
0
 private function initValidator()
 {
     $fields = $this->type->fields();
     $rules = array();
     foreach ($fields as $value) {
         $rules[$value] = self::$rules[$value];
     }
     $this->validator = Validator::make($this->input, $rules);
 }
 /**
  * @param array  $input
  * @param int    $code
  * @param string $message
  *
  * @return void
  *
  * @dataProvider check
  */
 public function testCheck($input, $code = null, $message = null)
 {
     Secure::sign($input, 'check', 'secret');
     $opType = new Type('check', $input);
     try {
         $this->assertTrue($opType->validate());
         if ($code) {
             $this->assertFalse(true, 'Exception must be there with code ' . $code);
         }
     } catch (ProcessorException $e) {
         $this->assertEquals($code, $e->getCode(), $e->getMessage());
         $this->assertContains($message, $e->getMessage());
     }
 }
 /**
  *
  * Check, clear and verify input params
  *
  * @param $action
  * @param $type
  * @param $input
  *
  * @throws ProcessorException
  * @return array
  */
 private function getVerifiedInput($action, $type, $input)
 {
     $input = Type::clearInput($type, $input);
     $baseInput = $input;
     $termId = $input['term'];
     $term = Terminal::find($termId);
     $sign = $input['sign'];
     Secure::sign($input, $type, $term->secret);
     $isCorrect = $sign === $input['sign'];
     if (!$isCorrect) {
         Log::warning($action . 'pull', array('message' => 'Invalid signature', 'sign' => $input['sign'], 'input' => Input::all()));
         throw new ProcessorException(ProcessorException::INVALID_SIGN);
     }
     Log::info($action . 'pull', array('message' => 'Correct signature', 'input' => Input::all()));
     return $baseInput;
 }
 private function getResponseData()
 {
     $data = array('term' => $this->payment->item()->term, 'type' => $this->payment->item()->type, 'code' => $this->payment->item()->code, 'amount' => $this->payment->item()->amount, 'cur' => $this->payment->item()->cur, 'status' => $this->payment->item()->status, 'time' => Time::ts());
     Secure::sign($data, $this->type->sid(), $this->term->secret);
     return $data;
 }