basically added tax

This commit is contained in:
1day2die 2021-11-04 21:42:17 +01:00
parent 4c4d64f30f
commit bff97e836d
3 changed files with 25 additions and 6 deletions

View file

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

View file

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

View file

@ -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>