parent
24995dcba5
commit
fdd92dbfff
|
|
@ -54,6 +54,20 @@ class WC_Huayi_Score extends WC_Payment_Gateway {
|
|||
'label' => __( '开启积分支付', 'huayi_score' ),
|
||||
'default' => 'yes'
|
||||
),
|
||||
'apiurl' => array(
|
||||
'title' => __( 'API地址', 'huayi_score' ),
|
||||
'type' => 'text',
|
||||
'description' => __( '对接API的地址.', 'huayi_score' ),
|
||||
'default' => __( 'https://test.com', 'huayi_score' ),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
'token' => array(
|
||||
'title' => __( 'Token', 'huayi_score' ),
|
||||
'type' => 'text',
|
||||
'description' => __( 'API Token.', 'huayi_score' ),
|
||||
'default' => __( 'token', 'huayi_score' ),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
'title' => array(
|
||||
'title' => __( '名称', 'huayi_score' ),
|
||||
'type' => 'text',
|
||||
|
|
@ -116,12 +130,12 @@ class WC_Huayi_Score extends WC_Payment_Gateway {
|
|||
// $huayi_unionid = get_user_meta( $order->get_user_id() , 'huayi_unionid',true );//获取登录接口后的unionid
|
||||
|
||||
if ( $huayi_uid > 0 ) {
|
||||
$scoreBalance = huayi_score_balance($huayi_uid);//获取积分余额 TODO
|
||||
if ($scoreBalance >= $order->order_total ) {//积分够扣
|
||||
$scorePay = huayi_score_pay($huayi_uid,$order->order_total,'订单号:'.$order_id);//执行扣款 TODO
|
||||
|
||||
$huayiScoreSdk = new HuayiScoreSdk(array('apiurl'=>'1','token'=>'1'));
|
||||
$balanceResult = $huayiScoreSdk->getBalance($huayi_uid);//获取积分余额 TODO
|
||||
if ($balanceResult >= $order->order_total ) {//积分够扣
|
||||
$payResult = $huayiScoreSdk->pay($huayi_uid,$order->order_total,'订单号:'.$order_id);//执行扣款 TODO
|
||||
//支付成功
|
||||
if ( $scorePay['uid'] > 0 ) {//TODO 修正状态判断
|
||||
if ( $payResult['uid'] > 0 ) {//TODO 修正状态判断
|
||||
|
||||
//更新订单状态
|
||||
//$order->update_status( 'on-hold', __( '等待积分支付', 'huayi_score' ) );//需要支付回调的接口才需要
|
||||
|
|
@ -139,7 +153,7 @@ class WC_Huayi_Score extends WC_Payment_Gateway {
|
|||
'redirect' => $this->get_return_url( $order )
|
||||
);
|
||||
} else { //支付失败
|
||||
$error_message = '支付接口出错 - ' . $scorePay;
|
||||
$error_message = '支付接口出错 - ' . $payResult;
|
||||
wc_add_notice( __('结算失败:', 'huayi_score') . $error_message, 'error' );
|
||||
return;
|
||||
}
|
||||
|
|
@ -168,7 +182,8 @@ class WC_Huayi_Score extends WC_Payment_Gateway {
|
|||
$huayi_uid = get_user_meta( $order->get_user_id() , 'huayi_uid',true );
|
||||
|
||||
if ( $huayi_uid > 0 ) {
|
||||
$result = huayi_score_refund($huayi_uid,$amount,'退款订单号:'.$order_id.'.退款原因:'.$reason);//执行退款
|
||||
$huayiScoreSdk = new HuayiScoreSdk(array('apiurl'=>'1','token'=>'1'));
|
||||
$result = $huayiScoreSdk->refund($huayi_uid,$amount,'退款订单号:'.$order_id.'.退款原因:'.$reason);//执行退款
|
||||
|
||||
if ( $result['uid'] > 0 ) {//TODO 修正状态判断
|
||||
$order->add_order_note( sprintf( __( '退款时间: %s - 退款会员ID: %s', 'huayi_score' ), date("Y-m-d H:i:s"),$result['uid'] ) );
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
* WordPress 个人资料添加额外的字段
|
||||
* http://www.wpdaxue.com/extra-user-profile-fields.html
|
||||
*/
|
||||
if (!has_action('show_user_profile','huayi_score_user_fields') && !has_action('edit_user_profile','huayi_score_user_fields')) {
|
||||
add_action( 'show_user_profile', 'huayi_score_user_fields' );
|
||||
add_action( 'edit_user_profile', 'huayi_score_user_fields' );
|
||||
if (!has_action('edit_user_profile','huayi_score_user_fields')) {
|
||||
// add_action( 'show_user_profile', 'huayi_score_user_fields' );//修改当前用户
|
||||
add_action( 'edit_user_profile', 'huayi_score_user_fields' );//修改其他用户
|
||||
}
|
||||
|
||||
function huayi_score_user_fields($user)
|
||||
|
|
@ -83,12 +83,10 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
<?php
|
||||
}
|
||||
|
||||
if (!has_action('show_user_profile','huayi_score_user_fields') && !has_action('edit_user_profile','huayi_score_user_fields')) {
|
||||
add_action( 'personal_options_update', 'huayi_score_save_user_fields' );
|
||||
add_action( 'edit_user_profile_update', 'huayi_score_save_user_fields' );
|
||||
if (!has_action('edit_user_profile_update','huayi_score_save_user_fields')) {
|
||||
// add_action( 'personal_options_update', 'huayi_score_save_user_fields' );//修改当前用户
|
||||
add_action( 'edit_user_profile_update', 'huayi_score_save_user_fields' );//修改其他用户
|
||||
}
|
||||
add_action( 'personal_options_update', 'huayi_score_save_user_fields' );
|
||||
add_action( 'edit_user_profile_update', 'huayi_score_save_user_fields' );
|
||||
|
||||
function huayi_score_save_user_fields($user_id)
|
||||
{
|
||||
|
|
@ -97,5 +95,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
}
|
||||
// update_usermeta($user_id, 'huayi_openid', $_POST['huayi_openid']);
|
||||
// update_usermeta($user_id, 'huayi_unionid', $_POST['huayi_unionid']);
|
||||
if (!isset($_POST['huayi_uid'])) {
|
||||
update_usermeta($user_id, 'huayi_uid', $_POST['huayi_uid']);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class HuayiScoreSdk
|
||||
{
|
||||
protected $apiurl = null;
|
||||
protected $token = null;
|
||||
public function __construct($option)
|
||||
{
|
||||
$this->apiurl = isset($option['apiurl']) ? $option['apiurl'] : '';
|
||||
$this->token = isset($option['token']) ? $option['token'] : '';
|
||||
}
|
||||
/**
|
||||
* 获取积分余额
|
||||
*/
|
||||
public function getBalance($huayi_uid)
|
||||
{
|
||||
return $huayi_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支出积分
|
||||
* @return string
|
||||
*/
|
||||
public function pay($huayi_uid,$amount,$note)
|
||||
{
|
||||
return $huayi_uid.$amount.$note;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退还积分
|
||||
* @return string
|
||||
*/
|
||||
public function refund($huayi_uid,$amount,$note)
|
||||
{
|
||||
return $huayi_uid.$amount.$note;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue