PHP code example of jack-walter-smith / bepaid-laravel

1. Go to this page and download the library: Download jack-walter-smith/bepaid-laravel 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/ */

    

jack-walter-smith / bepaid-laravel example snippets




namespace App\Services;

use JackWalterSmith\BePaidLaravel\Refund;

class PaymentService 
{
    /** @var Refund */
    private $refund;

    public function __construct(Refund $refund) {
        $this->refund = $refund;
    }

    public function refund()
    {
        // Create new DTO
        $refundDto = new \JackWalterSmith\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 JackWalterSmith\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
    }
}