PHP code example of morpheusadam / anypay

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

    

morpheusadam / anypay example snippets


$config = ['driver' => 'gatewayName', 'api_key' => 'your_api_key'];
$anypay = new Morpheusadam\Anypay\Anypay($config);
$invoice = new Morpheusadam\Anypay\Invoice();
$invoice->amount(1000); // مبلغ به ریال
$anypay->via('gatewayName')->purchase($invoice)->pay();

$config = ['api_key' => 'your_api_key'];
$gateway = 'gatewayName';
$amount = 1000; // مبلغ به ریال

try {
    $anypay = new Morpheusadam\Anypay\Anypay($config);
    $response = $anypay->payWith($gateway, $amount, $config);
    echo $response->getContent(); // نمایش جزئیات پاسخ
} catch (Exception $e) {
    echo 'خطا در پرداخت: ' . $e->getMessage();
}


 
try {
$anypay = new Morpheusadam\Anypay\Anypay($config);
$receipt = $anypay->verify();
echo 'پرداخت تایید شد. شماره تراکنش: ' . $receipt->getTransactionId();
} catch (Exception $e) {
echo 'خطا در تایید پرداخت: ' . $e->getMessage();
}



$invoice = (new Invoice)->amount(1000);

 Anypay::via('driverName')->purchase(
    $invoice, 
    function($driver, $transactionId) {
 	}
);