PHP code example of larevio / persian-providers

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

    

larevio / persian-providers example snippets


payment('zarinpal', ['token' => $merchantId]);
sms('smsir', ['token' => $apiKey, 'line' => $senderLine]);
inquiry('zohal', ['token' => $token]);
exchange('nobitex', ['token' => $token]);

use Larevio\PersianProviders\Enums\Currency;

payment()->amount(150_000, Currency::IRT);   // 150,000 tomans = 1,500,000 rials
payment()->amount(1_500_000, Currency::IRR); // same amount

use Larevio\PersianProviders\Enums\Currency;

$pending = payment('zibal')
    ->amount($order->total_tomans, Currency::IRT)
    ->order($order->id)
    ->description("Order #{$order->id}")
    ->mobile($customer->mobile)
    ->callback(route('payment.callback'))
    ->create();

// Save these before redirecting. Verification uses your stored values, not the callback's.
$order->update(['payment_id' => $pending->id, 'gateway' => 'zibal']);

$pending->redirect(); // Auto-submitting form for POST gateways, otherwise a 302.

$verified = payment($order->gateway)
    ->id($order->payment_id)
    ->amount($order->total_tomans, Currency::IRT)
    ->order($order->id)
    ->extra($request->all())
    ->verify();

if ($verified === false) {
    // The callback says the payment failed or was cancelled. No request was sent.
}

DB::transaction(function () use ($order, $verified) {
    // Fulfil the order once. Verifying again returns $verified->alreadyVerified === true.
});

if ($payment->supportsReverse()) {
    $reversed = $payment->reverse(); // Reverses the full amount.
}

sms('smsir')->to('09120000000')->message('Your order is ready.')->send();

sms('kavenegar')
    ->to('09120000000')
    ->templateId('verify')
    ->sendPattern(['token' => '1234']);

$submission = sms('ghasedak')->sendBatch([
    ['phone' => '09120000000', 'text' => 'Your order is ready.'],
    ['phone' => '09120000001', 'text' => 'Your appointment is tomorrow.'],
]);

$scheduled = sms('kavenegar')
    ->to(['09120000000', '09120000001'])
    ->message('Appointment reminder')
    ->schedule(now()->addHour());

$balance = sms('smsir')->balance();

$matched = inquiry('zohal')->matchMobile($mobile, $nationalCode);
$account = inquiry('zohal')->ibanInquiry($iban);

use Larevio\PersianProviders\Enums\Currency;

$rate = exchange('nobitex')->getRate(Currency::BTC, Currency::IRT);
$rate->last;     // "21513079017.5" tomans per BTC
$rate->bestSell; // lowest ask
$rate->bestBuy;  // highest bid

use Larevio\PersianProviders\Exceptions\PaymentVerificationException;
use Larevio\PersianProviders\Exceptions\ProviderException;
use Larevio\PersianProviders\Exceptions\TransportException;

try {
    $verified = $payment->verify();
} catch (PaymentVerificationException $e) {
    report($e);                 // Mismatch: investigate, and reverse the payment if needed.
} catch (TransportException $e) {
    // Outcome unknown. Call verify again; if it went through, alreadyVerified is true.
} catch (ProviderException $e) {
    $e->providerCode;           // e.g. -51 from Zarinpal
}

Http::fake(['gateway.zibal.ir/*' => Http::response(['result' => 100, 'trackId' => 123])]);