If you want to use bavix/laravel-wallet plugin with a one-time inline defined product, here is how to do it:
- Create a fake model for it
app/Models/InlineProduct.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Bavix\Wallet\Interfaces\ProductInterface;
use Bavix\Wallet\Traits\HasWalletFloat;
class InlineProduct extends Model implements ProductInterface {
use HasWalletFloat;
public $id = 0;
public function __construct(public $price, public $title, public $description) {}
public function getKey() { return 0; }
public function getAmountProduct($customer): int|string {
return number_format($this->price, 2, '.', '');
}
public function getMetaProduct(): ?array {
return [
'title' => $this->title,
'description' => $this->description,
];
}
}
- Pay for it
$item = new InlineProduct(price: 10, title: 'Custom order #51', description: 'Custom order');
$user->safePay($item);