PHP code example of neputertech / getpay-gateway

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

    

neputertech / getpay-gateway example snippets




use Illuminate\Http\Request;
use NeputerTech\GetpayGateway\Facades\Getpay;

class PaymentController
{
    public function pay(Request $request)
    {
        $refID = 'ORD-'.now()->timestamp; // your unique order reference

        // Redirects to the package's checkout route with all businessName: 'Acme Inc', // optional
            imageUrl: asset('images/logo.png'), // optional
            themeColor: '#2F855A',    // optional (hex)
            orderInfoUi: null         // optional (custom UI payload)
        );
    }
}



use Illuminate\Http\Request;
use NeputerTech\GetpayGateway\Exceptions\GetpayException;
use NeputerTech\GetpayGateway\Facades\Getpay;

class PaymentController
{
    public function callback(Request $request)
    {
        $token = $request->query('token');

        try {
            $status = Getpay::verify($token); // returns the gateway response array

            // Example success check
            if (data_get($status, 'message') === 'SUCCESS') {
                // TODO: mark order as paid using $status
                return redirect()->route('thankyou')->with('status', 'Payment successful');
            }

            return redirect()->route('payments.getpay.failed')
                ->withErrors('Payment not successful.');
        } catch (GetpayException $e) {
            // 4001: Token decoding failed
            // 4002: Invalid token data
            // 4003: Gateway error
            // 4004: Transaction failed
            return redirect()->route('payments.getpay.failed')
                ->withErrors($e->getMessage());
        }
    }

    public function failed()
    {
        return back()->withErrors('Payment cancelled/failed.');
    }
}

// routes/web.php
Route::get('/payments/getpay/callback', [PaymentController::class, 'callback'])
    ->name('payments.getpay.callback');

Route::get('/payments/getpay/failed', [PaymentController::class, 'failed'])
    ->name('payments.getpay.failed');

use Illuminate\Support\Facades\Http;
use NeputerTech\GetpayGateway\Facades\Getpay;

Http::fake([
    config('getpay.base_url').'/merchant-status' => Http::response([
        'message' => 'SUCCESS',
        'id' => 'example-id',
    ], 200),
]);

$result = Getpay::verify(base64_encode(json_encode([
    'id' => 'example-id',
    'oprSecret' => 'secret',
])));

$this->assertSame('SUCCESS', data_get($result, 'message'));
bash
php artisan vendor:publish --provider="NeputerTech\GetpayGateway\GetpayServiceProvider" --tag=getpay-config
bash
php artisan vendor:publish --tag=getpay-views