PHP code example of nmdigitalhub / payment-gateway

1. Go to this page and download the library: Download nmdigitalhub/payment-gateway 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/ */

    

nmdigitalhub / payment-gateway example snippets


use NMDigitalHub\PaymentGateway\Facades\Payment;

// יצירת תשלום בסיסי
$payment = Payment::amount(100)
    ->currency('ILS')
    ->customerEmail('[email protected]')
    ->customerName('יוסי כהן')
    ->description('תשלום עבור מוצר')
    ->create();

// תוצאה: URL לדף התשלום של CardCom
return redirect($payment->checkout_url);

use NMDigitalHub\PaymentGateway\Facades\Payment;

$payment = Payment::amount(250.50)
    ->currency('ILS')
    ->customerEmail('[email protected]')
    ->customerName('רחל לוי')
    ->customerPhone('0501234567')
    ->description('חידוש מנוי שנתי')
    ->savePaymentMethod() // שמירת כרטיס לעתיד
    ->successUrl('https://mysite.com/payment/success')
    ->failedUrl('https://mysite.com/payment/failed')
    ->webhookUrl('https://mysite.com/webhooks/cardcom')
    ->metadata(['order_id' => 123, 'user_id' => 456])
    ->create();

// קבלת טוכנים שמורים של המשתמש
$tokens = auth()->user()->paymentTokens()->active()->get();

// תשלום עם טוכן
$payment = Payment::useToken($tokenId)
    ->amount(99.99)
    ->cvv('123') // נדרש לאימות 3D
    ->description('תשלום חוזר')
    ->create();

// תוצאה: תשלום מיידי או הפנייה ל-3D Secure
if ($payment->

use NMDigitalHub\PaymentGateway\Models\PaymentPage;

$page = PaymentPage::create([
    'title' => 'תשלום עבור קורס',
    'slug' => 'course-payment',
    'description' => 'תשלום מאובטח עבור הקורס שלנו',
    'type' => 'checkout',
    'status' => 'published',
    'is_public' => true,
    'language' => 'he',
    'content' => [
        [
            'type' => 'heading',
            'data' => ['content' => 'תשלום מאובטח', 'level' => 'h1']
        ],
        [
            'type' => 'payment_form',
            'data' => ['allowed_methods' => ['cardcom']]
        ]
    ]
]);

// URL לעמוד התשלום: /payment/course-payment

// routes/web.php
use NMDigitalHub\PaymentGateway\Http\Controllers\CheckoutController;

Route::get('/payment/{slug}', [CheckoutController::class, 'showPaymentPage']);
Route::post('/payment/{slug}', [CheckoutController::class, 'processPayment']);

use NMDigitalHub\PaymentGateway\Services\CardComLowProfileService;

Route::post('/webhooks/cardcom', function (Request $request) {
    $service = app(CardComLowProfileService::class);
    $transaction = $service->handleWebhook($request->all());
    
    if ($transaction && $transaction->status === 'success') {
        // עיבוד הזמנה מוצלחת
        $order = Order::where('reference', $transaction->reference)->first();
        $order->markAsCompleted();
        
        // שליחת מייל אישור
        Mail::to($transaction->customerEmail)
            ->send(new PaymentConfirmationMail($transaction));
    }
    
    return response('OK', 200);
});

use NMDigitalHub\PaymentGateway\Models\PaymentTransaction;

// קבלת עסקאות לפי משתמש
$transactions = PaymentTransaction::where('customer_email', '[email protected]')
    ->whereIn('status', ['success', 'completed'])
    ->orderBy('created_at', 'desc')
    ->get();

// קבלת עסקה לפי מזהה
$transaction = PaymentTransaction::where('transaction_id', 'PAY-123')->first();

// סטטיסטיקות תשלומים
$stats = PaymentTransaction::selectRaw('
    COUNT(*) as total_transactions,
    SUM(CASE WHEN status = "success" THEN amount ELSE 0 END) as total_amount,
    AVG(amount) as average_amount
')->where('created_at', '>=', now()->subMonth())->first();

use App\Models\PaymentToken;

// קבלת טוכנים פעילים של משתמש
$tokens = PaymentToken::where('user_id', auth()->id())
    ->active()
    ->notExpired()
    ->get();

// הגדרת טוכן כברירת מחדל
$token->setAsDefault();

// ביטול טוכן
$token->deactivate();

// config/payment-gateway.php
return [
    'security' => [
        'encryption_key' => env('PAYMENT_GATEWAY_ENCRYPTION_KEY'),
        'hmac_secret' => env('PAYMENT_GATEWAY_HMAC_SECRET'),
        'session_timeout' => 1800, // 30 דקות
        'max_attempts' => 3,
        'lockout_duration' => 900, // 15 דקות
    ],
    
    'logging' => [
        'enabled' => true,
        '

// שימוש ב-cache עבור שאילתות כבדות
$providers = Cache::remember('active_payment_providers', 3600, function () {
    return ServiceProvider::active()->get();
});

// אינדקסים מומלצים במאגר הנתונים
Schema::table('payment_transactions', function (Blueprint $table) {
    $table->index(['customer_email', 'status']);
    $table->index(['status', 'created_at']);
    $table->index(['provider', 'status']);
});
bash
# התקנה בכוח (עריפת הגדרות קיימות)
php artisan payment-gateway:install --force

# התקנה עם נתוני דמו
php artisan payment-gateway:install --demo

# התקנה ללא migrations
php artisan payment-gateway:install --skip-migrations

# התקנה עם אופטימיזציה
php artisan payment-gateway:install --optimize

# פרטי התקנה מלאים
php artisan payment-gateway:install --verbose
bash
# בדיקת חיבור לספקים
php artisan payment-gateway:health-check

# סנכרון קטלוגים
php artisan payment-gateway:sync

# בדיקת ספק
php artisan payment-gateway:test cardcom

# יצירת עמוד תשלום
php artisan payment-gateway:create-page
bash
# ניקוי טוכנים שפגו
php artisan payment-gateway:cleanup-tokens

# ייצוא עסקאות לדוח
php artisan payment-gateway:export --from="2024-01-01" --to="2024-12-31"

# גיבוי נתוני תשלום
php artisan payment-gateway:backup
bash
# בדיקת פרטי החיבור
php artisan payment-gateway:test cardcom

# בדיקת הגדרות
php artisan config:cache
php artisan config:clear
bash
# בדיקת URL פנוי
curl -X POST https://your-domain.com/webhooks/cardcom

# בדיקת הגדרות HMAC
php artisan tinker
>>> config('payment-gateway.security.hmac_secret')
bash
# ניקוי cache של Filament
php artisan filament:cache-components
php artisan filament:optimize
bash
# מידע על החבילה
php artisan payment-gateway:info

# רשימת פקודות זמינות  
php artisan payment-gateway:help

# בדיקת תקינות המערכת
php artisan payment-gateway:doctor