mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	rewrite: payment
This commit is contained in:
		
							
								
								
									
										48
									
								
								app/Services/PaymentService.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								app/Services/PaymentService.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Services; | ||||
|  | ||||
|  | ||||
| use App\Models\Payment; | ||||
|  | ||||
| class PaymentService | ||||
| { | ||||
|     public function __construct($method, $id = NULL) | ||||
|     { | ||||
|         $this->method = $method; | ||||
|         $this->class = '\\App\\Payments\\' . $this->method; | ||||
|         if (!class_exists($this->class)) abort(500, 'gate is not found'); | ||||
|         if ($id) $payment = Payment::find($id)->toArray(); | ||||
|         $this->config = []; | ||||
|         if (isset($payment) && $payment['config']) $this->config = json_decode($payment['config'], true); | ||||
|         $this->payment = new $this->class($this->config); | ||||
|     } | ||||
|  | ||||
|     public function notify($params) | ||||
|     { | ||||
|         if (!$this->config['enable']) abort(500, 'gate is not enable'); | ||||
|         return $this->payment->notify($params); | ||||
|     } | ||||
|  | ||||
|     public function pay($order) | ||||
|     { | ||||
|         return $this->payment->pay([ | ||||
|             'notify_url' => url('/api/v1/guest/payment/notify/' . $this->method), | ||||
|             'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order', | ||||
|             'trade_no' => $order['trade_no'], | ||||
|             'total_amount' => $order['total_amount'], | ||||
|             'user_id' => $order['user_id'], | ||||
|             'stripe_token' => $order['stripe_token'] | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function form() | ||||
|     { | ||||
|         $form = $this->payment->form(); | ||||
|         $keys = array_keys($form); | ||||
|         foreach ($keys as $key) { | ||||
|             if (isset($this->config[$key])) $form[$key]['value'] = $this->config[$key]; | ||||
|         } | ||||
|         return $form; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user