PHP code example of salamzadeh / pb-payment

1. Go to this page and download the library: Download salamzadeh/pb-payment 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/ */

    

salamzadeh / pb-payment example snippets


   $app->register( Salamzadeh\PBPayment\PBPaymentServiceProvider::class);
    

use Salamzadeh\PBPayment\PBPayment;

// Default gateway
$payment = PBPayment::create();
// Select one of available gateways
$payment = PBPayment::create('sadad');
// Test gateway (Would not work on production environment)
$payment = PBPayment::create('test');
// Or use your own gateway
$payment = PBPayment::create(NewGateway::class);

$payment->setUserId($user->id)
        ->setAmount($data['amount'])
        ->setCallbackUrl(route('bank.callback'))
        ->ready();

return $payment->redirect();

use Salamzadeh\PBPayment\PBPayment;
use Salamzadeh\PBPayment\Exceptions\PBPaymentException;

try {
    $payment = PBPayment::detect()->confirm();
    $trackingCode = $payment->getTrackingCode();
    $statusText = $payment->getTransactionStatusText();
} catch (Salamzadeh\PBPayment\Exceptions\PBPaymentException $ex) {
    throw $ex;
}

use Salamzadeh\PBPayment\Gateways\AbstractGateway;
use Salamzadeh\PBPayment\Gateways\GatewayInterface;

class NewGateway extends AbstractGateway implements GatewayInterface
{
    public function getName(): string
    {
        return 'new-gateway';
    }

    public function initialize(array $parameters = []): self
    {
        parent::initialize($parameters);
    
        return $this;
    }
    
    public function purchase(): void
    {
        // Send Purchase Request

        $reference_number = 'xxxx';

        $this->transactionUpdate([
            'reference_number' => $reference_number,
        ]);
    }

    
    public function purchaseUri(): string
    {
        return 'http://new-gateway.com/token/xxxx';
    }
    
    public function verify(): void
    {
        $this->transactionVerifyPending();
            
        // Send Payment Verify Request

        $tracking_code = 'yyyy';

        $this->transactionSucceed([
            'tracking_code' => $tracking_code
        ]);
    }
}
bash
    php artisan vendor:publish --provider="Salamzadeh\PBPayment\PBPaymentServiceProvider"
    
bash
    php artisan migrate