dever 7 anos atrás
pai
commit
84c752a988

+ 1 - 1
assets/demo.html

@@ -9,7 +9,7 @@
 <body>
  
 <div class="layui-container">
-    <blockquote class="layui-elem-quote">Notice:This is SG Pay Demo.</blockquote>
+    <blockquote class="layui-elem-quote">Notice:<?php echo $msg ?></blockquote>
     <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
         <legend>Demo</legend>
     </fieldset>

+ 2 - 0
assets/demo.php

@@ -1,3 +1,5 @@
 <?php
 
+$status = $_GET['status'];
+$msg = isset($_GET['msg']) && $_GET['msg'] ? '<font style="color:red">' . $_GET['msg'] . '</font>' : 'This is SG Pay Demo.';
 include('demo.html');

+ 10 - 2
assets/sg.js

@@ -51,12 +51,20 @@ var SG =
             ,'name' : 'naps'
             ,'type' : 'redirection'
         }
-        ,'installments' : 
+        /*
+        ,'installments_page' : 
         {
             'id' : 12
-            ,'name' : 'installments'
+            ,'name' : 'installments page'
             ,'type' : 'page'
         }
+        */
+        ,'installments' : 
+        {
+            'id' : 2
+            ,'name' : 'installments'
+            ,'type' : 'redirection'
+        }
     },
     Html : function()
     {

+ 7 - 0
config/lang/en.php

@@ -18,6 +18,13 @@ return array
 	'pay_info' => '支付信息',
 	'order_manage' => '订单管理',
 
+	'company_manage' => '企业管理',
+	'company' => '企业',
+	'appid' => 'appid',
+	'appsecret' => 'appsecret',
+
+	'type' => '支付类型',
+
 	'name' => '名称',
 	'reorder' => '排序',
 	'state' => '状态',

+ 23 - 2
config/lang/zh-cn.php

@@ -2,14 +2,35 @@
 
 return array
 (
-	'pay_wait' => '支付',
+	'pay_wait' => '支付',
 	'pay_yes' => '已支付',
 	'pay_no' => '支付失败',
 
-	'cash_type' => '币种类型',
+	'currency_manage' => '币种管理',
+	'currency' => '币种',
+	'user'	=> '用户',
+	'order'	=> '订单号',
+	'product_name'	=> '产品名',
+	'account'	=> '支付账户',
+	'amount'	=> '金额',
+	'status'	=> '状态',
+	'status_desc'	=> '支付状态说明',
+	'pay_info' => '支付信息',
+	'order_manage' => '订单管理',
+
+	'type' => '支付类型',
 
 	'name' => '名称',
 	'reorder' => '排序',
 	'state' => '状态',
 	'cdate' => '录入时间',
+
+	'no_product_name' => '没有产品信息',
+	'no_amount' => '没有支付金额',
+	'no_currency' => '没有支付币种',
+	'no_refer' => '没有回调url',
+
+	'invalid_order' => 'Invalid Order',
+	'invalid_parameters' => 'Invalid Parameters',
+	'invalid_signature' => 'Invalid signature',
 );

+ 28 - 13
payment/database/currency.php → payment/database/company.php

@@ -4,10 +4,15 @@
 return array
 (
     # 表名
-    'name' => 'currency',
+    'name' => 'company',
     # 显示给用户看的名称
-    'lang' => Dever::lang('currency_manage'),
-    'order' => 1,
+    'lang' => Dever::lang('company_manage'),
+    'order' => -10,
+    'end' => array
+    (
+        'insert' => 'payment/lib/manage.createAppid',
+        //'update' => 'payment/lib/manage.createAppid',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -35,18 +40,28 @@ return array
             'list'      => true,
         ),
 
-        'reorder'       => array
+        'appid'      => array
         (
-            'type'      => 'int-11',
-            'name'      => Dever::lang('reorder'),
-            'default'   => '1',
-            'desc'      => Dever::lang('reorder'),
-            'match'     => 'option',
-            'update'    => 'text',
-            'search'    => 'order',
+            'type'      => 'varchar-60',
+            'name'      => Dever::lang('appid'),
+            'default'   => '',
+            'desc'      => Dever::lang('appid'),
+            'match'     => 'is_string',
+            //'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'appsecret'      => array
+        (
+            'type'      => 'varchar-120',
+            'name'      => Dever::lang('appsecret'),
+            'default'   => '',
+            'desc'      => Dever::lang('appsecret'),
+            'match'     => 'is_string',
+            //'update'    => 'text',
+            'search'    => 'fulltext',
             'list'      => true,
-            'order'     => 'desc',
-            'edit'      => true,
         ),
 
         'state'     => array

+ 24 - 2
payment/database/order.php

@@ -32,13 +32,24 @@ return array
 			//'list'		=> true,
 		),
 
+		'company_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> Dever::lang('company'),
+			'default' 	=> '1',
+			'desc' 		=> Dever::lang('company'),
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
 		'uid'		=> array
 		(
 			'type' 		=> 'varchar-200',
 			'name' 		=> Dever::lang('user'),
 			'default' 	=> '1',
 			'desc' 		=> Dever::lang('user'),
-			'match' 	=> 'is_numeric',
+			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'list'		=> true,
 		),
@@ -49,7 +60,7 @@ return array
 			'name' 		=> Dever::lang('order'),
 			'default' 	=> '',
 			'desc' 		=> Dever::lang('order'),
-			'match' 	=> 'is_numeric',
+			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'list'		=> true,
 		),
@@ -79,6 +90,17 @@ return array
 			'list'		=> true,
 		),
 
