yoone-wc-moneris-payments/includes/constants/moneris.php

80 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
if (! defined('ABSPATH')) {
exit;
}
/**
* Yoone Moneris 常量与端点默认值
* 参考 moneryze 项目结构,集中管理常量与默认配置。
*/
// 默认配置常量
define('YOONE_MONERIS_DEFAULT_CRYPT_TYPE', '7');
define('YOONE_MONERIS_DEFAULT_TIMEOUT', 30);
define('YOONE_MONERIS_DEFAULT_HTTP_METHOD', 'POST');
define('YOONE_MONERIS_DEFAULT_PROTOCOL', 'https');
define('YOONE_MONERIS_DEFAULT_PORT', 443);
define('YOONE_MONERIS_MPI_PATH', '/mpi/servlet/MpiServlet');
// 端点映射(按国家与环境)
$GLOBALS['YOONE_MONERIS_ENDPOINTS'] = array(
'CA' => array(
'sandbox' => array(
'host' => 'esqa.moneris.com',
'path' => '/gateway2/servlet/MpgRequest',
'protocol' => YOONE_MONERIS_DEFAULT_PROTOCOL,
'port' => YOONE_MONERIS_DEFAULT_PORT,
),
'production' => array(
'host' => 'www3.moneris.com',
'path' => '/gateway2/servlet/MpgRequest',
'protocol' => YOONE_MONERIS_DEFAULT_PROTOCOL,
'port' => YOONE_MONERIS_DEFAULT_PORT,
),
),
'US' => array(
'sandbox' => array(
'host' => 'esplusqa.moneris.com',
'path' => '/gateway_us/servlet/MpgRequest',
'protocol' => YOONE_MONERIS_DEFAULT_PROTOCOL,
'port' => YOONE_MONERIS_DEFAULT_PORT,
),
'production' => array(
// 注意US 生产主机需根据商户环境确认,建议在设置中显式覆盖;此处仅提供路径与端口默认值。
'host' => '',
'path' => '/gateway_us/servlet/MpgRequest',
'protocol' => YOONE_MONERIS_DEFAULT_PROTOCOL,
'port' => YOONE_MONERIS_DEFAULT_PORT,
),
),
);
/**
* 判断是否启用沙箱(环境值统一为 'yes'/'no')。
*
* @param string $sandboxOption 'yes' 或 'no'
* @return bool
*/
function yoone_moneris_is_sandbox($sandboxOption)
{
return strtolower((string) $sandboxOption) === 'yes';
}
/**
* 获取端点默认配置(主机/路径/端口/协议)。
*
* @param string $countryCode 'CA' 或 'US'
* @param bool $isSandbox 是否沙箱
* @return array{host:string,path:string,protocol:string,port:int}
*/
function yoone_moneris_endpoint_defaults($countryCode, $isSandbox)
{
$cc = strtoupper((string) $countryCode);
$env = $isSandbox ? 'sandbox' : 'production';
$map = $GLOBALS['YOONE_MONERIS_ENDPOINTS'];
if (isset($map[$cc][$env])) {
return $map[$cc][$env];
}
// 回退 CA 生产
return $map['CA']['production'];
}