PHP code example of parkwayprojects / laravel-paywithbank3d

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

    

parkwayprojects / laravel-paywithbank3d example snippets


'aliases' => [
    ...
    'PayWithBank3D' => Parkwayprojects\PayWithBank3D\Facades\PayWithBank3DFacade::class,
    ...
]



/*
 * You can place your custom package configuration in here.
 */
return [
    /**
     * Public Key From PayWithBank3D.
     */
    'publicKey' => getenv('PWB3D_PUBLIC_KEY'),

    /**
     * Secret Key From PayWithBank3D.
     */
    'secretKey' => getenv('PWB3D_SECRET_KEY'),

    /**
     * switch to live or test.
     */
    'mode' => getenv('PWB3D_MODE', 'live'),

    /**
     * PayWithBank3D Test Payment URL.
     */
    'testUrl' => getenv('PWB3D_TEST_URL'),

    /**
     * PayWithBank3D Live Payment URL.
     */
    'liveURL' => getenv('PWB3D_LIVE_URL'),
];


// Laravel 5.1.17 and above
Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay'); 

Route::post('/pay', [
    'uses' => 'PaymentController@redirectToGateway',
    'as' => 'pay'
]);

Route::post('/pay2', [
    'uses' => 'PaymentController@PaymentData',
    'as' => 'data'
]);

Route::get('/payment/callback', 'PaymentController@handleGatewayCallback')->name('callback');

// Laravel 5.0
Route::get('payment/callback', [
    'uses' => 'PaymentController@handleGatewayCallback'
]); 



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use PayWithBank3D;

class PaymentController extends Controller
{

    /**
     * Redirect the User to PayWithBank3D Payment Page
     * @return Url
     */
    public function redirectToGateway()
    {
        return PayWithBank3D::setUrl()->redirectNow();
    }

    /**
     * Get The PayWithBank3D Redirect Url
     * @return array
     */
    public function redirectUrl()
    {
        return  PayWithBank3D::getUrl();
    }

    /**
     * Obtain PayWithBank3D payment information
     * @return void
     */
    public function handleGatewayCallback()
    {
        $paymentDetails =  PayWithBank3D::getData();

        dd($paymentDetails);
        // Now you have the payment details,
        // you can then redirect or do whatever you want
    }
}

/**
 *  This fluent method does all the dirty work of sending a POST request with the form data
 *  to PayWithBank3D Api, then it gets the payment Url and redirects the user to PayWithBank3D
 *  Payment Page. I abstracted all of it, so you don't have to worry about that.
 *  Just eat your cookies while coding!
 */
PayWithBank3D::setUrl()->redirectNow();

/**
*  SetUrl can also accept an array instead of a request object and you are good to go, it will be in this format
 */

        $data = [
                    'reference' => time(),
                    'amount'=> 20000,
                    'currencyCode' => 'NGN',
                    'customer' => [
                        'name' => 'Edward Paul',
                        'email' => '[email protected]',
                        'phone' => '08170574789'
                    ],
                    'returnUrl' => route('verify'),
                    'metadata' => [
                        'orderId'=> '1234'
                    ]
                ];
       return PayWithBank3DFacade::setUrl($data)->redirectNow();


/**
 * This fluent method does all the dirty work of verifying that the just concluded transaction was actually valid,
 */
PayWithBank3D::getData();

/**
 * This method gets the return the redirect url in the case your frontend is detached from your backend
 * @returns array
 */
PayWithBank3D::setUrl()->getUrl();

bash
php artisan vendor:publish --provider="Parkwayprojects\PayWithBank3D\PayWithBank3DServiceProvider"
 php
PWB3D_PUBLIC_KEY=****
PWB3D_SECRET_KEY=****
PWB3D_MODE=test
PWB3D_TEST_URL=https://staging.paywithbank3d.com
PWB3D_LIVE_URL=https://paywithbank3d.com