Signed-off-by: hitsword <mail@huayizhiyun.com>
This commit is contained in:
hitsword
2019-05-20 13:22:01 +08:00
parent 24995dcba5
commit fdd92dbfff
3 changed files with 72 additions and 16 deletions
+22 -7
View File
@@ -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'] ) );