PHP code example of algmaal / laravel-fawaterak

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

    

algmaal / laravel-fawaterak example snippets


use Algmaal\LaravelFawaterak\Facades\Fawaterak;

// الحصول على طرق الدفع
$paymentMethods = app(\Algmaal\LaravelFawaterak\Contracts\FawaterakServiceInterface::class)
    ->getPaymentMethods();

foreach ($paymentMethods['data'] as $method) {
    echo $method['name_ar'] . ' - ' . $method['name_en'];
}

use Algmaal\LaravelFawaterak\Facades\Fawaterak;

// بيانات العميل
$customerData = [
    'first_name' => 'محمد',
    'last_name' => 'أحمد',
    'email' => '[email protected]',
    'phone' => '01234567890',
    'address' => 'القاهرة، مصر'
];

// عناصر السلة
$cartItems = [
    [
        'name' => 'منتج تجريبي 1',
        'price' => '100',
        'quantity' => '1'
    ],
    [
        'name' => 'منتج تجريبي 2',
        'price' => '50',
        'quantity' => '2'
    ]
];

// إنشاء الدفعة
$payment = Fawaterak::createPayment(
    $customerData,
    $cartItems,
    200.0, // المجموع
    2, // معرف طريقة الدفع (Visa/Mastercard)
    [
        'currency' => 'EGP',
        'invoice_number' => 'INV-001',
        'redirection_urls' => [
            'successUrl' => 'https://yoursite.com/payment/success',
            'failUrl' => 'https://yoursite.com/payment/failed',
            'pendingUrl' => 'https://yoursite.com/payment/pending'
        ]
    ]
);

// إعادة توجيه العميل لصفحة الدفع
if (isset($payment['data']['payment_data']['redirectTo'])) {
    return redirect($payment['data']['payment_data']['redirectTo']);
}

use Algmaal\LaravelFawaterak\Facades\Fawaterak;

$invoiceKey = 'hyU2vcy3USvT5Tg';

// التحقق من نجاح الدفعة
if (Fawaterak::isPaymentSuccessful($invoiceKey)) {
    echo 'تم الدفع بنجاح!';
} else {
    echo 'الدفعة لم تكتمل بعد';
}

// الحصول على حالة الدفعة
$status = Fawaterak::getPaymentStatus($invoiceKey);
echo "حالة الدفعة: {$status}";

// الحصول على تفاصيل الدفعة كاملة
$paymentDetails = Fawaterak::getPayment($invoiceKey);

// في EventServiceProvider
use Illuminate\Support\Facades\Event;

Event::listen('fawaterak.webhook.received', function ($data) {
    // معالجة عامة لجميع الـ webhooks
    Log::info('Webhook received', $data);
});

Event::listen('fawaterak.payment.paid', function ($data) {
    // معالجة الدفعات المكتملة
    $invoiceKey = $data['invoice_key'];
    // تحديث قاعدة البيانات، إرسال إيميل، إلخ
});

Event::listen('fawaterak.payment.failed', function ($data) {
    // معالجة الدفعات الفاشلة
});

Event::listen('fawaterak.payment.pending', function ($data) {
    // معالجة الدفعات المعلقة
});

$payment = Fawaterak::createPayment($customer, $items, $total, 2);
// سيتم إعادة توجيه العميل لصفحة الدفع

$payment = Fawaterak::createPayment($customer, $items, $total, 3);
// سيحصل العميل على كود Fawry للدفع
$fawryCode = $payment['data']['payment_data']['fawryCode'];

$payment = Fawaterak::createPayment($customer, $items, $total, 4, [
    'mobile_wallet_number' => '01234567890'
]);
// سيحصل العميل على QR Code للدفع
$qrCode = $payment['data']['payment_data']['meezaQrCode'];

$options = [
    'redirection_urls' => [
        'successUrl' => 'https://yoursite.com/payment/success',
        'failUrl' => 'https://yoursite.com/payment/failed',
        'pendingUrl' => 'https://yoursite.com/payment/pending'
    ]
];

$options = [
    'discount_data' => [
        'type' => 'pcg', // أو 'literal'
        'value' => 10 // 10% أو 10 جنيه
    ]
];

$options = [
    'tax_data' => [
        'title' => 'ضريبة القيمة المضافة',
        'value' => 14 // 14%
    ]
];
bash
php artisan vendor:publish --provider="Algmaal\LaravelFawaterak\FawaterakServiceProvider" --tag="fawaterak-config"