Skip to content

Commit

Permalink
修正物流部份問題 #188547_3
Browse files Browse the repository at this point in the history
  • Loading branch information
AllennChang committed Mar 19, 2024
1 parent bbebc21 commit f873e11
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 72 deletions.
Binary file modified ecpay-ecommerce-for-woocommerce.zip
Binary file not shown.
6 changes: 5 additions & 1 deletion ecpay-ecommerce-for-woocommerce/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: ecommerce, e-commerce, store, sales, sell, shop, cart, checkout, payment,
Requires at least: 6.0
Tested up to: 6.0
Requires PHP: 8.2
Stable tag: 1.1.2312190
Stable tag: 1.1.2403150
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -19,6 +19,10 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html

== Changelog ==

v1.1.2403150
修正貨到付款使用永久連結結帳失敗問題
修正虛擬商品結帳失敗問題

v1.1.2312190
支援 HPOS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,53 +105,52 @@ public function add_address_meta($order) {
echo '<style>.logistic_button_display {display: inline-block;}</style>';
}

echo wp_kses_post('<p><strong>帳單姓名:<br/></strong>' . $order->get_meta('_billing_last_name', true) . ' ' . $order->get_meta('_billing_first_name', true) . '</p>');
echo wp_kses_post('<p><strong>帳單姓名:<br/></strong>' . $order->get_billing_last_name() . ' ' . $order->get_billing_first_name() . '</p>');
}