+		'type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> Dever::lang('type'),
+			'default' 	=> '',
+			'desc' 		=> Dever::lang('type'),
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'text',
+			//'list'		=> true,
+		),
+
 		'amount'		=> array
 		(
 			'type' 		=> 'varchar-30',

+ 26 - 3
payment/lib/Core.php

@@ -27,10 +27,10 @@ class Core
             $db->update($param);
 
             if (isset($lang)) {
-                Dever::alert($lang);
+                return $this->out($lang);
             }
         } else {
-            Dever::alert('invalid_order');
+            return $this->out('invalid_order');
         }
     }
 
@@ -51,7 +51,7 @@ class Core
     /**
      * create order
      */
-    protected function createOrder($uid, $account, $product_name, $amount, $currency, $type_name)
+    protected function createOrder($uid, $account, $product_name, $amount, $currency, $type_id, $type_name)
     {
         $db = Dever::db('payment/order');
         $order_id = Dever::order($account);
@@ -66,6 +66,7 @@ class Core
             $add['amount'] = $amount;
             $add['currency'] = $currency;
             $add['order_id'] = $order_id;
+            $add['type'] = $type_id;
             $add['id'] = $db->insert($add);
             $msg = '发起支付';
             $this->log($msg, $add);
@@ -94,4 +95,26 @@ class Core
 
         Dever::log($msg, 'pay');
     }
+
+    /**
+     * result
+     *
+     * @return mixed
+     */
+    protected function out($msg)
+    {
+        $result = array();
+        $result['status'] = 2;
+
+        $refer = Dever::session('refer');
+        if ($msg == 'ok') {
+            $result['status'] = 1;
+        }
+        $result['msg'] = Dever::lang($msg);
+        if (!$refer) {
+            Dever::alert($msg);
+        }
+        
+        return $result;
+    }
 }

+ 22 - 0
payment/lib/Manage.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace Payment\Lib;
+
+use Dever;
+
+class Manage
+{
+    public function createAppid($id, $name, $data)
+    {
+    	$appid = Dever::order('sg');
+    	$info = Dever::db('payment/company')->one(array('appid' => $appid));
+    	if ($info) {
+    		return $this->createAppid($id, $name, $data);
+    	}
+    	$appsecret = sha1(Dever::uuid());
+    	$update['where_id'] = $id;
+    	$update['appid'] = $appid;
+    	$update['appsecret'] = $appsecret;
+        Dever::db('payment/company')->update($update);
+    }
+}

+ 152 - 33
payment/lib/Payfort.php

@@ -9,6 +9,7 @@ class Payfort extends Core
     private $config = array();
     private $language = 'en';
     private $url = 'https://checkout.payfort.com/FortAPI/paymentPage';
+    private $gatewayUrl = 'https://paymentservices.payfort.com/FortAPI/paymentApi';
 
     public function __construct($name, $config)
     {
@@ -16,7 +17,7 @@ class Payfort extends Core
         $this->config = $config;
     }
 
