浏览代码

Adding Tax, beautify

WBLKLeipe 3 年之前
父节点
当前提交
6797410cb4

+ 20 - 6
app/Http/Controllers/Admin/PaymentController.php

@@ -30,11 +30,15 @@ class PaymentController extends Controller
 
 
     public function getTaxPercent(){
-        return Configuration::getValueByKey("TAX_IN_PERCENT");
+        $tax = Configuration::getValueByKey("SALES_TAX");
+        if ( $tax < 0 ) {
+            return 0;
+        }
+        return $tax;
     }
 
     public function getTaxValue(PaypalProduct $paypalProduct){
-        return $paypalProduct->price*Configuration::getValueByKey("TAX_IN_PERCENT")/100;
+        return $paypalProduct->price*$this->getTaxPercent()/100;
     }
 
     public function getTotalPrice(PaypalProduct $paypalProduct){
@@ -74,7 +78,6 @@ 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 = [
@@ -85,10 +88,21 @@ class PaymentController extends Controller
                     "description" => $paypalProduct->description,
                     "amount"       => [
                         "value"         => $this->getTotalPrice($paypalProduct),
-                        "currency_code" => strtoupper($paypalProduct->currency_code)
+                        'currency_code' => strtoupper($paypalProduct->currency_code),
+                        'breakdown' =>[
+                            'item_total' =>
+                               [
+                                    'currency_code' => strtoupper($paypalProduct->currency_code),
+                                    'value' => $paypalProduct->price,
+                                ],
+                            'tax_total' =>
+                                [
+                                    'currency_code' => strtoupper($paypalProduct->currency_code),
+                                    'value' => $this->getTaxValue($paypalProduct),
+                                ]
+                        ]
                     ]
-                ]
-            ],
+                ],
             "application_context" => [
                 "cancel_url" => route('payment.cancel'),
                 "return_url" => route('payment.success', ['product' => $paypalProduct->id]),

+ 0 - 35
database/migrations/2021_11_04_195244_tax_in_config.php

@@ -1,35 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-class TaxInConfig extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        DB::table('configurations')->insert(
-            array(
-                'key'   => 'TAX_IN_PERCENT',
-                'value' => '0',
-                'type'  => 'integer',
-                'description'  => 'The %-value of tax that will be added to the product price on checkout',
-            )
-        );
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-
-    }
-}

+ 8 - 0
database/seeders/Seeds/ConfigurationSeeder.php

@@ -136,6 +136,14 @@ class ConfigurationSeeder extends Seeder
             'type'        => 'boolean',
             'description' => 'Charges the first hour worth of credits upon creating a server.'
         ]);
+        //sales tax
+        Configuration::firstOrCreate([
+            'key'   => 'SALES_TAX',
+        ], [
+            'value' => '0',
+            'type'  => 'integer',
+            'description'  => 'The %-value of tax that will be added to the product price on checkout'
+        ]);
 
     }
 }