fastadmin 支付插件退款操作

编程入门 行业动态 更新时间:2024-10-07 12:28:25

fastadmin 支付<a href=https://www.elefans.com/category/jswz/34/1771202.html style=插件退款操作"/>

fastadmin 支付插件退款操作

 //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;}}

更多推荐

fastadmin 支付插件退款操作

本文发布于:2024-02-05 11:09:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1744971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插件   操作   fastadmin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!