laravel 微信退款
作者:互联网
use Overtrue\Wechat\Payment;
use Overtrue\Wechat\Payment\Business;
use Overtrue\Wechat\Payment\Refund;
private $NOTIFYURL = 回调地址';
private $appId = 'appId ';
private $appSercret = 'appSercret ';
private $mchId = 'mchId';
private $mchKey = mchKey';
public function OrderRefundSave(Request $request){
$input = $request->all();
$user_refund = UserOrderRefund::where('id',$input['refund_id'])->first();
$user_order = UserOrder::where('id',$user_refund->order_id)->first();
$business = new Business($this->appId, $this->appSercret, $this->mchId, $this->mchKey);
$business->setClientCert(dirname(__FILE__).'/cert/apiclient_cert.pem');
$business->setClientKey(dirname(__FILE__).'/cert/apiclient_key.pem');
$refund =new Refund($business);
$refund->out_refund_no= md5(uniqid(microtime()));//退单单号
$refund->total_fee=$user_refund->refund_price * 100; //订单金额
//$refund->refund_fee=$user_refund->refund_price * 100;//退款金额
$refund->refund_fee=0.01* 100;//退款金额
$refund->out_trade_no=$user_order->order_sn;//原商户订单号
$wxRefund = $refund->getResponse();
if($wxRefund['return_code'] != 'SUCCESS' || $wxRefund['result_code'] !='SUCCESS'){
admin_toastr('退款失败','error');
return redirect(admin_url('order-refund/'.$input['refund_id'].'/edit'));
}
$user_refund->status = 1;
$user_refund->refund_may_price = $input['refund_price'];
$user_refund->save();
admin_toastr('退款成功','success');
return redirect(admin_url('order-refund/'.$input['refund_id']));
}
标签:laravel,refund,微信,private,order,user,input,退款,id 来源: https://blog.csdn.net/qq_34333717/article/details/98954245