Adding Tax, beautify
This commit is contained in:
parent
bff97e836d
commit
6797410cb4
|
@ -30,11 +30,15 @@ class PaymentController extends Controller
|
||||||
|
|
||||||
|
|
||||||
public function getTaxPercent(){
|
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){
|
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){
|
public function getTotalPrice(PaypalProduct $paypalProduct){
|
||||||
|
@ -74,7 +78,6 @@ class PaymentController extends Controller
|
||||||
*/
|
*/
|
||||||
public function pay(Request $request, PaypalProduct $paypalProduct)
|
public function pay(Request $request, PaypalProduct $paypalProduct)
|
||||||
{
|
{
|
||||||
$tax = $paypalProduct->price*Configuration::getValueByKey("TAX_IN_PERCENT")/100;
|
|
||||||
$request = new OrdersCreateRequest();
|
$request = new OrdersCreateRequest();
|
||||||
$request->prefer('return=representation');
|
$request->prefer('return=representation');
|
||||||
$request->body = [
|
$request->body = [
|
||||||
|
@ -85,10 +88,21 @@ class PaymentController extends Controller
|
||||||
"description" => $paypalProduct->description,
|
"description" => $paypalProduct->description,
|
||||||
"amount" => [
|
"amount" => [
|
||||||
"value" => $this->getTotalPrice($paypalProduct),
|
"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" => [
|
"application_context" => [
|
||||||
"cancel_url" => route('payment.cancel'),
|
"cancel_url" => route('payment.cancel'),
|
||||||
"return_url" => route('payment.success', ['product' => $paypalProduct->id]),
|
"return_url" => route('payment.success', ['product' => $paypalProduct->id]),
|
||||||
|
|
|
@ -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()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -136,6 +136,14 @@ class ConfigurationSeeder extends Seeder
|
||||||
'type' => 'boolean',
|
'type' => 'boolean',
|
||||||
'description' => 'Charges the first hour worth of credits upon creating a server.'
|
'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'
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue