<?php
namespace Cmbc\Api;

class Notify extends Core
{
	protected function init()
	{
		$this->api = 'https://ipaynow.acquire.cmbchina.com/';
	}

	public function request($request, $tool = false)
	{
		$this->data = $request;
		$this->setParam('mhtOrderNo');
		$this->setParam('mhtOrderName');
		$this->setParam('mhtOrderType');
		$this->setParam('mhtCurrencyType');
		$this->setParam('mhtOrderAmt');
		$this->setParam('oriMhtOrderAmt');
		$this->setParam('discountAmt');
		$this->setParam('mhtOrderDetail');
		$this->setParam('mhtOrderTimeOut');
		$this->setParam('mhtOrderStartTime');
		$this->setParam('payTime');
		$this->setParam('nowPayOrderNo');
		$this->setParam('transStatus');
		$this->setParam('mhtCharset');
		$this->setParam('deviceType');
		$this->setParam('payChannelType');
		$this->setParam('channelOrderNo');
		$this->setParam('payConsumerId');
		$this->setParam('mhtReserved');
		$this->setParam('bankType');
		$this->setParam('cardType');
		$this->setParam('signType');
		$this->setParam('funcode');
		$this->setParam('version');
		$error = $this->getError();
		if ($error) {
			$tool->updateOrder($this->param['mhtOrderNo'], $this->param['mhtOrderAmt'], $error);
			return false;
		}

		unset($this->param['mhtSubAppId']);
		$signature = $this->createSignature($this->param['signType']);
		if ($signature != $this->data['signature']) {
			$tool->updateOrder($this->param['mhtOrderNo'], $this->param['mhtOrderAmt'], '签名错误');
			return false;
		}
		return $this->param;
	}

	public function response($response)
	{
		return $response;
	}
}