Browse Source

修改afterpay支付方式

llp 1 day ago
parent
commit
0353433af7
1 changed files with 24 additions and 20 deletions
  1. 24 20
      packages/Longyi/Pay/Afterpay/src/Payment/Afterpay.php

+ 24 - 20
packages/Longyi/Pay/Afterpay/src/Payment/Afterpay.php

@@ -300,29 +300,33 @@ class Afterpay extends Payment
         }
         $countryCode = $order->billing_address->country ?? null;
         $this->resolveCredentials($countryCode);
-        $client = new Client();
-        $response = $client->request('GET', $this->orderStatusUlr . $gatewayOrderId, [
-            'headers' => [
-                'Accept' => 'application/json',
-                'Content-Type' => 'application/json',
-                'Authorization' => 'Basic ' . base64_encode("{$this->clientId}:{$this->apikey}")
-            ],
-            'timeout' => 30,
-            'verify'  => false,
-        ]);
-        $responseBody = $response->getBody()->getContents();
-        Log::channel('payment')->info("{$order->payment->method} fetchOrderStatus response", [
-            'gatewayOrderId' => $gatewayOrderId,
-            'status' => $response->getStatusCode(),
-            'body' => $responseBody
-        ]);
-        $resultObject = json_decode($responseBody);
         $paymentStatus = [];
         $paymentStatus['captures'] = null;
         $paymentStatus['status'] = null;
-        if ($resultObject->status == 'APPROVED' && $resultObject->paymentState == 'CAPTURED') {
-            $paymentStatus['captures'] = true;
-            $paymentStatus['status'] = 'COMPLETED';
+        try {
+            $client = new Client();
+            $response = $client->request('GET', $this->orderStatusUlr . $gatewayOrderId, [
+                'headers' => [
+                    'Accept' => 'application/json',
+                    'Content-Type' => 'application/json',
+                    'Authorization' => 'Basic ' . base64_encode("{$this->clientId}:{$this->apikey}")
+                ],
+                'timeout' => 30,
+                'verify'  => false,
+            ]);
+            $responseBody = $response->getBody()->getContents();
+            Log::channel('payment')->info("{$order->payment->method} fetchOrderStatus response", [
+                'gatewayOrderId' => $gatewayOrderId,
+                'status' => $response->getStatusCode(),
+                'body' => $responseBody
+            ]);
+            $resultObject = json_decode($responseBody);
+            if ($resultObject->status == 'APPROVED' && $resultObject->paymentState == 'CAPTURED') {
+                $paymentStatus['captures'] = true;
+                $paymentStatus['status'] = 'COMPLETED';
+            }
+        } catch (\Exception $e) {
+            Log::channel('payment')->error("{$order->payment->method} fetchOrderStatus error: " . $e->getMessage());
         }
         return $paymentStatus;
     }