PHP code example of nimah79 / iran-payment

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

    

nimah79 / iran-payment example snippets


   $app->register( Dena\IranPayment\IranPaymentServiceProvider::class);
    

use Dena\IranPayment\IranPayment;

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

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

return $payment->redirect();

use Dena\IranPayment\IranPayment;
use Dena\IranPayment\Exceptions\IranPaymentException;

try {
    $payment = IranPayment::detect()->confirm();
    $trackingCode = $payment->getTrackingCode();
    $statusText = $payment->getTransactionStatusText();
} catch (Dena\IranPayment\Exceptions\IranPaymentException $ex) {
    throw $ex;
}

use Dena\IranPayment\Gateways\AbstractGateway;
use Dena\IranPayment\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="Dena\IranPayment\IranPaymentServiceProvider"
    
bash
    php artisan migrate