当前位置:   article > 正文

fastadmin 支付插件退款操作_fastadmin epay

fastadmin epay
 

//1 首先要安装fastadmin的支付插件 退款需配置证书 此方法使用后不能更新支付插件 升级后方法会被覆盖掉

//2 在addons\epay\library\Service 支付的同文件下放此方法 基本和支付参数参数差不多
 /**
     * 提交退款订单
     * @param array|float $amount    订单金额
     * @param array|float $refund_money    退款金额
     * @param string      $orderid   订单号
     * @param string      $refund_sn   退款订单号
     * @param string      $type      支付类型,可选alipay或wechat
     * @param string      $remark     退款原因
     * @param string      $notifyurl 通知回调URL
     * @param string      $returnurl 跳转返回URL
     * @param string      $method    支付方式
     * @return Response|RedirectResponse|Collection
     * @throws Exception
     */
    public static function submitRefund($amount=null,$refund_money,$orderid,$refund_sn,$type,$remark = null,$notifyurl = null,$returnurl = null,$method = 'app'){
        if (!is_array($amount)) {
            $params = [
                'amount'    => $amount,
                'type'      => $type,
                'notifyurl' => $notifyurl,
                'returnurl' => $returnurl,
                'method'    => $method,
            ];
        } else {
            $params = $amount;
        }
        $type = isset($params['type']) && in_array($params['type'], ['alipay', 'wechat']) ? $params['type'] : 'wechat';
        $request = request();
        $notifyurl = isset($params['notifyurl']) ? $params['notifyurl'] : $request->root(true) . '/addons/epay/index/' . $type . 'notify';
        // $returnurl = isset($params['returnurl']) ? $params['returnurl'] : $request->root(true) . '/addons/epay/index/' . $type . 'return/out_trade_no/' . $orderid;
        $config = Service::getConfig($type);
        $config['notify_url'] = $notifyurl;
        $config['return_url'] = $returnurl;
        $result = null;
        //退款参数
        $order_data = [
            'out_trade_no' => $orderid//原订单号
        ];
        if ($type == 'wechat') {
            //创建支付对象
            $pay = Pay::wechat($config);
            $total_fee = $amount * 100;
            $refund_fee = $refund_money * 100;
            $order_data = array_merge($order_data, [
                'out_refund_no' => $refund_sn,//退款订单号
                'total_fee' => $total_fee,//支付金额
                'refund_fee' => $refund_fee,//退款金额
                'refund_desc' => $remark,//退款原因
                'type' => $method  //支付方式
            ]);
        } else {
            $pay = Pay::alipay($config);
            $order_data = array_merge($order_data, [
                'out_request_no' => $refund_sn,//退款订单号
                'refund_amount' => $refund_money,
            ]);
        }

        $result = $pay->refund($order_data);

        //使用重写的Response类、RedirectResponse、Collection类
        if ($result instanceof \Symfony\Component\HttpFoundation\RedirectResponse) {
            $result = RedirectResponse::create($result->getTargetUrl());
        } elseif ($result instanceof \Symfony\Component\HttpFoundation\Response) {
            $result = Response::create($result->getContent());
        } elseif ($result instanceof \Yansongda\Supports\Collection) {
            $result = Collection::make($result->all());
        }
        return $result;
    }
    
    //3 在需要退款的地方 use addons\epay\library\Service;
   
      $orderInfo=$this->model::find($id);//退款订单信息
      
      $notifyurl = $this->request->domain().'/api/' . $this->request->controller() . '/refundNotifyx/paytype/' . $orderInfo->pay_type;//退款回调地址
      
      //直接调用退款方法传参即可
      
      $response = Service::submitRefund($orderInfo->pay_fee,$orderInfo->refund_fee, $orderInfo->order_sn,getRefundSn($userId),$orderInfo->pay_type, $orderInfo->reason, $notifyurl,'', 'app');
    
    //4生成退款订单号 此方法可自写
    
        if(!function_exists('getRefundSn')) {
           
                function getRefundSn($user_id)
                {
                        $rand = $user_id < 9999 ? mt_rand(100000, 99999999) : mt_rand(100, 99999);
                        $order_sn = date('Yhis') . $rand;
                        $id = str_pad($user_id, (24 - strlen($order_sn)), '0', STR_PAD_BOTH);
                        return 'R' . $order_sn . $id;
                 }
            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/132105
推荐阅读
相关标签
  

闽ICP备14008679号