Skip to content

Commit

Permalink
增加apple pay 付款方式
Browse files Browse the repository at this point in the history
  • Loading branch information
AllennChang committed Oct 24, 2022
1 parent 87218da commit 61a0c33
Show file tree
Hide file tree
Showing 15 changed files with 1,399 additions and 1,085 deletions.
1,986 changes: 1,083 additions & 903 deletions ecpay-ecommerce-for-woocommerce/admin/order/class-wooecpay-order.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function output() {

if ( $current_section == '' ) {
wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=wooecpay_setting&section=ecpay_main' ) );
exit;
}
$settings = $this->get_settings( $current_section );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin Name: ECPay Ecommerce for WooCommerce
* Plugin URI: https://www.ecpay.com.tw
* Description: Ecpay Plug for WooCommerce
* Version: 1.0.220728
* Version: 1.0.221019
* 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.0.220728' );
define( 'WOOECPAY_VERSION', '1.0.220714' );
define( 'WOOECPAY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'WOOECPAY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'WOOECPAY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
'desc' => __('Only letters and numbers allowed.', 'ecpay-ecommerce-for-woocommerce'),
'desc_tip' => true
],
[
'title' => __( 'Display order item name', 'ecpay-ecommerce-for-woocommerce' ),
'id' => 'wooecpay_enabled_logistic_disp_item_name',
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display order item name', 'ecpay-ecommerce-for-woocommerce' ),
'desc_tip' => false
],
[
'title' => __('CVS type', 'ecpay-ecommerce-for-woocommerce'),
'id' => 'wooecpay_logistic_cvs_type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'name' => __( 'Enable ECPay gateway method', 'ecpay-ecommerce-for-woocommerce'),
'type' => 'checkbox',
'desc' => __( 'Enable ECPay gateway method', 'ecpay-ecommerce-for-woocommerce'),
'id' => 'wooecpay_ecpay_enabled_payment',
'id' => 'wooecpay_enabled_payment',
'default' => 'no',
'desc_tip' => true,
],
Expand All @@ -20,7 +20,7 @@
'name' => __( 'Enable ECPay shipping method', 'ecpay-ecommerce-for-woocommerce'),
'type' => 'checkbox',
'desc' => __( 'Enable ECPay shipping method', 'ecpay-ecommerce-for-woocommerce'),
'id' => 'wooecpay_ecpay_enabled_logistic',
'id' => 'wooecpay_enabled_logistic',
'default' => 'no',
'desc_tip' => true,
],
Expand All @@ -29,7 +29,7 @@
'name' => __( 'Enable ECPay invoice method', 'ecpay-ecommerce-for-woocommerce'),
'type' => 'checkbox',
'desc' => __( 'Enable ECPay invoice method', 'ecpay-ecommerce-for-woocommerce'),
'id' => 'wooecpay_ecpay_enabled_invoice',
'id' => 'wooecpay_enabled_invoice',
'default' => 'no',
'desc_tip' => true,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function gateway_disable_for_shipping_rate( $available_gateways ) {

if ( ! is_admin() ) {

$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
$chosen_shipping_tmp = wc_get_chosen_shipping_method_ids();
$chosen_shipping = $chosen_shipping_tmp[0] ;

if(!empty($chosen_shipping)){

Expand All @@ -89,6 +89,7 @@ function gateway_disable_for_shipping_rate( $available_gateways ) {
$key == 'Wooecpay_Gateway_Atm' ||
$key == 'Wooecpay_Gateway_Cvs' ||
$key == 'Wooecpay_Gateway_Barcode' ||
$key == 'Wooecpay_Gateway_Applepay' ||
$key == 'cod'
){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,18 @@ public function __construct($instance_id = 0)
parent::__construct();

}

public function is_available($package)
{
$is_available = true;

$total = WC()->cart->cart_contents_total ;

// 金額超過2萬元時不顯示綠界超商物流
if($total >= 20000){
$is_available = false ;
}

return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package, $this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ public function __construct($instance_id = 0)
parent::__construct();

}

public function is_available($package)
{
$is_available = true;

$total = WC()->cart->cart_contents_total ;

// 金額超過2萬元時不顯示綠界超商物流
if($total >= 20000){
$is_available = false ;
}

return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package, $this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ public function __construct($instance_id = 0)
parent::__construct();

}

public function is_available($package)
{
$is_available = true;

$total = WC()->cart->cart_contents_total ;

// 金額超過2萬元時不顯示綠界超商物流
if($total >= 20000){
$is_available = false ;
}

return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package, $this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,18 @@ public function __construct($instance_id = 0)
parent::__construct();

}

public function is_available($package)
{
$is_available = true;

$total = WC()->cart->cart_contents_total ;

// 金額超過2萬元時不顯示綠界超商物流
if($total >= 20000){
$is_available = false ;
}

return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package, $this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public function map_response()
// 紀錄訂單其他資訊
$order->update_meta_data( '_wooecpay_payment_order_prefix', get_option('wooecpay_payment_order_prefix') ); // 前綴
$order->update_meta_data( '_wooecpay_payment_merchant_trade_no', $merchant_trade_no ); //MerchantTradeNo

$order->update_meta_data( '_wooecpay_query_trade_tag', 0);

$order->add_order_note(sprintf(__('Ecpay Payment Merchant Trade No %s', 'ecpay-ecommerce-for-woocommerce'), $merchant_trade_no));

$order->save();
Expand All @@ -124,7 +125,7 @@ public function map_response()
'MerchantTradeDate' => date('Y/m/d H:i:s'),
'PaymentType' => 'aio',
'TotalAmount' => (int) ceil($order->get_total()),
'TradeDesc' => UrlService::ecpayUrlEncode(get_bloginfo('name')),
'TradeDesc' => 'woocommerce_v2',
'ItemName' => $item_name,
'ChoosePayment' => $this->get_ChoosePayment($order->get_payment_method()),
'EncryptType' => 1,
Expand Down Expand Up @@ -290,6 +291,8 @@ public function logistic_status_response()

$order->add_order_note('物流貨態回傳:'.$RtnMsg.' ('.$RtnCode.')');
$order->save();

echo '1|OK';
}
}
}
Expand Down Expand Up @@ -378,15 +381,15 @@ protected function add_type_info($input, $order)
break;

case 'ATM':
$input['ExpireDate'] = $this->get_option('_wooecpay_payment_expire_date', 3);
$input['ExpireDate'] = get_option('_wooecpay_payment_expire_date', 3);
break;

case 'BARCODE':
$input['StoreExpireDate'] = $this->get_option('_wooecpay_payment_expire_date', 3);
$input['StoreExpireDate'] = get_option('_wooecpay_payment_expire_date', 3);
break;

case 'CVS':
$input['StoreExpireDate'] = $this->get_option('_wooecpay_payment_expire_date', 86400);
$input['StoreExpireDate'] = get_option('_wooecpay_payment_expire_date', 86400);
break;
}

