Online payment controller sber
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Http\Controllers;
|
|||||||
use App\Http\Requests\OnlinePaymentStoreRequest;
|
use App\Http\Requests\OnlinePaymentStoreRequest;
|
||||||
use App\Models\Payment\OnlinePaymentHistory;
|
use App\Models\Payment\OnlinePaymentHistory;
|
||||||
use App\Repos\Payment\OnlinePaymentRepo;
|
use App\Repos\Payment\OnlinePaymentRepo;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -13,16 +12,9 @@ class OnlinePaymentController extends Controller
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Online payment
|
* Online payment
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(OnlinePaymentStoreRequest $request)
|
||||||
{
|
{
|
||||||
// Validate the order id
|
|
||||||
if (validator($request->all(), ['orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId']])->fails()) {
|
|
||||||
return ['wrong order id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find order from history
|
// Find order from history
|
||||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||||
|
|
||||||
|
|||||||
@@ -31,14 +31,15 @@ class MakeSberPaymentAction extends Action
|
|||||||
public function handle(ActionFields $fields, Collection $models): mixed
|
public function handle(ActionFields $fields, Collection $models): mixed
|
||||||
{
|
{
|
||||||
$usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value');
|
$usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value');
|
||||||
|
$payment_amount = floatval($fields->get('payment_amount'));
|
||||||
|
$usd_payment = $fields->get('usd_payment');
|
||||||
|
|
||||||
if (! $usd_to_tmt || ! property_exists($fields, 'payment_amount') || ! property_exists($fields, 'usd_payment')) {
|
if (! $usd_to_tmt || ! $payment_amount || ! $usd_payment) {
|
||||||
return ActionResponse::danger('Walýuta hasaby girizilmedik, operator bilen habarlaşmagyňyzy haýyş edýärin.');
|
return ActionResponse::danger('Walýuta hasaby girizilmedik, operator bilen habarlaşmagyňyzy haýyş edýärin.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$today = today();
|
$today = today();
|
||||||
$resource = $models->first();
|
$resource = $models->first();
|
||||||
$payment_amount = floatval($fields->payment_amount);
|
|
||||||
|
|
||||||
$hasBeenPaid = false;
|
$hasBeenPaid = false;
|
||||||
$resource->paymentItems->each(function ($item) use (&$hasBeenPaid, $today) {
|
$resource->paymentItems->each(function ($item) use (&$hasBeenPaid, $today) {
|
||||||
@@ -83,7 +84,7 @@ class MakeSberPaymentAction extends Action
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->createPaymentRecord($payment, $resource, $total_amount, $fields->usd_payment);
|
$this->createPaymentRecord($payment, $resource, $total_amount, $usd_payment);
|
||||||
|
|
||||||
return ActionResponse::openInNewTab($payment['url']);
|
return ActionResponse::openInNewTab($payment['url']);
|
||||||
}
|
}
|
||||||
@@ -129,8 +130,10 @@ class MakeSberPaymentAction extends Action
|
|||||||
->fullWidth()
|
->fullWidth()
|
||||||
->readonly()
|
->readonly()
|
||||||
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) {
|
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) {
|
||||||
if (property_exists($formData, 'payment_amount')) {
|
$payment_amount = $formData->get('payment_amount');
|
||||||
$usdValue = number_format($formData->payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
|
|
||||||
|
if ($payment_amount) {
|
||||||
|
$usdValue = number_format($payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
|
||||||
|
|
||||||
$field->setValue($usdValue);
|
$field->setValue($usdValue);
|
||||||
} else {
|
} else {
|
||||||
@@ -140,8 +143,10 @@ class MakeSberPaymentAction extends Action
|
|||||||
|
|
||||||
Hidden::make('usd_payment')
|
Hidden::make('usd_payment')
|
||||||
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) {
|
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) {
|
||||||
if (property_exists($formData, 'payment_amount')) {
|
$payment_amount = $formData->get('payment_amount');
|
||||||
$usdValue = number_format($formData->payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
|
|
||||||
|
if ($payment_amount) {
|
||||||
|
$usdValue = number_format($payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
|
||||||
|
|
||||||
$field->setValue($usdValue);
|
$field->setValue($usdValue);
|
||||||
} else {
|
} else {
|
||||||
@@ -153,9 +158,11 @@ class MakeSberPaymentAction extends Action
|
|||||||
->fullWidth()
|
->fullWidth()
|
||||||
->readonly()
|
->readonly()
|
||||||
->dependsOn('payment_amount', function ($field, $request, $formData) use ($tvebTaxTMT, $bankTax) {
|
->dependsOn('payment_amount', function ($field, $request, $formData) use ($tvebTaxTMT, $bankTax) {
|
||||||
if (property_exists($formData, 'payment_amount')) {
|
$payment_amount = $formData->get('payment_amount');
|
||||||
|
|
||||||
|
if ($payment_amount) {
|
||||||
$field->setValue(
|
$field->setValue(
|
||||||
number_format($formData->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '')
|
number_format($payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '')
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$field->setValue('');
|
$field->setValue('');
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Repos\Payment;
|
namespace App\Repos\Payment;
|
||||||
|
|
||||||
use App\Models\Branch\Branch;
|
|
||||||
use App\Models\Payment\OnlinePaymentHistory;
|
use App\Models\Payment\OnlinePaymentHistory;
|
||||||
use App\Repos\Payment\Sber\HandlesSberPeyments;
|
use App\Repos\Payment\Sber\HandlesSberPeyments;
|
||||||
use App\Repos\Payment\VisaMaster\HandlesVisaMasterPayments;
|
use App\Repos\Payment\VisaMaster\HandlesVisaMasterPayments;
|
||||||
@@ -198,10 +197,6 @@ class OnlinePaymentRepo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Failed payment response
|
* Failed payment response
|
||||||
*
|
|
||||||
* @param $paymentHistory
|
|
||||||
* @param $bank_branch
|
|
||||||
* @param $resource
|
|
||||||
*/
|
*/
|
||||||
public static function failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL)
|
public static function failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user