PHP code example of axcherednikov / laravel-bepaid
1. Go to this page and download the library: Download axcherednikov/laravel-bepaid 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/ */
axcherednikov / laravel-bepaid example snippets
namespace App\Services;
use Excent\BePaidLaravel\Refund;
class PaymentService
{
public function __construct(private Refund $refund)
{
}
public function refund()
{
// Create new DTO
$refundDto = new \Excent\BePaidLaravel\Dtos\RefundDto([
'reason' => 'Purchase returns',
'parent_uid' => 'payment_uid',
'money' => [
'amount' => 333.33,
],
]);
$response = $this->refund
->fill($refundDto)
->submit();
// OR even shorter
// $response = $this->refund->submit($refundDto);
// ... process the $response
}
}
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
//
];
/**
* The subscriber classes to register.
*
* @var array
*/
protected $subscribe = [
'App\Listeners\PaymentNotificationEventSubscriber',
];
}
namespace App\Listeners;
use Excent\BePaidLaravel\Contracts\BePaidSubscriber;
use Illuminate\Http\Request;
class PaymentNotificationEventSubscriber extends BePaidSubscriber
{
public function onNotificationSuccess(Request $request)
{
// ... process the request
}
public function onNotificationFail(Request $request)
{
// ... process the request
}
public function onSuccess(Request $request)
{
// ... process the request
}
public function onFail(Request $request)
{
// ... process the request
}
public function onReturn(Request $request)
{
// ... process the request
}
public function onCancel(Request $request)
{
// ... process the request
}
public function onDecline(Request $request)
{
// ... process the request
}
}