Explorar o código

修改支付方式

llp hai 4 días
pai
achega
955c829a1b
Modificáronse 1 ficheiros con 41 adicións e 1 borrados
  1. 41 1
      packages/Longyi/Pay/Applepay/src/Payment/Applepay.php

+ 41 - 1
packages/Longyi/Pay/Applepay/src/Payment/Applepay.php

@@ -73,7 +73,7 @@ class Applepay extends Payment
     {
         $billingAddressLines = $this->getAddressLines($order->billing_address->address);
         $data = [
-            'intent' => 'AUTHORIZE',
+            'intent' => 'CAPTURE',
             'purchase_units' => [
                 [
                     'reference_id' => $override['merchantOrderId'],
@@ -143,6 +143,46 @@ class Applepay extends Payment
         $resultObject = json_decode($responseBody);
         return $resultObject->id;
     }
+    public function captureAndVerify($order, $transactionId)
+    {
+        if ($order->status != Order::STATUS_PENDING) {
+            return new \Exception('order status is error');
+        }
+        $additional = $order->payment->additional;
+        $token = $additional['gateway_order_id'];
+        if ($transactionId != $token) {
+            return new \Exception('order token is error');
+        }
+        return $this->capturePayment($token);
+    }
+    public function capturePayment($id)
+    {
+        $data = [];
+        $client = new Client();
+        $response = $client->request('POST', str_replace('{id}', $id, $this->captureOrderApi), [
+            'headers' => [
+                'Accept' => 'application/json',
+                'Content-Type' => 'application/json',
+                'Authorization' =>  'Basic '.base64_encode("{$this->clientId}:{$this->apikey}")
+            ],
+            'json' => $data,
+            'timeout' => 30,
+            'verify' => false
+        ]);
+        $responseBody = $response->getBody()->getContents();
+        Log::channel('payment')->info('appleypay capturePayment response', [
+            'order_id'  => $order->increment_id ?? null,
+            'status'    => $response->getStatusCode(),
+            'body'      => json_decode($responseBody, true),
+            'data'      => $data
+        ]);
+        $resultObject = json_decode($responseBody);
+        if ($resultObject->purchase_units[0]->payments->captures[0]->status == 'COMPLETED') {
+            return ['transaction_id' => $resultObject->id];
+        } else {
+            throw new \Exception("applepay capture is error");
+        }
+    }
     /**
      * Return cart items.
      *