مثال زیر نمونهی پیادهسازی شدهی درگاه پرداخت پِیآیآر توسط کتابخانهی کامپوزر میباشد و بدون درنظر گرفتن مسائل امنیتی و پرهیز از تراکنشهای تکراری در نظر گرفته شده است. لطفاً در پیاده سازی درگاه در پروژهی خود، نکات امنیتی را رعایت فرمائید.
Created
September 29, 2019 09:09
-
-
Save omidgfx/cb7a9a3fba55fea3df5c11e0b6963d7c to your computer and use it in GitHub Desktop.
Payir Gateway Composer Library Example (PHP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php use Omidgfx\Payir; | |
require 'vendor/autoload.php'; | |
$payir = new Payir('API-KEY'); | |
try { | |
$response = $payir->send(100, 'https://site.com/verify?order=123'); | |
if ($response instanceof Payir\ErrorResponse) { | |
echo $response->error(); | |
} elseif ($response instanceof Payir\SendResponse) { | |
$response->redirectToPayLink(); | |
} | |
} catch (Exception $exception) { | |
echo $exception->getMessage(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php use Omidgfx\Payir; | |
require 'vendor/autoload.php'; | |
$payir = new Payir('API-KEY'); | |
$payir->makeCallbackListener() | |
->setOnError(static function (Payir\ErrorResponse $errorResponse) { | |
echo $errorResponse->error(); | |
})->setOnSuccess(static function (Payir\VerifyResponse $verifyResponse) { | |
// check db for transId. | |
// you can access to transId that just got from pay.ir like this: | |
# $verifyResponse->transId; | |
// OK we can sell our stuff here | |
})->setOnException(static function (Exception $exception) { | |
// you can throw this exception or just track it down to fix the issue | |
// throw $exception; | |
echo $exception->getMessage(); | |
})->listen(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment