PHP code example of brightcweb / paypal

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

    

brightcweb / paypal example snippets


use Brightcweb\Paypal\Myclass\BrightCWebPaypalClass;

class YourController extends Controller
{
    protected $BrightCwebPaypalClass;

    public function __construct(BrightCWebPaypalClass $BrightCWebPaypalClass)
    {
        $this->BrightCwebPaypalClass = $BrightCWebPaypalClass;
    }
}

public function checkout(Request $req)
{
    $amount = $req->amount; // Get order or donation amount
    $paymentData = $this->BrightCwebPaypalClass->createPaypalOrder($amount);

    return redirect($paymentData['links'][1]['href']);
}

Route::get('/checkout', [YourController::class, 'checkout'])->name('checkout');

public function successpaypal(Request $request)
{
    $orderId = $request->query('token');
    $payerId = $request->query('PayerID');

    $paymentDetails = $this->BrightCwebPaypalClass->handlePaymentSuccess($orderId, $payerId);

    if ($paymentDetails) {
        // Optionally send notifications or update tables
        return view('vendor.brightcwebpaypal.sucesspaypal', $paymentDetails);
    }

    return view('vendor.brightcwebpaypal.canceled');
}

public function cancelpaypal()
{
    return view('vendor.brightcwebpaypal.canceled');
}

Route::get('/successpaypal', [YourController::class, 'successpaypal'])->name('successpaypal');
Route::get('/cancelpaypal', [YourController::class, 'cancelpaypal'])->name('cancelpaypal');
bash
php artisan vendor:publish --tag=brightpaypalconfig
bash
php artisan migrate
bash
php artisan config:clear
php artisan cache:clear
php artisan config:cache
bash
php artisan config:clear
php artisan cache:clear
php artisan config:cache