Expand Down Expand Up @@ -416,6 +419,10 @@ protected function get_ChoosePayment($payment_method)
case 'Wooecpay_Gateway_Barcode':
$choose_payment = 'BARCODE' ;
break;

case 'Wooecpay_Gateway_Applepay':
$choose_payment = 'ApplePay' ;
break;
}

return $choose_payment ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function load_payment_gateway() {
include WOOECPAY_PLUGIN_INCLUDE_DIR . '/services/payment/ecpay-gateway-webatm.php';
include WOOECPAY_PLUGIN_INCLUDE_DIR . '/services/payment/ecpay-gateway-barcode.php';
include WOOECPAY_PLUGIN_INCLUDE_DIR . '/services/payment/ecpay-gateway-cvs.php';
include WOOECPAY_PLUGIN_INCLUDE_DIR . '/services/payment/ecpay-gateway-applepay.php';

include WOOECPAY_PLUGIN_INCLUDE_DIR . '/services/payment/woocommerce-gateway-cod.php'; // 貨到付款相關程序
}

Expand All @@ -47,6 +49,7 @@ public function add_method($methods)
$methods[] = 'Wooecpay_Gateway_Atm';
$methods[] = 'Wooecpay_Gateway_Cvs';
$methods[] = 'Wooecpay_Gateway_Barcode';
$methods[] = 'Wooecpay_Gateway_Applepay';

return $methods;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,35 @@ public function receipt_page($order_id)

// 執行地圖選擇

// 取出商店代號
$CVSStoreID = $order->get_meta('_ecpay_logistic_cvs_store_id') ;

if(empty($CVSStoreID)){

// 不存在則走向地圖API
$api_logistic_info = $this->get_ecpay_logistic_api_info();
$client_back_url = WC()->api_request_url('wooecpay_logistic_map_callback', true);
$MerchantTradeNo = $this->get_merchant_trade_no($order->get_id(), get_option('wooecpay_logistic_order_prefix'));
$LogisticsType = $this->get_logistics_sub_type($shipping_method_id) ;

try {
$factory = new Factory([
'hashKey' => $api_logistic_info['hashKey'],
'hashIv' => $api_logistic_info['hashIv'],
'hashMethod' => 'md5',
]);
$autoSubmitFormService = $factory->create('AutoSubmitFormWithCmvService');

$input = [
'MerchantID' => $api_logistic_info['merchant_id'],
'MerchantTradeNo' => $MerchantTradeNo,
'LogisticsType' => $LogisticsType['type'],
'LogisticsSubType' => $LogisticsType['sub_type'],
'IsCollection' => 'Y',
'ServerReplyURL' => $client_back_url,
];

$form_map = $autoSubmitFormService->generate($input, $api_logistic_info['action']);

echo $form_map ;

} catch (RtnException $e) {
echo wp_kses_post( '(' . $e->getCode() . ')' . $e->getMessage() ) . PHP_EOL;
}
// 不存在則走向地圖API
$api_logistic_info = $this->get_ecpay_logistic_api_info();
$client_back_url = WC()->api_request_url('wooecpay_logistic_map_callback', true);
$MerchantTradeNo = $this->get_merchant_trade_no($order->get_id(), get_option('wooecpay_logistic_order_prefix'));
$LogisticsType = $this->get_logistics_sub_type($shipping_method_id) ;

try {
$factory = new Factory([
'hashKey' => $api_logistic_info['hashKey'],
'hashIv' => $api_logistic_info['hashIv'],
'hashMethod' => 'md5',
]);
$autoSubmitFormService = $factory->create('AutoSubmitFormWithCmvService');

$input = [
'MerchantID' => $api_logistic_info['merchant_id'],
'MerchantTradeNo' => $MerchantTradeNo,
'LogisticsType' => $LogisticsType['type'],
'LogisticsSubType' => $LogisticsType['sub_type'],
'IsCollection' => 'Y',
'ServerReplyURL' => $client_back_url,
];

$form_map = $autoSubmitFormService->generate($input, $api_logistic_info['action']);

echo $form_map ;

} catch (RtnException $e) {
echo wp_kses_post( '(' . $e->getCode() . ')' . $e->getMessage() ) . PHP_EOL;
}


Expand All @@ -103,6 +97,8 @@ public function receipt_page($order_id)
// 紀錄訂單其他資訊
$order->update_meta_data( '_wooecpay_payment_order_prefix', get_option('wooecpay_payment_order_prefix') ); // 前綴
$order->update_meta_data( '_wooecpay_payment_merchant_trade_no', $merchant_trade_no ); //MerchantTradeNo
$order->update_meta_data( '_wooecpay_query_trade_tag', 0);

$order->add_order_note(sprintf(__('Ecpay Payment Merchant Trade No %s', 'ecpay-ecommerce-for-woocommerce'), $merchant_trade_no));

$order->save();
Expand All @@ -122,7 +118,7 @@ public function receipt_page($order_id)
'MerchantTradeDate' => date('Y/m/d H:i:s'),
'PaymentType' => 'aio',
'TotalAmount' => (int) ceil($order->get_total()),
'TradeDesc' => UrlService::ecpayUrlEncode(get_bloginfo('name')),
'TradeDesc' => 'woocommerce_v2',
'ItemName' => $item_name,
'ChoosePayment' => $this->payment_type,
'EncryptType' => 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,25 @@ public function payment_fields()
{
parent::payment_fields();

$total = $this->get_order_total();

echo '<p>' . _x('Number of periods', 'Checkout info', 'ecpay-ecommerce-for-woocommerce');
echo '<select name="ecpay_number_of_periods">';

foreach ($this->number_of_periods as $number_of_periods) {
echo '<option value="' . esc_attr($number_of_periods) . '">' . wp_kses_post($number_of_periods) . '</option>';

// 圓夢分期有2W的限制
if($number_of_periods == 30){

if($total >= 20000){
echo '<option value="' . esc_attr($number_of_periods) . '">' . wp_kses_post($number_of_periods) . '</option>';
}

} else {
echo '<option value="' . esc_attr($number_of_periods) . '">' . wp_kses_post($number_of_periods) . '</option>';
}
}

echo '</select>';
}

Expand Down
Loading

0 comments on commit 61a0c33

Please sign in to comment.