/**
* 訂單金流資訊回傳
*/
public function add_payment_info($order) {

$payment_method = $order->get_meta('_payment_method', true);
$payment_method = $order->get_payment_method();

echo '<p>&nbsp;</p>';
echo '<h3>' . __('Gateway info', 'ecpay-ecommerce-for-woocommerce') . '</h3>';

echo wp_kses_post('<p><strong>' . __('Payment Type', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_payment_method_title', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('Payment Type', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_payment_method_title() . '</p>');

switch ($payment_method) {
case 'Wooecpay_Gateway_Credit':
echo wp_kses_post('<p><strong>信用卡前六碼:&nbsp;</strong>' . $order->get_meta('_ecpay_card6no', true) . '</p>');
echo wp_kses_post('<p><strong>信用卡後四碼:&nbsp;</strong>' . $order->get_meta('_ecpay_card4no', true) . '</p>');
break;
case 'Wooecpay_Gateway_Credit_Installment':
echo wp_kses_post('<p><strong>期數:&nbsp;</strong>' . $order->get_meta('_ecpay_payment_number_of_periods', true) . '數</p>');
break;
case 'Wooecpay_Gateway_Atm':
echo wp_kses_post('<p><strong>' . __('Bank code', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_atm_BankCode', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('ATM No', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_atm_vAccount', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('Payment deadline', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_atm_ExpireDate', true) . '</p>');
break;
case 'Wooecpay_Gateway_Cvs':
echo wp_kses_post('<p><strong>' . __('CVS No', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_cvs_PaymentNo', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('Payment deadline', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_cvs_ExpireDate', true) . '</p>');
break;
case 'Wooecpay_Gateway_Barcode':
echo wp_kses_post('<p><strong>' . __('barcode one', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_Barcode1', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('barcode two', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_Barcode2', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('barcode three', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_Barcode3', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('Payment deadline', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_ExpireDate', true) . '</p>');
break;
case 'Wooecpay_Gateway_Twqr':
echo wp_kses_post('<p><strong>' . __('TWQR trade no', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_twqr_trad_no', true) . '</p>');
break;
case 'Wooecpay_Gateway_Bnpl':
echo wp_kses_post('<p><strong>' . __('BNPL Trade No', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_bnpl_BNPLTradeNo', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('BNPL Installment', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_bnpl_BNPLInstallment', true) . '</p>');
break;
default:
break;
case 'Wooecpay_Gateway_Credit':
echo wp_kses_post('<p><strong>信用卡前六碼:&nbsp;</strong>' . $order->get_meta('_ecpay_card6no', true) . '</p>');
echo wp_kses_post('<p><strong>信用卡後四碼:&nbsp;</strong>' . $order->get_meta('_ecpay_card4no', true) . '</p>');
break;
case 'Wooecpay_Gateway_Credit_Installment':
echo wp_kses_post('<p><strong>期數:&nbsp;</strong>' . $order->get_meta('_ecpay_payment_number_of_periods', true) . '數</p>');
break;
case 'Wooecpay_Gateway_Atm':
echo wp_kses_post('<p><strong>' . __('Bank code', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_atm_BankCode', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('ATM No', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_atm_vAccount', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('Payment deadline', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_atm_ExpireDate', true) . '</p>');
break;
case 'Wooecpay_Gateway_Cvs':
echo wp_kses_post('<p><strong>' . __('CVS No', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_cvs_PaymentNo', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('Payment deadline', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_cvs_ExpireDate', true) . '</p>');
break;
case 'Wooecpay_Gateway_Barcode':
echo wp_kses_post('<p><strong>' . __('barcode one', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_Barcode1', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('barcode two', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_Barcode2', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('barcode three', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_Barcode3', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('Payment deadline', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_barcode_ExpireDate', true) . '</p>');
break;
case 'Wooecpay_Gateway_Twqr':
echo wp_kses_post('<p><strong>' . __('TWQR trade no', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_twqr_trad_no', true) . '</p>');
break;
case 'Wooecpay_Gateway_Bnpl':
echo wp_kses_post('<p><strong>' . __('BNPL Trade No', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_bnpl_BNPLTradeNo', true) . '</p>');
echo wp_kses_post('<p><strong>' . __('BNPL Installment', 'ecpay-ecommerce-for-woocommerce') . ':&nbsp;</strong>' . $order->get_meta('_ecpay_bnpl_BNPLInstallment', true) . '</p>');
break;
default:
break;
}
}

Expand All @@ -173,7 +172,7 @@ public function check_order_status_cancel($order) {
) {

// 判斷金流方式
$payment_method = $order->get_meta('_payment_method', true);
$payment_method = $order->get_payment_method();

if (
$payment_method == 'Wooecpay_Gateway_Credit' ||
Expand Down Expand Up @@ -363,11 +362,12 @@ public function add_invoice_meta($order) {
* 複寫聯絡電話至收件人電話
*/
public function order_update_sync_shipping_phone($post_id) {
if ($order = wc_get_order($post_id)) {
$shipping_phone = (!empty($order->get_shipping_phone())) ?: $order->get_billing_phone();

$shipping_phone = $order->get_meta('_shipping_phone', true);

$order->update_meta_data('wooecpay_shipping_phone', $shipping_phone);
$order->save();
$order->update_meta_data('wooecpay_shipping_phone', $shipping_phone);
$order->save();
}
}

public function ecpay_validate_logistic_fields($post_id, $data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* @copyright Copyright (c) 2016 Green World FinTech Service Co., Ltd. (https://www.ecpay.com.tw)
* @version 1.1.2312190
* @version 1.1.2403150
*
* Plugin Name: ECPay Ecommerce for WooCommerce
* Plugin URI: https://www.ecpay.com.tw
* Description: Ecpay Plug for WooCommerce
* Version: 1.1.2312190
* Version: 1.1.2403150
* Author: ECPay Green World FinTech Service Co., Ltd.
* Author URI: https://www.ecpay.com.tw
* License: GPLv2
Expand All @@ -20,7 +20,7 @@
defined('ABSPATH') or exit;

// 相關常數定義
define('WOOECPAY_VERSION', '1.1.2312190');
define('WOOECPAY_VERSION', '1.1.2403150');
define('REQUIREMENT_WOOCOMMERCE_VERSION', '8.3.0');
define('WOOECPAY_PLUGIN_URL', plugin_dir_url(__FILE__));
define('WOOECPAY_PLUGIN_DIR', plugin_dir_path(__FILE__));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public function invoice_create($order) {
$wooecpay_invoice_dalay_date = (int) $wooecpay_invoice_dalay_date;

// 取得付款方式,判斷是否紀錄發票備註
$payment_method = $order->get_meta('_payment_method', true);
$payment_method = $order->get_payment_method();

if (empty($wooecpay_invoice_dalay_date)) {
// 立即開立
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ public function get_available_state_home_tcat_outside() {
];
}

public function get_permalink($url) {
// 產生符合永久連結格式的API URL
$symbol = (strpos($url, '?') === false) ? '?' : '&';
return $url . $symbol;
}

public function generate_ecpay_map_form($shipping_method_id, $order_id) {
$api_logistic_info = $this->get_ecpay_logistic_api_info('map');
$client_back_url = WC()->api_request_url('wooecpay_change_logistic_map_callback', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public function check_order_is_duplicate_payment($order)
$merchant_trade_no_list = [];

// 取得訂單付款方式
$payment_method = $order->get_meta('_payment_method', true);
$payment_method = $order->get_payment_method();

// 取得重複付款訂單的綠界金流特店交易編號
$merchant_trade_no_list = $this->get_duplicate_payment_orders_merchant_trade_no($order->get_id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,23 @@ public function validate_checkout_shipping_field($data, $errors) {
$chosen_shipping = $this->get_chosen_shipping_method_ids();
$chosen_shipping = (empty($chosen_shipping)) ? '' : $chosen_shipping[0];

// 收件人姓名檢查
$error_message = $this->logisticHelper->validate_shipping_field('name', $data['shipping_last_name'] . $data['shipping_first_name']);
if ($error_message != '') {
$errors->add('validation', $error_message);
}
if (WC()->cart->needs_shipping() && WC()->cart->show_shipping() && $this->logisticHelper->is_ecpay_logistics($chosen_shipping)) {
// 收件人姓名檢查
$error_message = $this->logisticHelper->validate_shipping_field('name', $data['shipping_last_name'] . $data['shipping_first_name']);
if ($error_message != '') {
$errors->add('validation', $error_message);
}

// 驗證收件人電話
$error_message = $this->logisticHelper->validate_shipping_field('phone', $data['billing_phone']);
if ($error_message != '') {
$errors->add('validation', $error_message);
}
// 驗證收件人電話
$error_message = $this->logisticHelper->validate_shipping_field('phone', $data['billing_phone']);
if ($error_message != '') {
$errors->add('validation', $error_message);
}

// 黑貓宅配離島檢查
if (in_array($chosen_shipping, ['Wooecpay_Logistic_Home_Tcat', 'Wooecpay_Logistic_Home_Tcat_Outside']) && in_array('Wooecpay_Logistic_Home_Tcat', get_option('wooecpay_enabled_logistic_outside', []))) {
$this->wooecpay_check_logistic_home_fields($data, $errors, $chosen_shipping);
// 黑貓宅配離島檢查
if (in_array($chosen_shipping, ['Wooecpay_Logistic_Home_Tcat', 'Wooecpay_Logistic_Home_Tcat_Outside']) && in_array('Wooecpay_Logistic_Home_Tcat', get_option('wooecpay_enabled_logistic_outside', []))) {
$this->wooecpay_check_logistic_home_fields($data, $errors, $chosen_shipping);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function map_response() {
if (!$is_valid) {
$confirm_msg = __('The selected store does not match the chosen shipping method (Outlying Island/Main Island). Please select a different store or cancel the transaction and place a new order.', 'ecpay-ecommerce-for-woocommerce');
$encryption_order_id = $this->logisticHelper->encrypt_order_id($order_id);
$url = WC()->api_request_url('wooecpay_logistic_redirect_map', true) . '&id=' . $encryption_order_id;
$url = $this->logisticHelper->get_permalink(WC()->api_request_url('wooecpay_logistic_redirect_map', true)) . 'id=' . $encryption_order_id;

// 提示訊息
echo '<script>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function receipt_page($order_id) {
$shippping_tag = true;
}

ecpay_log('物流方式-' . $shipping_method_id, 'A00002', $order_id);
ecpay_log('物流方式-' . print_r($shipping_method_id, true), 'A00002', $order_id);

if ($shippping_tag && $this->logisticHelper->is_ecpay_cvs_logistics($shipping_method_id)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ public function redirect_url($url, $orderInfo) {
// 付款方式
$payment_method = $orderInfo->get_payment_method();

// 物流方式
$shipping_method_id = $orderInfo->get_items('shipping');
$shipping_method_id = reset($shipping_method_id);
$shipping_method_id = $shipping_method_id->get_method_id();

if ($payment_method == 'cod') {

// 物流方式
$shipping_method_id = $orderInfo->get_items('shipping');
$shipping_method_id = reset($shipping_method_id);
$shipping_method_id = $shipping_method_id ? $shipping_method_id->get_method_id() : '';

// 紀錄訂單付款資訊進 DB
$this->paymentHelper->insert_ecpay_orders_payment_status($orderInfo->get_id(), $payment_method, '', 1);

if ($this->logisticHelper->is_ecpay_logistics($shipping_method_id)) {
$encryption_order_id = $this->logisticHelper->encrypt_order_id($orderInfo->get_id());
$redirect_cvs_map_url = WC()->api_request_url('wooecpay_logistic_redirect_map_preprocessor', true) . '&id=' . $encryption_order_id;
$redirect_cvs_map_url = $this->logisticHelper->get_permalink(WC()->api_request_url('wooecpay_logistic_redirect_map_preprocessor', true)) . 'id=' . $encryption_order_id;

return $redirect_cvs_map_url;
}
}
Expand Down Expand Up @@ -75,7 +77,7 @@ public function redirect_map_preprocessor() {
$shippping_tag &&
$this->logisticHelper->is_ecpay_cvs_logistics($shipping_method_id)
) {
$client_back_url = WC()->api_request_url('wooecpay_logistic_map_response', true) . '&id=' . $id;
$client_back_url = $this->logisticHelper->get_permalink(WC()->api_request_url('wooecpay_logistic_map_response', true)) . 'id=' . $id;
$api_logistic_info = $this->logisticHelper->get_ecpay_logistic_api_info('map');
$MerchantTradeNo = $this->logisticHelper->get_merchant_trade_no($order->get_id(), get_option('wooecpay_logistic_order_prefix'));
$LogisticsType = $this->logisticHelper->get_logistics_sub_type($shipping_method_id);
Expand Down Expand Up @@ -205,8 +207,8 @@ public function logistic_map_response() {
// 重導地圖API
$confirm_msg = __('The selected store does not match the chosen shipping method (Outlying Island/Main Island). Please select a different store or cancel the transaction and place a new order.', 'ecpay-ecommerce-for-woocommerce');

$redirect_cvs_map_url = WC()->api_request_url('wooecpay_logistic_redirect_map_preprocessor', true) . '&id=' . $id;
$canceled_url = WC()->api_request_url('wooecpay_logistic_cancel_order_cod', true) . '&id=' . $id;
$redirect_cvs_map_url = $this->logisticHelper->get_permalink(WC()->api_request_url('wooecpay_logistic_redirect_map_preprocessor', true)) . 'id=' . $id;
$canceled_url = $this->logisticHelper->get_permalink(WC()->api_request_url('wooecpay_logistic_cancel_order_cod', true)) . 'id=' . $id;

// 提示訊息
echo '<script> ';
Expand All @@ -228,7 +230,7 @@ public function woocommerce_cod_pending_payment_order_status($order_status, $ord
// 物流方式
$shipping_method_id = $order->get_items('shipping');
$shipping_method_id = reset($shipping_method_id);
$shipping_method_id = $shipping_method_id->get_method_id();
$shipping_method_id = $shipping_method_id ? $shipping_method_id->get_method_id() : '';

if ($this->logisticHelper->is_ecpay_cvs_logistics($shipping_method_id)) {
$order_status = 'pending';
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: ECPay Ecommerce for WooCommerce\n"
"POT-Creation-Date: 2023-12-28 10:31+0800\n"
"PO-Revision-Date: 2023-12-28 10:46+0800\n"
"PO-Revision-Date: 2024-03-07 17:16+0800\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: zh_TW\n"
Expand Down

0 comments on commit f873e11

Please sign in to comment.