public function testCheck() { $input = $this->doPrepareCheckInput(); // check $processor = $this->makeProcessor($input, 'check'); $processor->response(); $paymentCheck = $processor->item(); $this->assertEquals(Status::ENABLED, $paymentCheck->status); $this->assertEmpty($paymentCheck->code); // pay $processor = $this->makeProcessor($input, 'pay'); $processor->response(); $paymentPay = $processor->item(); $this->assertNotEmpty($paymentPay->code); // 'check' changed to 'pay' $paymentCheck = Payment::find($paymentCheck->id); $this->assertEquals(Status::PAY, $paymentCheck->status); // status $input = array('term' => $paymentPay->term, 'code' => $paymentPay->code, 'to' => $paymentPay->to, 'time' => Time::ts()); Secure::sign($input, 'status', 'secret'); $processor = $this->makeProcessor($input, 'status'); $processor->response(); $paymentStatus = $processor->item(); // 'status' == data from 'pay' $this->assertEquals($paymentPay->id, $paymentStatus->id); $this->assertEquals(Status::PROCESSED, $paymentStatus->status); // cancel $processor = $this->makeProcessor($input, 'cancel'); $response = $processor->response(); $this->assertEmpty($response->error()); }
public function setUp() { parent::setUp(); Terminal::truncate(); Payment::truncate(); $this->term = new Terminal(); $this->term->id = 123; $this->term->secret = 'secret'; $this->term->save(); $this->makeCity(); $this->makeFee(); }
/** * search payment * * @param string $term * @param integer $city * @param float $amount * @param string $to * @param string|array $status * * @return PaymentModel|null */ public static function findCheck($term, $city, $amount, $to, $status = null) { $payment = self::$paymentStatic->newInstance()->whereTerm($term)->whereCity($city)->whereAmount($amount)->whereTo($to)->whereType(Type::CHECK); if (!is_array($status)) { $status = (array) $status; } if ($status) { $payment->whereIn('status', $status); } $payment->orderBy('id', 'desc'); $payment = $payment->first(); return $payment; }
/** * Approve one payment */ public function approve() { $id = Input::get('id'); $terminal = Terminal::whereUserId($this->userId())->first(); $payment = Payment::find($id); if ($payment->term == $terminal->id) { $status = $payment->getPossibleStatus(); if ($status) { $payment->status = $status; $payment->save(); if ($payment->getPossibleStatus()) { return array('next' => true, 'value' => 'Move to [' . $payment->getPossibleStatus() . ']', 'status' => $payment->status); } } } return array('next' => false, 'status' => $payment ? $payment->status : null); }