Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreiTelteu/d3656ce689e410b3d3cc7f4a9b395a05 to your computer and use it in GitHub Desktop.
Save AndreiTelteu/d3656ce689e410b3d3cc7f4a9b395a05 to your computer and use it in GitHub Desktop.
Use a custom inline product in bavix/laravel-wallet plugin https://bavix.github.io/laravel-wallet/#/payment

If you want to use bavix/laravel-wallet plugin with a one-time inline defined product, here is how to do it:

  1. 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,
        ];
    }
}
  1. Pay for it
$item = new InlineProduct(price: 10, title: 'Custom order #51', description: 'Custom order');
$user->safePay($item);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment