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
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();