test
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('visa_master_payment_order_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('visa_master_payment_order_id')->constrained('visa_master_payment_orders')->nullOnDelete();
|
||||
$table->foreignId('online_payment_history_id')->nullable()->constrained('online_payment_histories')->nullOnDelete();
|
||||
|
||||
$table->string('payer_name')->nullable();
|
||||
$table->string('payer_card')->nullable();
|
||||
|
||||
$table->string('payment_order_number')->nullable();
|
||||
|
||||
$table->string('tmt_payment_amount');
|
||||
$table->string('usd_payment_amount');
|
||||
$table->boolean('paid')->default(false);
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('visa_master_payment_order_items');
|
||||
}
|
||||
};
|
||||
@@ -8,6 +8,7 @@ use App\Repos\Order\Loan\LoanOrderRepo;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
@@ -89,6 +90,14 @@ class VisaMasterPaymentOrder extends Model implements HasMedia
|
||||
return $this->belongsTo(Branch::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment itmes
|
||||
*/
|
||||
public function paymentItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(VisaMasterPaymentOrderItem::class, 'visa_master_payment_order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get applications types
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\VisaMasterPaymentOrder\Models;
|
||||
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Models\User;
|
||||
use App\Repos\Order\Loan\LoanOrderRepo;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
class VisaMasterPaymentOrderItem extends Model implements HasMedia
|
||||
{
|
||||
use InteractsWithMedia;
|
||||
|
||||
/**
|
||||
* Table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'visa_master_payment_order_items';
|
||||
|
||||
/**
|
||||
* Guarded attributes
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Parent order
|
||||
*/
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(VisaMasterPaymentOrder::class, 'visa_master_payment_order_id');
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Nova\Fields\Badge;
|
||||
use Laravel\Nova\Fields\HasMany;
|
||||
use Laravel\Nova\Fields\Hidden;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
@@ -342,6 +343,8 @@ class NovaVisaMasterPaymentOrder extends Resource
|
||||
'sender_passport_local_old_replacement'
|
||||
),
|
||||
]),
|
||||
|
||||
// HasMany::make(__('Payment items'), 'paymentItems', ),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -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