name = $name; $this->config = $config; } private function getType($type, $currency) { if ($type < 5 && $currency == 'SAR') { $type = 4; } $name = $value = $method = $command = ''; switch ($type) { case 1: # 目前不支持 $name = 'Pay with credit cards (Redirection)'; $method = 'redirection'; break; case 2: $name = 'Pay with installments (Redirection)'; $method = 'redirection'; $command = 'PURCHASE'; break; case 3: $name = 'Pay with NAPS'; $value = 'NAPS'; $currency = 'NAPS'; $method = 'redirection'; break; case 4: $name = 'Pay with SADAD'; $value = 'SADAD'; $currency = 'SAR'; $method = 'redirection'; $command = 'AUTHORIZATION'; break; case 11: $name = 'Pay with credit cards (Merchant Page)'; $method = 'page'; $currency = ''; $command = 'TOKENIZATION'; break; case 12: $name = 'Pay with installments (Merchant Page)'; $method = 'page'; $currency = ''; $command = 'TOKENIZATION'; break; case 21: $name = 'Pay with credit cards (Merchant Page 2.0)'; $method = 'page_v2'; $currency = ''; $command = 'TOKENIZATION'; break; } $currency = strtoupper($currency); return array ( 'id' => $type, 'name' => $name, 'value' => $value, 'method' => $method, 'currency' => $currency, 'command' => $command, ); } /** * 获取统一下单的基本信息 */ public function request($type, $uid, $account, $product_name, $amount, $currency, $data = array()) { if (!$data) { $data = array(); } $type = $this->getType($type, $currency); $order_id = $this->createOrder($uid, $this->name, $product_name, $amount, $type['currency'], $type['name']); $method = $type['method']; $param = array(); if ($type['currency']) { $param['amount'] = $amount; $param['currency'] = $type['currency']; } $param = $this->param($order_id, $type['command'], $type['value'], $param); $data += $param; return $this->result($method, $param, $data); } /** * 获取返回数据 * * @return mixed */ private function result($method, $param, $data) { $form = $this->form($param); return array('form' => $form, 'url' => $this->url, 'param' => $data, 'method' => $method); } /** * 通知回调 * * @return mixed */ public function notify($param) { if (empty($param)) { Dever::alert('invalid_parameters'); } $responseSignature = $param['signature']; $order_id = $param['merchant_reference']; unset($param['l']); unset($param['signature']); unset($param['integration_type']); unset($param['product_name']); unset($param['order_id']); $amount = $param['amount']; if (isset($param['card_number']) && $param['card_number']) { unset($param['amount']); } $signature = $this->signature($this->config['response_phrase'], $param); if ($signature != $responseSignature) { $this->updateOrder($param['merchant_reference'], $amount, 'invalid_signature'); } if (substr($param['response_code'], 2) != '000') { $this->updateOrder($param['merchant_reference'], $amount, $param['response_message']); } return true; } /** * 生成基本参数 * * @return mixed */ private function param($order_id, $command, $payment_option, $param = array()) { $param['access_code'] = $this->config['access_code']; $param['merchant_identifier'] = $this->config['merchant_id']; $param['merchant_reference'] = $order_id; $param['language'] = $this->language; if ($payment_option) { $param['payment_option'] = $payment_option; } # AUTHORIZATION(授权)、PURCHASE(购买) TOKENIZATION CHECK_STATUS if ($command == 'TOKENIZATION') { $param['service_command'] = $command; } else { $param['command'] = $command; } $param['return_url'] = Dever::url('api.notify?order_id=' . $order_id, 'payment'); $param['signature'] = $this->signature($this->config['request_phrase'], $param); return $param; } public function form($data) { $form = '