PHP code example of fynduck / laravel-maib-ecommerce

1. Go to this page and download the library: Download fynduck/laravel-maib-ecommerce 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/ */

    

fynduck / laravel-maib-ecommerce example snippets


use Fynduck\MaibEcommerce\Facades\Maib;
use Fynduck\MaibEcommerce\Enums\Currency;
use Fynduck\MaibEcommerce\Enums\Language;

$payment = Maib::pay([
    // r 'en' (ro | ru | en)

    // optional
    'description' => 'Order #123',       // max 124 chars
    'clientName' => 'John Doe',          // max 128 chars
    'email' => '[email protected]',
    'phone' => '069123456',              // max 40 chars
    'orderId' => '123',                  // max 36 chars
    'delivery' => 1.25,                  // delivery price
    'items' => [
        ['id' => 'SKU-1', 'name' => 'Product 1', 'price' => 2.50, 'quantity' => 2],
        ['id' => 'SKU-2', 'name' => 'Product 2', 'price' => 4.00, 'quantity' => 1],
    ],
    'callbackUrl' => route('maib.callback'),
    'okUrl' => route('checkout.success'),
    'failUrl' => route('checkout.failed'),
]);

// Persist $payment->payId, then redirect the customer to the maib checkout page:
return redirect()->away($payment->payUrl);

$hold = Maib::hold(['amount' => 10.25, 'currency' => 'MDL', 'clientIp' => $request->ip()]);
// ...later, capture all or part of the held amount:
$captured = Maib::complete(['payId' => $hold->payId, 'confirmAmount' => 10.25]);

$refund = Maib::refund(['payId' => $payId, 'refundAmount' => 10.25]);

$info = Maib::payInfo($payId); // 36-char payId
$info->statusEnum(); // PaymentStatus enum

// Register a card (redirects to checkout); maib returns a billerId on the callback.
$save = Maib::saveRecurring(['billerExpiry' => '1230', 'currency' => 'MDL', 'clientIp' => $ip]);
return redirect()->away($save->payUrl);

// Later, charge the stored card without customer interaction:
$charge = Maib::executeRecurring(['billerId' => $billerId, 'amount' => 6.25, 'currency' => 'MDL']);

// One-click works the same way:
$save = Maib::saveOneclick(['billerExpiry' => '1230', 'currency' => 'MDL', 'clientIp' => $ip]);
$charge = Maib::executeOneclick(['billerId' => $billerId, 'amount' => 6.25, 'currency' => 'MDL', 'clientIp' => $ip]);

// Remove a stored card:
Maib::deleteCard($billerId);

namespace App\Providers;

use App\Listeners\MarkOrderAsPaid;
use Fynduck\MaibEcommerce\Events\PaymentFailed;
use Fynduck\MaibEcommerce\Events\PaymentSucceeded;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        PaymentSucceeded::class => [
            MarkOrderAsPaid::class,
        ],
        PaymentFailed::class => [
            // App\Listeners\NotifyCustomerOfFailure::class,
        ],
    ];
}

namespace App\Listeners;

use Fynduck\MaibEcommerce\Events\PaymentSucceeded;
use Illuminate\Contracts\Queue\ShouldQueue;

class MarkOrderAsPaid implements ShouldQueue
{
    public string $queue = 'payments';

    public function handle(PaymentSucceeded $event): void
    {
        $payId = $event->callback->payId();
        // mark your order as paid, notify the customer, etc.
    }
}
bash
php artisan vendor:publish --tag=maib-config
bash
php artisan vendor:publish --tag=maib-migrations
php artisan migrate