-    private function getType($type, $currency)
+    private function getType($type, $currency = '')
     {
         if ($type < 5 && $currency == 'SAR') {
             $type = 4;
@@ -27,11 +28,14 @@ class Payfort extends Core
                 # 目前不支持
                 $name = 'Pay with credit cards (Redirection)';
                 $method = 'redirection';
+                $currency = '';
+                $command = 'PURCHASE';
                 break;
 
             case 2:
                 $name = 'Pay with installments (Redirection)';
                 $method = 'redirection';
+                $currency = '';
                 $command = 'PURCHASE';
                 break;
 
@@ -39,6 +43,7 @@ class Payfort extends Core
                 $name = 'Pay with NAPS';
                 $value = 'NAPS';
                 $currency = 'NAPS';
+                $command = 'AUTHORIZATION';
                 $method = 'redirection';
                 break;
 
@@ -62,6 +67,7 @@ class Payfort extends Core
                 $method = 'page';
                 $currency = '';
                 $command = 'TOKENIZATION';
+
                 break;
 
             case 21:
@@ -94,23 +100,62 @@ class Payfort extends Core
             $data = array();
         }
         $type = $this->getType($type, $currency);
-        $order_id = $this->createOrder($uid, $this->name, $product_name, $amount, $type['currency'], $type['name']);
+        $order_id = $this->createOrder($uid, $this->name, $product_name, $amount, $type['currency'], $type['id'], $type['name']);
 
         $method = $type['method'];
 
         $param = array();
-        if ($type['currency']) {
-            $param['amount'] = $amount;
-            $param['currency'] = $type['currency'];
+        if ($type['id'] == 3) {
+            $param['order_description'] = $product_name;
         }
-
-        $param = $this->param($order_id, $type['command'], $type['value'], $param);
+        $param = $this->param($order_id, $amount, $type['currency'], $type['command'], $type['value'], $type['id'], $param);
 
         $data += $param;
 
         return $this->result($method, $param, $data);
     }
 
+    /**
+     * 生成基本参数
+     *
+     * @return mixed
+     */
+    private function param($order_id, $amount, $currency, $command, $payment_option, $type, $param = array())
+    {
+        if ($type == 2 || $type == 12) {
+            $param['installments'] = 'STANDALONE';
+        }
+
+        if ($type == 12 && isset($param['plan_code'])) {
+            $param['installments']   = 'YES';
+            $command                 = 'PURCHASE';
+        }
+
+        if ($currency) {
+            $param['amount'] = $this->convertFortAmount($amount, $currency);
+            $param['currency'] = $currency;
+        }
+
+        $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;
+    }
+
     /**
      * 获取返回数据
      *
@@ -130,17 +175,36 @@ class Payfort extends Core
     public function notify($param)
     {
         if (empty($param)) {
-            Dever::alert('invalid_parameters');
+            return $this->out('invalid_parameters');
         }
 
+        $post                   = $param;
         $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']);
+        if (isset($param['3ds'])) {
+            unset($param['3ds']);
+        }
+        if (isset($param['product_name'])) {
+            unset($param['product_name']);
+        }
+        if (isset($param['integration_type'])) {
+            unset($param['integration_type']);
+        }
+        if (isset($param['signature'])) {
+            unset($param['signature']);
+        }
+        if (isset($param['order_id'])) {
+            unset($param['order_id']);
+        }
+        if (isset($param['type'])) {
+            unset($param['type']);
+        }
 
+        if (isset($param['currency']) && $param['currency']) {
+            $param['amount'] = $this->convertFortAmount($param['amount'], $param['currency']);
+        }
+        
         $amount = $param['amount'];
         if (isset($param['card_number']) && $param['card_number']) {
             unset($param['amount']);
@@ -149,44 +213,57 @@ class Payfort extends Core
         $signature = $this->signature($this->config['response_phrase'], $param);
 
         if ($signature != $responseSignature) {
-            $this->updateOrder($param['merchant_reference'], $amount, 'invalid_signature');
+            return $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 $this->updateOrder($param['merchant_reference'], $amount, $param['response_message']);
+        }
+
+        if (isset($param['card_number']) && $param['card_number']) {
+            return $this->pageNotify($post);
         }
 
-        return true;
+        return $this->out('ok');
     }
 
     /**
-     * 生成基本参数
+     * merchantPageNotifyFort
      *
      * @return mixed
      */
-    private function param($order_id, $command, $payment_option, $param = array())
+    private function pageNotify($param)
     {
-        $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;
+        $type = $this->getType($param['type']);
+        $method = $type['method'];
+        $post = array();
+
+        $post['customer_ip'] = $_SERVER['REMOTE_ADDR'];
+        if (isset($param['token_name'])) {
+            $post['token_name'] = $param['token_name'];
         }
-        # AUTHORIZATION(授权)、PURCHASE(购买) TOKENIZATION CHECK_STATUS
-        if ($command == 'TOKENIZATION') {
-            $param['service_command'] = $command;
-        } else {
-            $param['command'] = $command;
+
+        if(isset($param['3ds']) && $param['3ds'] == 'no') {
+            $post['check_3ds'] = 'NO';
         }
-        
-        $param['return_url'] = Dever::url('api.notify?order_id=' . $order_id, 'payment');
-        $param['signature'] = $this->signature($this->config['request_phrase'], $param);
-        return $param;
+
+        if (!$type['currency']) {
+            $type['currency'] = 'USD';
+        }
+
+        $type['command'] = 'AUTHORIZATION';
+
+        $post = $this->param($param['order_id'], $param['amount'], $type['currency'], $type['command'], $type['value'], $type['id'], $post);
+        print_r($post);die;
+
+        $result = Dever::curl($this->gatewayUrl, $post, 'post');
+
+        return $this->notify($result);
     }
 
     public function form($data)
     {
-        $form = '<form style="display:none" name="sg-form" id="sg-form" method="post" action="' . $this->url . '" targets="f1"><iframe style="display:none;" id="f1" name="f1"></iframe><input type="hidden" name="function" id="function" value="SG.notify"/>';
+        $form = '<form style="display:none" name="sg-form" id="sg-form" method="post" action="' . $this->url . '">';
         foreach ($data as $k => $v) {
             $form .= '<input type="hidden" name="' . $k . '" value="' . $v . '">';
         }
@@ -210,4 +287,46 @@ class Payfort extends Core
         $signature_string = $phrase . $signature_string . $phrase;
         return hash('sha256', $signature_string);
     }
+
+    /**
+     * Convert Amount with dicemal points
+     * @param decimal $amount
+     * @param string  $currencyCode
+     * @return decimal
+     */
+    private function convertFortAmount($amount, $currencyCode)
+    {
+        $new_amount = 0;
+        $total = $amount;
+        $decimalPoints    = $this->getCurrencyDecimalPoints($currencyCode);
+        $new_amount = round($total, $decimalPoints) * (pow(10, $decimalPoints));
+        return $new_amount;
+    }
+
+    private  function castAmountFromFort($amount, $currencyCode)
+    {
+        $decimalPoints    = $this->getCurrencyDecimalPoints($currencyCode);
+        //return $amount / (pow(10, $decimalPoints));
+        $new_amount = round($amount, $decimalPoints) / (pow(10, $decimalPoints));
+        return $new_amount;
+    }
+
+    private function getCurrencyDecimalPoints($currency)
+    {
+        $decimalPoint  = 2;
+        $arrCurrencies = array(
+            'JOD' => 3,
+            'KWD' => 3,
+            'OMR' => 3,
+            'TND' => 3,
+            'BHD' => 3,
+            'LYD' => 3,
+            'IQD' => 3,
+            'USD' => 0,
+        );
+        if (isset($arrCurrencies[$currency])) {
+            $decimalPoint = $arrCurrencies[$currency];
+        }
+        return $decimalPoint;
+    }
 }

+ 309 - 0
payment/sdk/payfort/trace.log

@@ -6643,3 +6643,312 @@ Array
 )
 
 
