PHP code example of kayintveen / laravel-paynl

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

    

kayintveen / laravel-paynl example snippets


use Kayintveen\LaravelPayNL\Facades\PayNL;

$transaction = PayNL::startTransaction([
    'amount' => 10.00,
    'returnUrl' => route('payment.return'),
    'exchangeUrl' => route('payment.webhook'),
    'description' => 'Order #12345',
    'enduser' => [
        'emailAddress' => '[email protected]',
        'initials' => 'J',
        'lastName' => 'Doe',
    ],
]);

// Redirect to payment URL
return redirect($transaction->getRedirectUrl());

$transaction = PayNL::getTransaction('1234567890X12ab34');

echo $transaction->isPaid() ? 'Paid' : 'Not paid';

$status = PayNL::getTransactionStatus('1234567890X12ab34');

if ($status->isPaid()) {
    // Payment successful
}

// Full refund
$refund = PayNL::refundTransaction('1234567890X12ab34');

// Partial refund (amount in cents)
$refund = PayNL::refundTransaction(
    transactionId: '1234567890X12ab34',
    amount: 500, // €5.00
    description: 'Partial refund for order #12345'
);

$paymentMethods = PayNL::getPaymentMethods();

foreach ($paymentMethods as $method) {
    echo $method['name'];
}

// Approve a transaction
PayNL::approveTransaction('1234567890X12ab34');

// Decline a transaction
PayNL::declineTransaction('1234567890X12ab34');

// Void a transaction
PayNL::voidTransaction('1234567890X12ab34');

// Capture a transaction
PayNL::captureTransaction('1234567890X12ab34');

$qr = PayNL::getQrCode('1234567890X12ab34');

echo $qr->getQrUrl(); // URL to QR code image

use Kayintveen\LaravelPayNL\PayNL;

class PaymentController extends Controller
{
    public function __construct(
        protected PayNL $payNL
    ) {}

    public function createPayment()
    {
        $transaction = $this->payNL->startTransaction([
            'amount' => 10.00,
            // ...
        ]);

        return redirect($transaction->getRedirectUrl());
    }
}

use Kayintveen\LaravelPayNL\Exceptions\PayNLException;

try {
    $transaction = PayNL::startTransaction($options);
} catch (PayNLException $e) {
    Log::error('Payment failed: ' . $e->getMessage());

    return back()->with('error', 'Payment could not be processed');
}
bash
php artisan vendor:publish --tag=paynl-config