PHP code example of veltix / laravel-montonio

1. Go to this page and download the library: Download veltix/laravel-montonio library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

veltix / laravel-montonio example snippets


use Veltix\LaravelMontonio\Facades\Montonio;

// Payments API
$paymentsClient = Montonio::payments();

// Shipping API
$shippingClient = Montonio::shipping();

// Webhook verifier
$webhookVerifier = Montonio::webhooks();

use Veltix\LaravelMontonio\Models\PaymentMethod;
use Veltix\LaravelMontonio\Models\ShippingMethod;

// Get all active payment methods
$methods = PaymentMethod::active()->get();

// Get all active shipping methods
$methods = ShippingMethod::active()->get();

use Veltix\LaravelMontonio\Services\MethodCacheService;

$cache = app(MethodCacheService::class);

$paymentMethods = $cache->paymentMethods();
$shippingMethods = $cache->shippingMethods();

use Veltix\LaravelMontonio\Events\PaymentWebhookReceived;
use Veltix\LaravelMontonio\Events\ShipmentStatusUpdated;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        PaymentWebhookReceived::class => [
            HandlePaymentWebhook::class,
        ],
        ShipmentStatusUpdated::class => [
            HandleShipmentUpdate::class,
        ],
    ];
}

// config/montonio.php
'webhooks' => [
    'middleware' => ['api', App\Http\Middleware\VerifyIpWhitelist::class],
],

// config/montonio.php
'models' => [
    'payment_method' => App\Models\PaymentMethod::class,
    'shipping_method' => App\Models\ShippingMethod::class,
],

use Veltix\LaravelMontonio\Models\PaymentMethod as BasePaymentMethod;

class PaymentMethod extends BasePaymentMethod
{
    protected $table = 'my_payment_methods';

    public function orders(): HasMany
    {
        return $this->hasMany(Order::class);
    }
}

'models' => [
    'payment_method' => App\Models\PaymentMethod::class,
],

use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

$this->app->bind(ClientInterface::class, fn () => new MyCustomClient());
$this->app->bind(RequestFactoryInterface::class, fn () => new MyRequestFactory());
$this->app->bind(StreamFactoryInterface::class, fn () => new MyStreamFactory());
bash
php artisan montonio:install
bash
php artisan montonio:install --skip-migrations
bash
php artisan migrate
php artisan montonio:sync-methods
bash
php artisan vendor:publish --tag=montonio-config