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);
// קבלת טוכנים שמורים של המשתמש
$tokens = auth()->user()->paymentTokens()->active()->get();
// תשלום עם טוכן
$payment = Payment::useToken($tokenId)
->amount(99.99)
->cvv('123') // נדרש לאימות 3D
->description('תשלום חוזר')
->create();
// תוצאה: תשלום מיידי או הפנייה ל-3D Secure
if ($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();