瀏覽代碼

basically added tax

1day2die 3 年之前
父節點
當前提交
bff97e836d

+ 21 - 2
app/Http/Controllers/Admin/PaymentController.php

@@ -27,6 +27,21 @@ use PayPalHttp\HttpException;
 
 class PaymentController extends Controller
 {
+
+
+    public function getTaxPercent(){
+        return Configuration::getValueByKey("TAX_IN_PERCENT");
+    }
+
+    public function getTaxValue(PaypalProduct $paypalProduct){
+        return $paypalProduct->price*Configuration::getValueByKey("TAX_IN_PERCENT")/100;
+    }
+
+    public function getTotalPrice(PaypalProduct $paypalProduct){
+        return $paypalProduct->price+($this->getTaxValue($paypalProduct));
+    }
+
+
     /**
      * @return Application|Factory|View
      */
@@ -45,7 +60,10 @@ class PaymentController extends Controller
     public function checkOut(Request $request, PaypalProduct $paypalProduct)
     {
         return view('store.checkout')->with([
-            'product' => $paypalProduct
+            'product'      => $paypalProduct,
+            'taxvalue'     => $this->getTaxValue($paypalProduct),
+            'taxpercent'   => $this->getTaxPercent(),
+            'total'        => $this->getTotalPrice($paypalProduct)
         ]);
     }
 
@@ -56,6 +74,7 @@ class PaymentController extends Controller
      */
     public function pay(Request $request, PaypalProduct $paypalProduct)
     {
+        $tax = $paypalProduct->price*Configuration::getValueByKey("TAX_IN_PERCENT")/100;
         $request = new OrdersCreateRequest();
         $request->prefer('return=representation');
         $request->body = [
@@ -65,7 +84,7 @@ class PaymentController extends Controller
                     "reference_id" => uniqid(),
                     "description" => $paypalProduct->description,
                     "amount"       => [
-                        "value"         => $paypalProduct->price,
+                        "value"         => $this->getTotalPrice($paypalProduct),
                         "currency_code" => strtoupper($paypalProduct->currency_code)
                     ]
                 ]

+ 1 - 1
database/migrations/2021_11_04_195244_tax_in_config.php

@@ -18,7 +18,7 @@ class TaxInConfig extends Migration
                 'key'   => 'TAX_IN_PERCENT',
                 'value' => '0',
                 'type'  => 'integer',
-                'description'  => 'This will be added to the Product Price on Checkout',
+                'description'  => 'The %-value of tax that will be added to the product price on checkout',
             )
         );
     }

+ 3 - 3
resources/views/store/checkout.blade.php

@@ -114,8 +114,8 @@
                                             <td>{{$product->formatCurrency()}}</td>
                                         </tr>
                                         <tr>
-                                            <th>Tax (0%)</th>
-                                            <td>0.00</td>
+                                            <th>Tax ({{$taxpercent}}%)</th>
+                                            <td>€{{number_format($taxvalue, 2, '.', '')}}</td>
                                         </tr>
                                         <tr>
                                             <th>Quantity:</th>
@@ -123,7 +123,7 @@
                                         </tr>
                                         <tr>
                                             <th>Total:</th>
-                                            <td>{{$product->formatCurrency()}}</td>
+                                            <td>€{{number_format($total, 2, '.', '')}}</td>
                                         </tr>
                                     </table>
                                 </div>