mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 17:31:49 +08:00 
			
		
		
		
	update: payment add custom notify domain name
This commit is contained in:
		| @@ -26,7 +26,12 @@ class PaymentController extends Controller | ||||
|     { | ||||
|         $payments = Payment::all(); | ||||
|         foreach ($payments as $k => $v) { | ||||
|             $payments[$k]['notify_url'] = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}"); | ||||
|             $notifyUrl = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}"); | ||||
|             if ($v->notify_domain) { | ||||
|                 $parseUrl = parse_url($notifyUrl); | ||||
|                 $notifyUrl = $v->notify_domain . $parseUrl['path']; | ||||
|             } | ||||
|             $payments[$k]['notify_url'] = $notifyUrl; | ||||
|         } | ||||
|         return response([ | ||||
|             'data' => $payments | ||||
| @@ -58,22 +63,20 @@ class PaymentController extends Controller | ||||
|                 'data' => true | ||||
|             ]); | ||||
|         } | ||||
|         $request->validate([ | ||||
|         $params = $request->validate([ | ||||
|             'name' => 'required', | ||||
|             'icon' => 'nullable', | ||||
|             'payment' => 'required', | ||||
|             'config' => 'required' | ||||
|             'config' => 'required', | ||||
|             'notify_domain' => 'nullable|url' | ||||
|         ], [ | ||||
|             'name.required' => '显示名称不能为空', | ||||
|             'payment.required' => '网关参数不能为空', | ||||
|             'config.required' => '配置参数不能为空' | ||||
|             'config.required' => '配置参数不能为空', | ||||
|             'notify_domain.url' => '自定义通知域名格式有误' | ||||
|         ]); | ||||
|         if (!Payment::create([ | ||||
|             'name' => $request->input('name'), | ||||
|             'icon' => $request->input('icon'), | ||||
|             'payment' => $request->input('payment'), | ||||
|             'config' => $request->input('config'), | ||||
|             'uuid' => Helper::randomChar(8) | ||||
|         ])) { | ||||
|         $params['uuid'] = Helper::randomChar(8); | ||||
|         if (!Payment::create($params)) { | ||||
|             abort(500, '保存失败'); | ||||
|         } | ||||
|         return response([ | ||||
|   | ||||
| @@ -32,25 +32,16 @@ class MGate { | ||||
|                 'label' => 'AppSecret', | ||||
|                 'description' => '', | ||||
|                 'type' => 'input', | ||||
|             ], | ||||
|             'notify_domain' => [ | ||||
|                 'label' => '通知域名(选填)', | ||||
|                 'description' => '用于接收来自网关的支付通知', | ||||
|                 'type' => 'input' | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function pay($order) | ||||
|     { | ||||
|         if (isset($this->config['notify_domain'])) { | ||||
|             $parseUrl = parse_url($order['notify_url']); | ||||
|             $notifyUrl = "{$parseUrl['scheme']}://{$this->config['notify_domain']}{$parseUrl['path']}"; | ||||
|         } | ||||
|         $params = [ | ||||
|             'out_trade_no' => $order['trade_no'], | ||||
|             'total_amount' => $order['total_amount'], | ||||
|             'notify_url' => $notifyUrl ?? $order['notify_url'], | ||||
|             'notify_url' => $order['notify_url'], | ||||
|             'return_url' => $order['return_url'] | ||||
|         ]; | ||||
|         $params['app_id'] = $this->config['mgate_app_id']; | ||||
|   | ||||
| @@ -26,6 +26,7 @@ class PaymentService | ||||
|             $this->config['enable'] = $payment['enable']; | ||||
|             $this->config['id'] = $payment['id']; | ||||
|             $this->config['uuid'] = $payment['uuid']; | ||||
|             $this->config['notify_domain'] = $payment['notify_domain']; | ||||
|         }; | ||||
|         $this->payment = new $this->class($this->config); | ||||
|         if (isset($this->payment->customResult)) $this->customResult = $this->payment->customResult; | ||||
| @@ -39,8 +40,15 @@ class PaymentService | ||||
|  | ||||
|     public function pay($order) | ||||
|     { | ||||
|         // custom notify domain name | ||||
|         $notifyUrl = url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"); | ||||
|         if ($this->config['notify_domain']) { | ||||
|             $parseUrl = parse_url($notifyUrl); | ||||
|             $notifyUrl = $this->config['notify_domain'] . $parseUrl['path']; | ||||
|         } | ||||
|  | ||||
|         return $this->payment->pay([ | ||||
|             'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"), | ||||
|             'notify_url' => $notifyUrl, | ||||
|             'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'], | ||||
|             'trade_no' => $order['trade_no'], | ||||
|             'total_amount' => $order['total_amount'], | ||||
|   | ||||
		Reference in New Issue
	
	Block a user