+========================================================
+
+Fort Redirect Request Parameters 
+Array
+(
+    [amount] => 10000
+    [currency] => SAR
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 1014180333
+    [customer_email] => test@payfort.com
+    [command] => AUTHORIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=processResponse
+    [payment_option] => SADAD
+    [signature] => 9db16cb345c470b1471ca18151395556b7a2348c1de042120afd7d4dc8025921
+)
+
+
+========================================================
+
+Fort Redirect Response Parameters 
+Array
+(
+    [r] => processResponse
+    [amount] => 10000
+    [response_code] => 00014
+    [signature] => 2e60dec5f0dfb29f44eb9faf4b51def0c8b2a5c080d5df96d92d34d23205242d
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [payment_option] => SADAD
+    [language] => en
+    [command] => AUTHORIZATION
+    [response_message] => Inactive payment option
+    [merchant_reference] => 1014180333
+    [customer_email] => test@payfort.com
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=processResponse
+    [currency] => SAR
+    [status] => 00
+)
+
+
+========================================================
+
+Invalid Signature. Calculated Signature: 2e60dec5f0dfb29f44eb9faf4b51def0c8b2a5c080d5df96d92d34d23205242d, Response Signature: cf60631a62964975b874b6f241ea3826b866ebec70179b65a3a5e94277433158
+
+========================================================
+
+Fort Redirect Request Parameters 
+Array
+(
+    [amount] => 100
+    [currency] => SAR
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => PA1535018290311546078
+    [command] => AUTHORIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/?l=api.notify&order_id=PA1535018290311546078
+    [payment_option] => SADAD
+    [signature] => 40a0a94ed2f1854744e1ca8eb69b9de6a8c85992c9520973d4ab77c2afbf5cdb
+)
+
+
+========================================================
+
+Fort Merchant Page Request Parameters 
+Array
+(
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 1713954395
+    [service_command] => TOKENIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [installments] => STANDALONE
+    [amount] => 10000
+    [signature] => 181657be9f86ebf581217f06a9dd18cea8c87a409ba2e78666b7e3db582b063c
+)
+
+
+========================================================
+
+Fort Merchant Page Request Parameters 
+Array
+(
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 1680399775
+    [service_command] => TOKENIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [installments] => STANDALONE
+    [amount] => 10000
+    [signature] => fb28aebaadca657028d6ef13912b97fc80e38237d00982cccaaf6bba09ffccd3
+)
+
+
+========================================================
+
+Fort Merchant Page Request Parameters 
+Array
+(
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 1727272658
+    [service_command] => TOKENIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [installments] => STANDALONE
+    [amount] => 10000
+    [signature] => 1a6a26944939ee8b0e725cdfbcdfb5a03676fcd27b04398e0010428a562a9c78
+)
+
+
+========================================================
+
+Fort Merchant Page Response Parameters 
+Array
+(
+    [r] => merchantPageReturn
+    [amount] => 10000
+    [response_code] => 00093
+    [service_command] => TOKENIZATION
+    [response_message] => service inactive
+    [signature] => c433bae2b308c0d5082e490030f8dc72ab0ad46a4b366dffc2e624cac91c2522
+    [merchant_identifier] => qRVCYhzy
+    [merchant_reference] => 1727272658
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [language] => en
+    [status] => 00
+)
+
+
+========================================================
+
+Invalid Signature. Calculated Signature: c433bae2b308c0d5082e490030f8dc72ab0ad46a4b366dffc2e624cac91c2522, Response Signature: 80b39f365b27b8a28007f892f6676fb37e61a54788f0d5eb22e8aec93b877d68
+
+========================================================
+
+Fort Merchant Page Request Parameters 
+Array
+(
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 1547207743
+    [service_command] => TOKENIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [installments] => STANDALONE
+    [amount] => 10000
+    [signature] => 25b465ccb06135b5104a116754ff1580e7afe477ce0a367f5ac662ec5c7d57e8
+)
+
+
+========================================================
+
+Fort Merchant Page Response Parameters 
+Array
+(
+    [r] => merchantPageReturn
+    [amount] => 10000
+    [response_code] => 00093
+    [service_command] => TOKENIZATION
+    [response_message] => service inactive
+    [signature] => 3853f785c8457f603b591cb6429c96d28e5ce050e34d2421ebba2fa0c28ac106
+    [merchant_identifier] => qRVCYhzy
+    [merchant_reference] => 1547207743
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [language] => en
+    [status] => 00
+)
+
+
+========================================================
+
+Invalid Signature. Calculated Signature: 3853f785c8457f603b591cb6429c96d28e5ce050e34d2421ebba2fa0c28ac106, Response Signature: 3556f9f81301003a646b2374902fbe67949d528353201c5e93517049416abb1f
+
+========================================================
+
+Fort Merchant Page Request Parameters 
+Array
+(
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 789629213
+    [service_command] => TOKENIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [installments] => STANDALONE
+    [amount] => 10000
+    [signature] => fb59d4e73fa1d44246df41d85c8598d55b3b1b7aec1938360ed7b1469843825a
+)
+
+
+========================================================
+
+Fort Merchant Page Response Parameters 
+Array
+(
+    [r] => merchantPageReturn
+    [amount] => 10000
+    [response_code] => 00093
+    [service_command] => TOKENIZATION
+    [response_message] => service inactive
+    [signature] => 627a881dea00ba2e0d9dab4c10211332b2008b52787bf2f7bfe18dacb5775e1e
+    [merchant_identifier] => qRVCYhzy
+    [merchant_reference] => 789629213
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [language] => en
+    [status] => 00
+)
+
+
+========================================================
+
+Invalid Signature. Calculated Signature: 627a881dea00ba2e0d9dab4c10211332b2008b52787bf2f7bfe18dacb5775e1e, Response Signature: f0a8f25b2c4d763e2b7b8a8cf26453ae6c0022cfbec781ffc18cf809cb49325a
+
+========================================================
+
+Fort Merchant Page Request Parameters 
+Array
+(
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 2117935981
+    [service_command] => TOKENIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [installments] => STANDALONE
+    [amount] => 10000
+    [signature] => c45233962330e7a2ec0bddf8030e2c202d8ffabac031f8720593e579e1ec8085
+)
+
+
+========================================================
+
+Fort Merchant Page Response Parameters 
+Array
+(
+    [r] => merchantPageReturn
+    [amount] => 10000
+    [response_code] => 00093
+    [service_command] => TOKENIZATION
+    [response_message] => service inactive
+    [signature] => 0ae0103462f24062722a34c5a370973c18c40a0102cefc97e1c3e516068d4c14
+    [merchant_identifier] => qRVCYhzy
+    [merchant_reference] => 2117935981
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [language] => en
+    [status] => 00
+)
+
+
+========================================================
+
+Invalid Signature. Calculated Signature: 0ae0103462f24062722a34c5a370973c18c40a0102cefc97e1c3e516068d4c14, Response Signature: 30430cad46cfde7ff7e7030e62de6c6266873f1336924bd95bfc86a6b7474617
+
+========================================================
+
+Fort Merchant Page Request Parameters 
+Array
+(
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 187502879
+    [service_command] => TOKENIZATION
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=merchantPageReturn
+    [currency] => USD
+    [installments] => STANDALONE
+    [amount] => 10000
+    [signature] => 2c76731b8aa32bef28a4b2d7c590b6c0c46033596e6e3fc2665d16ef4fa3505d
+)
+
+
+========================================================
+
+Fort Redirect Request Parameters 
+Array
+(
+    [amount] => 10000
+    [currency] => USD
+    [merchant_identifier] => qRVCYhzy
+    [access_code] => IvPf2BwOqHwvZ6PrE8xU
+    [merchant_reference] => 1157826295
+    [customer_email] => test@payfort.com
+    [command] => PURCHASE
+    [language] => en
+    [return_url] => http://192.168.33.10/sg/payment/sdk/payfort/route.php?r=processResponse
+    [installments] => STANDALONE
+    [signature] => 412010e8d47d225ad482cecf8e12544c5666d970a20207847c316ccea922cd82
+)
+
+

