Refactor as J22j suggested
This commit is contained in:
parent
fd32a4aa97
commit
9e8abe314b
|
@ -28,24 +28,6 @@ use PayPalHttp\HttpException;
|
||||||
class PaymentController extends Controller
|
class PaymentController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public function getTaxPercent(){
|
|
||||||
$tax = Configuration::getValueByKey("SALES_TAX");
|
|
||||||
if ( $tax < 0 ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return $tax;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTaxValue(PaypalProduct $paypalProduct){
|
|
||||||
return $paypalProduct->price*$this->getTaxPercent()/100;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTotalPrice(PaypalProduct $paypalProduct){
|
|
||||||
return $paypalProduct->price+($this->getTaxValue($paypalProduct));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Application|Factory|View
|
* @return Application|Factory|View
|
||||||
*/
|
*/
|
||||||
|
@ -65,9 +47,9 @@ class PaymentController extends Controller
|
||||||
{
|
{
|
||||||
return view('store.checkout')->with([
|
return view('store.checkout')->with([
|
||||||
'product' => $paypalProduct,
|
'product' => $paypalProduct,
|
||||||
'taxvalue' => $this->getTaxValue($paypalProduct),
|
'taxvalue' => $paypalProduct->getTaxValue(),
|
||||||
'taxpercent' => $this->getTaxPercent(),
|
'taxpercent' => $paypalProduct->getTaxPercent(),
|
||||||
'total' => $this->getTotalPrice($paypalProduct)
|
'total' => $paypalProduct->getTotalPrice()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +69,7 @@ class PaymentController extends Controller
|
||||||
"reference_id" => uniqid(),
|
"reference_id" => uniqid(),
|
||||||
"description" => $paypalProduct->description,
|
"description" => $paypalProduct->description,
|
||||||
"amount" => [
|
"amount" => [
|
||||||
"value" => $this->getTotalPrice($paypalProduct),
|
"value" => $paypalProduct->getTotalPrice(),
|
||||||
'currency_code' => strtoupper($paypalProduct->currency_code),
|
'currency_code' => strtoupper($paypalProduct->currency_code),
|
||||||
'breakdown' =>[
|
'breakdown' =>[
|
||||||
'item_total' =>
|
'item_total' =>
|
||||||
|
@ -98,7 +80,7 @@ class PaymentController extends Controller
|
||||||
'tax_total' =>
|
'tax_total' =>
|
||||||
[
|
[
|
||||||
'currency_code' => strtoupper($paypalProduct->currency_code),
|
'currency_code' => strtoupper($paypalProduct->currency_code),
|
||||||
'value' => $this->getTaxValue($paypalProduct),
|
'value' => $paypalProduct->getTaxValue(),
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
@ -197,9 +179,9 @@ class PaymentController extends Controller
|
||||||
'status' => $response->result->status,
|
'status' => $response->result->status,
|
||||||
'amount' => $paypalProduct->quantity,
|
'amount' => $paypalProduct->quantity,
|
||||||
'price' => $paypalProduct->price,
|
'price' => $paypalProduct->price,
|
||||||
'tax_value' => $this->getTaxValue($paypalProduct),
|
'tax_value' => $paypalProduct->getTaxValue(),
|
||||||
'tax_percent' => $this->getTaxPercent(),
|
'tax_percent' => $paypalProduct->getTaxPercent(),
|
||||||
'total_price' => $this->getTotalPrice($paypalProduct),
|
'total_price' => $paypalProduct->getTotalPrice(),
|
||||||
'currency_code' => $paypalProduct->currency_code,
|
'currency_code' => $paypalProduct->currency_code,
|
||||||
'payer' => json_encode($response->result->payer),
|
'payer' => json_encode($response->result->payer),
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Hidehalo\Nanoid\Client;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use NumberFormatter;
|
use NumberFormatter;
|
||||||
use Spatie\Activitylog\Traits\LogsActivity;
|
use Spatie\Activitylog\Traits\LogsActivity;
|
||||||
|
use App\Models\Configuration;
|
||||||
|
|
||||||
class PaypalProduct extends Model
|
class PaypalProduct extends Model
|
||||||
{
|
{
|
||||||
|
@ -48,4 +49,20 @@ class PaypalProduct extends Model
|
||||||
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
||||||
return $formatter->formatCurrency($value, $this->currency_code);
|
return $formatter->formatCurrency($value, $this->currency_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTaxPercent(){
|
||||||
|
$tax = Configuration::getValueByKey("SALES_TAX");
|
||||||
|
if ( $tax < 0 ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return $tax;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTaxValue(){
|
||||||
|
return $this->price*$this->getTaxPercent()/100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTotalPrice(){
|
||||||
|
return $this->price+($this->getTaxValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue