test
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Nova\Actions;
|
||||
use App\Models\CurrencyRate;
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
|
||||
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
|
||||
use App\Modules\VisaMasterSettings\Models\VisaMasterSettings;
|
||||
use App\Repos\Payment\OnlinePaymentRepo;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@@ -17,6 +18,7 @@ use Laravel\Nova\Actions\Action;
|
||||
use Laravel\Nova\Actions\ActionResponse;
|
||||
use Laravel\Nova\Fields\ActionFields;
|
||||
use Laravel\Nova\Fields\Heading;
|
||||
use Laravel\Nova\Fields\Hidden;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
|
||||
@@ -41,12 +43,6 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
*/
|
||||
public function handle(ActionFields $fields, Collection $models)
|
||||
{
|
||||
$usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value');
|
||||
|
||||
if (! $usd_to_tmt) {
|
||||
return ActionResponse::danger('Walýuta hasaby girizilmedik, operator bilen habarlaşmagyňyzy haýyş edýärin.');
|
||||
}
|
||||
|
||||
$resource = $models->first();
|
||||
|
||||
if (! $resource->branch || ! $resource->branch->billing_visa_master_username) {
|
||||
@@ -57,9 +53,13 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
|
||||
$payment = $this->order($resource, $total_amount);
|
||||
|
||||
return $payment['status'] === 'success'
|
||||
? ActionResponse::openInNewTab($payment['url'])
|
||||
: ActionResponse::danger('Töleg ýerinde näsazlyk!');
|
||||
if ($payment['status'] !== 'success') {
|
||||
return ActionResponse::danger('Töleg ýerinde näsazlyk!');
|
||||
}
|
||||
|
||||
$this->createPaymentRecord($payment, $resource, $total_amount, $fields->usd_payment);
|
||||
|
||||
return ActionResponse::openInNewTab($payment['url']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +87,11 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">GBÜS tutumy: 3 TMT</h3>
|
||||
HTML))->asHtml(),
|
||||
|
||||
Text::make(__('Töleg aý'), 'month')
|
||||
->fullWidth()
|
||||
->readonly()
|
||||
->default(today()->translatedFormat('F')),
|
||||
|
||||
Text::make(sprintf('%s (%s)', __('Töleg möçberi'), __('TMT')), 'payment_amount')
|
||||
->fullWidth()
|
||||
->required()
|
||||
@@ -104,6 +109,15 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
}
|
||||
}),
|
||||
|
||||
Hidden::make('usd_payment')
|
||||
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_tmt) {
|
||||
if ($formData->payment_amount) {
|
||||
$field->setValue(number_format($formData->payment_amount / $usd_to_tmt->value, 2, '.', ''));
|
||||
} else {
|
||||
$field->setValue('');
|
||||
}
|
||||
}),
|
||||
|
||||
Text::make(__('Jemi (TMT)'), 'total_amount')
|
||||
->fullWidth()
|
||||
->readonly()
|
||||
@@ -163,7 +177,7 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
];
|
||||
}
|
||||
|
||||
OnlinePaymentHistory::create([
|
||||
$onlinePaymentHistory = OnlinePaymentHistory::create([
|
||||
'online_paymantable_id' => $resource->id,
|
||||
'online_paymantable_type' => VisaMasterPaymentOrder::class,
|
||||
'amount' => number_format($amount, 2, '', ''),
|
||||
@@ -181,6 +195,26 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
return [
|
||||
'status' => 'success',
|
||||
'url' => $paymentResponse['formUrl'],
|
||||
'order_id' => $paymentResponse['orderId'],
|
||||
'order_number' => $orderNumber,
|
||||
'online_payment_history_id' => $onlinePaymentHistory->id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create payment record
|
||||
*
|
||||
* @param $payment
|
||||
* @param $resource
|
||||
*/
|
||||
public function createPaymentRecord($payment, $resource, $total_amount, $usd_payment)
|
||||
{
|
||||
VisaMasterPaymentOrderItem::create([
|
||||
'visa_master_payment_order_id' => $resource->id,
|
||||
'online_payment_history_id' => $payment['online_payment_history_id'],
|
||||
'payment_order_number' => $payment['order_number'],
|
||||
'tmt_payment_amount' => $total_amount,
|
||||
'usd_payment_amount' => $usd_payment,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user