+ 9 - 44
payment/src/Api.php

@@ -33,48 +33,23 @@ class Api
         $this->init($param);
         if ($this->pay) {
             $param['amount'] = $this->pay['amount'];
+            $param['type'] = $this->pay['type'];
         }
         $result = $this->method->notify($param);
 
         $refer = Dever::session('refer');
         if ($refer) {
+            if (strpos($refer, '?')) {
+                $refer .= '&';
+            } else {
+                $refer .= '?';
+            }
+            $refer .= http_build_query($result);
+            
             Dever::location($refer);
         }
     }
 
-    /**
-     * 发起支付 直接付款
-     *
-     * @return mixed
-     */
-    public function redirection()
-    {
-        $type = Dever::input('type', 4);
-        return $this->get($type);
-    }
-
-    /**
-     * 发起支付 当前页面付款 信用卡
-     *
-     * @return mixed
-     */
-    public function page()
-    {
-        $type = Dever::input('type', 21);
-        return $this->get($type);
-    }
-
-    /**
-     * 发起支付 跳转到对方页面付款 信用卡
-     *
-     * @return mixed
-     */
-    public function page_v1()
-    {
-        $type = Dever::input('type', 11);
-        return $this->get($type);
-    }
-
     /**
      * 初始化 设置参数
      *
@@ -119,15 +94,7 @@ class Api
             //Dever::alert('no_currency');
         }
 
-        $refer = Dever::session('refer');
-
-        if ($refer) {
-            $this->refer = $refer;
-        }
-
-        if (!$this->refer) {
-            Dever::alert('no_refer');
-        }
+        Dever::session('refer', $this->refer);
 
         $this->uid = Dever::session('uid');
 
@@ -140,8 +107,6 @@ class Api
         }
 
         Dever::setInput('json', 1);
-        
-        Dever::session('refer', $this->refer);
 
         return $this->pay();
     }