李帅

1.打印paypal token

...@@ -14,6 +14,7 @@ use App\Models\User; ...@@ -14,6 +14,7 @@ use App\Models\User;
14 use App\Models\UserProfile; 14 use App\Models\UserProfile;
15 use Carbon\Carbon; 15 use Carbon\Carbon;
16 use GuzzleHttp\Client; 16 use GuzzleHttp\Client;
17 +use Illuminate\Support\Facades\Log;
17 use Illuminate\Support\Facades\Redis; 18 use Illuminate\Support\Facades\Redis;
18 19
19 class PaypalPayment implements PaymentInterface 20 class PaypalPayment implements PaymentInterface
...@@ -34,6 +35,7 @@ class PaypalPayment implements PaymentInterface ...@@ -34,6 +35,7 @@ class PaypalPayment implements PaymentInterface
34 35
35 public function __construct() 36 public function __construct()
36 { 37 {
38 + try{
37 // 初始化时做一些准备工作 39 // 初始化时做一些准备工作
38 $redis = Redis::connection(); 40 $redis = Redis::connection();
39 $access_token = $redis->get('paypal:access_token'); 41 $access_token = $redis->get('paypal:access_token');
...@@ -47,7 +49,6 @@ class PaypalPayment implements PaymentInterface ...@@ -47,7 +49,6 @@ class PaypalPayment implements PaymentInterface
47 'Accept'=>'application/json', 49 'Accept'=>'application/json',
48 ] 50 ]
49 ]); 51 ]);
50 -
51 $response = $client->post('/v1/oauth2/token',[ 52 $response = $client->post('/v1/oauth2/token',[
52 'form_params'=>['grant_type' => 'client_credentials'], 53 'form_params'=>['grant_type' => 'client_credentials'],
53 'auth' => [$this->clientId, $this->secret], 54 'auth' => [$this->clientId, $this->secret],
...@@ -58,6 +59,9 @@ class PaypalPayment implements PaymentInterface ...@@ -58,6 +59,9 @@ class PaypalPayment implements PaymentInterface
58 59
59 $redis->setex('paypal:access_token',$content['expires_in'],$content['access_token']); 60 $redis->setex('paypal:access_token',$content['expires_in'],$content['access_token']);
60 } 61 }
62 + }catch (\Exception $exception){
63 + Log::channel('daily')->error($exception->getMessage());
64 + }
61 } 65 }
62 66
63 /** 67 /**
...@@ -98,7 +102,7 @@ class PaypalPayment implements PaymentInterface ...@@ -98,7 +102,7 @@ class PaypalPayment implements PaymentInterface
98 } 102 }
99 103
100 public function prepare(Order $order) 104 public function prepare(Order $order)
101 - {return $this->accessToken; 105 + {
102 // 在PayPal上创建一个订单,它会返回一个订单对象,它有一个订单id 106 // 在PayPal上创建一个订单,它会返回一个订单对象,它有一个订单id
103 $client = new Client([ 107 $client = new Client([
104 'base_uri' => $this->baseUrlSandbox, 108 'base_uri' => $this->baseUrlSandbox,
......