diff --git a/includes/class-yoone-moneris-api.php b/includes/class-yoone-moneris-api.php index 3722bab..54b2c01 100644 --- a/includes/class-yoone-moneris-api.php +++ b/includes/class-yoone-moneris-api.php @@ -91,7 +91,8 @@ class Yoone_Moneris_API implements Yoone_Moneris_API_Interface { $num = isset($card['number']) ? preg_replace('/\D+/', '', (string) $card['number']) : ''; $masked = $num ? str_repeat('*', max(strlen($num) - 4, 0)) . substr($num, -4) : ''; error_log('【Yoone Moneris API】tokenize_card 请求:last4=' . ($num ? substr($num, -4) : '') . ' len=' . strlen($num) . ' expdate=' . $payload['expdate'] . ' cryptType=' . $payload['cryptType']); - $res = $this->send_moneris_xml( 'res_add_cc', $payload ); + // 使用集中加载的交易类型常量接口 + $res = $this->send_moneris_xml( Yoone_Moneris_Txn_Types::RES_ADD_CC, $payload ); error_log('$res11111111'. print_r($res, true)); if ( $res['ok'] ) { return array( @@ -126,7 +127,8 @@ class Yoone_Moneris_API implements Yoone_Moneris_API_Interface { require_once __DIR__ . '/utils/orderid.php'; } $unique_order_id = yoone_moneris_unique_order_id( $order_id ); - $type = $capture ? 'res_purchase_cc' : 'res_preauth_cc'; + // 使用集中加载的交易类型常量接口 + $type = $capture ? Yoone_Moneris_Txn_Types::RES_PURCHASE_CC : Yoone_Moneris_Txn_Types::RES_PREAUTH_CC; $payload = array( 'dataKey' => (string) $token, 'orderId' => (string) $unique_order_id, @@ -185,7 +187,8 @@ class Yoone_Moneris_API implements Yoone_Moneris_API_Interface { 'amount' => $this->format_amount( $amount ), 'cryptType' => $this->crypt_type, ); - $res = $this->send_moneris_xml( 'refund', $payload ); + // 使用集中加载的交易类型常量接口 + $res = $this->send_moneris_xml( Yoone_Moneris_Txn_Types::REFUND, $payload ); if ( $res['ok'] ) { return array( 'success' => true ); } @@ -214,9 +217,14 @@ class Yoone_Moneris_API implements Yoone_Moneris_API_Interface { // 构建请求体 $body = array( - 'storeId' => $this->store_id, - 'apiToken' => $this->api_token, - 'statusCheck'=> (bool) $this->status_check, + 'storeId' => $this->store_id, + 'apiToken' => $this->api_token, + // 明确发送字符串 true/false,避免 boolean false 被序列化为空字符串 + 'statusCheck' => $this->status_check ? 'true' : 'false', + // 添加处理国家代码(CA/US),与端点匹配 + 'processingCountryCode' => strtoupper($this->country_code), + // 在沙箱环境显式声明 test=true(与官方示例一致) + 'test' => $this->is_test_mode() ? 'true' : 'false', ); // 风险查询特殊结构(暂不支持;如需支持可扩展) diff --git a/includes/interfaces/class-yoone-moneris-txn-types.php b/includes/interfaces/class-yoone-moneris-txn-types.php new file mode 100644 index 0000000..63bfcaa --- /dev/null +++ b/includes/interfaces/class-yoone-moneris-txn-types.php @@ -0,0 +1,23 @@ +