Adding Tax, beautify

This commit is contained in:
WBLKLeipe 2021-11-05 07:43:57 +01:00
parent bff97e836d
commit 6797410cb4
3 changed files with 28 additions and 41 deletions

View file

@ -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]),

View file

@ -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()
{
}
}

View file

@ -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'
]);
}
}