|
@@ -9,6 +9,7 @@ class Payfort extends Core
|
|
private $config = array();
|
|
private $config = array();
|
|
private $language = 'en';
|
|
private $language = 'en';
|
|
private $url = 'https://checkout.payfort.com/FortAPI/paymentPage';
|
|
private $url = 'https://checkout.payfort.com/FortAPI/paymentPage';
|
|
|
|
+ private $gatewayUrl = 'https://paymentservices.payfort.com/FortAPI/paymentApi';
|
|
|
|
|
|
public function __construct($name, $config)
|
|
public function __construct($name, $config)
|
|
{
|
|
{
|
|
@@ -16,7 +17,7 @@ class Payfort extends Core
|
|
$this->config = $config;
|
|
$this->config = $config;
|
|
}
|
|
}
|
|
|
|
|
|
- private function getType($type, $currency)
|
|
|
|
|
|
+ private function getType($type, $currency = '')
|
|
{
|
|
{
|
|
if ($type < 5 && $currency == 'SAR') {
|
|
if ($type < 5 && $currency == 'SAR') {
|
|
$type = 4;
|
|
$type = 4;
|
|
@@ -27,11 +28,14 @@ class Payfort extends Core
|
|
# 目前不支持
|
|
# 目前不支持
|
|
$name = 'Pay with credit cards (Redirection)';
|
|
$name = 'Pay with credit cards (Redirection)';
|
|
$method = 'redirection';
|
|
$method = 'redirection';
|
|
|
|
+ $currency = '';
|
|
|
|
+ $command = 'PURCHASE';
|
|
break;
|
|
break;
|
|
|
|
|
|
case 2:
|
|
case 2:
|
|
$name = 'Pay with installments (Redirection)';
|
|
$name = 'Pay with installments (Redirection)';
|
|
$method = 'redirection';
|
|
$method = 'redirection';
|
|
|
|
+ $currency = '';
|
|
$command = 'PURCHASE';
|
|
$command = 'PURCHASE';
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -39,6 +43,7 @@ class Payfort extends Core
|
|
$name = 'Pay with NAPS';
|
|
$name = 'Pay with NAPS';
|
|
$value = 'NAPS';
|
|
$value = 'NAPS';
|
|
$currency = 'NAPS';
|
|
$currency = 'NAPS';
|
|
|
|
+ $command = 'AUTHORIZATION';
|
|
$method = 'redirection';
|
|
$method = 'redirection';
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -62,6 +67,7 @@ class Payfort extends Core
|
|
$method = 'page';
|
|
$method = 'page';
|
|
$currency = '';
|
|
$currency = '';
|
|
$command = 'TOKENIZATION';
|
|
$command = 'TOKENIZATION';
|
|
|
|
+
|
|
break;
|
|
break;
|
|
|
|
|
|
case 21:
|
|
case 21:
|
|
@@ -94,23 +100,62 @@ class Payfort extends Core
|
|
$data = array();
|
|
$data = array();
|
|
}
|
|
}
|
|
$type = $this->getType($type, $currency);
|
|
$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'];
|
|
$method = $type['method'];
|
|
|
|
|
|
$param = array();
|
|
$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;
|
|
$data += $param;
|
|
|
|
|
|
return $this->result($method, $param, $data);
|
|
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)
|
|
public function notify($param)
|
|
{
|
|
{
|
|
if (empty($param)) {
|
|
if (empty($param)) {
|
|
- Dever::alert('invalid_parameters');
|
|
|
|
|
|
+ return $this->out('invalid_parameters');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $post = $param;
|
|
$responseSignature = $param['signature'];
|
|
$responseSignature = $param['signature'];
|
|
$order_id = $param['merchant_reference'];
|
|
$order_id = $param['merchant_reference'];
|
|
unset($param['l']);
|
|
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'];
|
|
$amount = $param['amount'];
|
|
if (isset($param['card_number']) && $param['card_number']) {
|
|
if (isset($param['card_number']) && $param['card_number']) {
|
|
unset($param['amount']);
|
|
unset($param['amount']);
|
|
@@ -149,44 +213,57 @@ class Payfort extends Core
|
|
$signature = $this->signature($this->config['response_phrase'], $param);
|
|
$signature = $this->signature($this->config['response_phrase'], $param);
|
|
|
|
|
|
if ($signature != $responseSignature) {
|
|
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') {
|
|
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
|
|
* @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)
|
|
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) {
|
|
foreach ($data as $k => $v) {
|
|
$form .= '<input type="hidden" name="' . $k . '" value="' . $v . '">';
|
|
$form .= '<input type="hidden" name="' . $k . '" value="' . $v . '">';
|
|
}
|
|
}
|
|
@@ -210,4 +287,46 @@ class Payfort extends Core
|
|
$signature_string = $phrase . $signature_string . $phrase;
|
|
$signature_string = $phrase . $signature_string . $phrase;
|
|
return hash('sha256', $signature_string);
|
|
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;
|
|
|
|
+ }
|
|
}
|
|
}
|