PHP code example of karim007 / laravel-tap

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

    

karim007 / laravel-tap example snippets


    Route::get('/tap/create-payment', [App\Http\Controllers\TapPaymentController::class,'createPayment'])->name('tap-create-payment');
    Route::get('/tap/callback', [App\Http\Controllers\TapPaymentController::class,'callBack'])->name('tap-callBack');

    public function createPayment(Request $request)
    {
        $inv = uniqid();
        $data['requestorReferenceId'] = $inv;
        $data['amount'] = 10;
        $data['invoiceNumber'] = $inv;
        $data['additionalInformation'] = "Far far away, behind the word mountains";
        $data['callBackUrl'] = config("tap.callbackURL");

        return TapPayment::tPayment($data);
    }

    public function callBack(Request $request)
    {
        if ($request->status == 'completed'){
            $response = TapPayment::validatePayment($request->transactionId);
            //$response = TapPayment::validatePayment($request->transactionId, 1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..
            if (!$response){ //if validatePayment payment not found call checkTransaction
                $response = TapPayment::checkTransaction($request->requestorReferenceId);
                //$response = TapPayment::checkTransaction($request->requestorReferenceId,1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..
            }
            if (isset($response['status']) && $response['status'] == "completed") {
                /*
                 * for future use need to store
                 * transactionId, requestorReferenceId and coreTransactionId
                 * */
                return TapPayment::success('Thank you for your payment', $response['coreTransactionId']);
            }
            return TapPayment::failure($response['statusMessage']);
        }else if ($request->status == 'cancel'){
            return TapPayment::cancel('Your payment is canceled');
        }else{
            return TapPayment::failure('Your transaction is failed');
        }
    }

public function validatePayment($transactionId)
    {
        $response = TapPayment::validatePayment($transactionId);
        //$response = TapPayment::validatePayment($transactionId, 1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..
        return $response;
    }

    public function chkTransaction($requestorReferenceId)
    {
        $response = TapPayment::checkTransaction($requestorReferenceId);
        //$response = TapPayment::checkTransaction($requestorReferenceId, 1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..
        return $response;
    }
bash
php artisan vendor:publish --provider="Karim007\LaravelTap\LaravelTapServiceProvider" --tag="config"


php artisan vendor:publish --provider="Karim007\LaravelTap\TapPaymentController" --tag="controllers"