Browse Source

传递支付方式

chengwl 2 ngày trước cách đây
mục cha
commit
0a9c968e44

+ 6 - 0
packages/Webkul/BagistoApi/src/Dto/PaymentReplayInput.php

@@ -20,6 +20,12 @@ class PaymentReplayInput
     #[SerializedName('orderId')]
     public ?int $orderId = null;
 
+
+    #[Groups(['mutation'])]
+    #[ApiProperty(description: 'Payment method code for replay')]
+    #[SerializedName('paymentMethod')]
+    public ?string $paymentMethod = null;
+
     #[Groups(['mutation'])]
     #[ApiProperty(description: 'Optional override of payment success URL')]
     #[SerializedName('paymentSuccessUrl')]

+ 20 - 0
packages/Webkul/BagistoApi/src/Services/PaymentService.php

@@ -235,6 +235,26 @@ class PaymentService
             throw new OperationFailedException(__('bagistoapi::app.graphql.payment.not-pending', ['status' => $order->status]));
         }
 
+        if ($input->paymentMethod) {
+            if(!$order->payment->method!=$input->paymentMethod){
+
+                $paymentMethodConfig = config('payment_methods.'.$input->paymentMethod);
+                if (! $paymentMethodConfig || ! isset($paymentMethodConfig['class'])) {
+                    throw new OperationFailedException(__('bagistoapi::app.graphql.checkout.invalid-payment-method'));
+                }
+    
+                if (! $order->payment) {
+                    throw new OperationFailedException(__('bagistoapi::app.graphql.checkout.payment-method-required'));
+                }
+                $order->payment->method = $input->paymentMethod;
+                $order->payment->method_title = core()->getConfigData('sales.payment_methods.'.$input->paymentMethod.'.title');
+                $order->payment->save();
+                $order->refresh();
+
+            }
+           
+        }
+
         $gatewayOrderId = $this->createGatewayOrderForOrder($order);
 
         $this->writeGatewayOrderId($order, $gatewayOrderId);