From 6797410cb42927dfa6935c55dc335055316f2c0f Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Fri, 5 Nov 2021 07:43:57 +0100 Subject: [PATCH] Adding Tax, beautify --- .../Controllers/Admin/PaymentController.php | 26 ++++++++++---- .../2021_11_04_195244_tax_in_config.php | 35 ------------------- .../seeders/Seeds/ConfigurationSeeder.php | 8 +++++ 3 files changed, 28 insertions(+), 41 deletions(-) delete mode 100644 database/migrations/2021_11_04_195244_tax_in_config.php diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index 9538e668..dfe7108e 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/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]), diff --git a/database/migrations/2021_11_04_195244_tax_in_config.php b/database/migrations/2021_11_04_195244_tax_in_config.php deleted file mode 100644 index c5aa7a8a..00000000 --- a/database/migrations/2021_11_04_195244_tax_in_config.php +++ /dev/null @@ -1,35 +0,0 @@ -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() - { - - } -} diff --git a/database/seeders/Seeds/ConfigurationSeeder.php b/database/seeders/Seeds/ConfigurationSeeder.php index cce8c991..98d3a57a 100644 --- a/database/seeders/Seeds/ConfigurationSeeder.php +++ b/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' + ]); } }