File: /home/armgroup/libs/app/Http/Livewire/Account/Wallet/Create.php
<?php
namespace App\Http\Livewire\Account\Wallet;
use App\Http\Livewire\ConvertEmptyStringsToNull;
use App\Http\Livewire\General;
use App\Models\Payment;
use App\Models\Wallet;
use Livewire\Component;
use Shetabit\Multipay\Invoice;
use Shetabit\Payment\Facade\Payment as shetabitPayment;
class Create extends Component
{
use ConvertEmptyStringsToNull, General;
public $amount;
public $action;
public $method;
public $inputs = [];
protected function rules()
{
return [
'amount' => ['required', 'integer', 'min:1000', 'max:1000000000'],
];
}
public function render()
{
return view('livewire.account.wallet.create');
}
public function store()
{
$this->validate();
$payment = Payment::create([
'user_id' => auth()->id(),
'amount' => $this->amount,
'ip' => request()->ip(),
'paymentable_type' => Wallet::class,
]);
try {
$data = json_decode(shetabitPayment::callbackUrl(route('verify.wallet', $payment->id))->purchase(
(new Invoice)->amount($this->amount),
function ($driver, $transactionId) use ($payment) {
$payment->update([
'transaction_id' => $transactionId,
'driver' => config('payment.default'), // اگر چند درگاه داشته باشد میتوانیم با via مشخص کنیم و مقدار را اینجا هم بزاریم
]);
}
)->pay()->toJson());
$this->action = $data->action;
$this->method = $data->method;
$this->inputs = (array) $data->inputs;
$this->dispatchBrowserEvent('submit-payment-form');
} catch (\Exception $exception) {
$payment->update([
'error_message' => $exception->getMessage(),
]);
$this->doneMessage($exception->getMessage(), 'error');
return redirect()->route('account.wallets.create');
}
}
}