瀏覽代碼

修改购物车不存在的问题

llp 4 天之前
父節點
當前提交
463423c029

+ 3 - 0
packages/Longyi/Pay/Afterpay/src/Payment/Afterpay.php

@@ -209,6 +209,9 @@ class Afterpay extends Payment
             return false;
         }
         $cart = Cart::getCart();
+        if (! $cart || ! $cart->billing_address) {
+            return false;
+        }
         $billingCountry = $cart->billing_address->country;
         $allowedCountries = ['AU', 'CA', 'NZ', 'GB', 'US'];
         return in_array($billingCountry, $allowedCountries);

+ 3 - 0
packages/Longyi/Pay/Airwallex/src/Payment/Airwallex.php

@@ -237,6 +237,9 @@ class Airwallex extends Payment
             return false;
         }
         $cart = Cart::getCart();
+        if (! $cart || ! $cart->billing_address) {
+            return false;
+        }
         $billingCountry = $cart->billing_address->country;
         $allowedCountries = ['AU', 'CA', 'NZ', 'GB', 'US'];
         return in_array($billingCountry, $allowedCountries);

+ 4 - 1
packages/Longyi/Pay/AwxAfterpay/src/Payment/AwxAfterpay.php

@@ -78,7 +78,7 @@ class AwxAfterpay extends Payment
             'request_id' => $this->createUuid(),
             'amount' => $grandTotal,
             'descriptor' => $this->prefix,
-            'return_url' => $this->getBaseUlr() . '/klarna/standard/return?orderId=' . $override['merchantOrderId'],
+            'return_url' => $this->getBaseUlr() . '/afterpay/standard/return?orderId=' . $override['merchantOrderId'],
             'merchant_order_id' => $this->prefix . $override['merchantOrderId'],
             'currency' => $order->order_currency_code,
             'customer' => [
@@ -289,6 +289,9 @@ class AwxAfterpay extends Payment
             return false;
         }
         $cart = Cart::getCart();
+        if (! $cart || ! $cart->billing_address) {
+            return false;
+        }
         $billingCountry = $cart->billing_address->country;
         $allowedCountries = ['AU', 'CA', 'NZ', 'GB', 'US'];
         return in_array($billingCountry, $allowedCountries);

+ 3 - 0
packages/Longyi/Pay/AwxKlarna/src/Payment/AwxKlarna.php

@@ -297,6 +297,9 @@ class AwxKlarna extends Payment
             return false;
         }
         $cart = Cart::getCart();
+        if (! $cart || ! $cart->billing_address) {
+            return false;
+        }
         $billingCountry = $cart->billing_address->country;
         $allowedCountries = ['AU', 'AT', 'BE', 'CA', 'CZ', 'DK', 'FI', 'FR', 'DE', 'GR', 'IE',
             'IT', 'NL', 'NO', 'PL', 'PT', 'ES', 'SE', 'CH', 'GB', 'US'

+ 4 - 0
packages/Webkul/BagistoApi/src/State/PaymentMethodsProvider.php

@@ -9,6 +9,7 @@ use Webkul\BagistoApi\Dto\PaymentMethodOutput;
 use Webkul\BagistoApi\Exception\ResourceNotFoundException;
 use Webkul\BagistoApi\Facades\CartTokenFacade;
 use Webkul\BagistoApi\Facades\TokenHeaderFacade;
+use Webkul\Checkout\Facades\Cart;
 use Webkul\Payment\Facades\Payment;
 
 /**
@@ -38,6 +39,9 @@ class PaymentMethodsProvider implements ProviderInterface
             throw new ResourceNotFoundException(__('bagistoapi::app.graphql.cart.invalid-token'));
         }
 
+        // 将 API 上下文中的购物车设置到 Cart 门面,使 isAvailable() 能获取到购物车信息
+        Cart::setCart($cart);
+
         $methods = Payment::getSupportedPaymentMethods();
 
         if ($methods && is_array($methods) && isset($methods['payment_methods'])) {