Skip to content

Instantly share code, notes, and snippets.

@omidgfx
Created September 29, 2019 09:09
Show Gist options
  • Save omidgfx/cb7a9a3fba55fea3df5c11e0b6963d7c to your computer and use it in GitHub Desktop.
Save omidgfx/cb7a9a3fba55fea3df5c11e0b6963d7c to your computer and use it in GitHub Desktop.
Payir Gateway Composer Library Example (PHP)

مثال زیر نمونه‌ی پیاده‌سازی شده‌ی درگاه پرداخت پِی‌آی‌آر توسط کتابخانه‌ی کامپوزر می‌باشد و بدون درنظر گرفتن مسائل امنیتی و پرهیز از تراکنشهای تکراری در نظر گرفته شده است. لطفاً در پیاده سازی درگاه در پروژه‌ی خود، نکات امنیتی را رعایت فرمائید.

<?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();
}
<?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