Using this library you can integrate ShurjoPay payment gateway into your PHP applications.
If you face any problem then create issues or make a PR with your solution.
- PHP 7.3 or Later
- curl extension
The installation is pretty easy using Composer
composer require raziul/shurjopay-php
You can check the examples directory for full code.
$config = [
// set this to false if you are running in live mode
'sandbox_mode' => true,
// ShurjoPay credentials [Change these with your details]
'username' => 'sp_sandbox',
'password' => 'pyyk97hu&6u6',
'prefix' => 'NOK',
];
require __DIR__ . '/vendor/autoload.php';
// create ShurjoPay instance
$sp = new \Raziul\ShurjoPay\ShurjoPay($config);
// set callback url
$sp->setCallbackUrl($success_url, $cancel_url);
// make payment
$sp->makePayment($payload); // it will redirect to the payment page
You can also use method chaining like below
ShurjoPay::create($config)->setCallbackUrl($success_url, $cancel_url)->makePayment($payload);
After making a successfull payment, user will be redirected to the success_url with
order_id
query parameter in the URI.
// retrieve order id from the URI
$order_id = $_GET['order_id'];
// verify payment
$payment = $sp->verify($order_id);
// check success status
if ($payment->success()) {
// show the payment method
echo $payment->paymentMethod();
}
Available methods in the Payment class.
Method | Description |
---|---|
$payment->success() | Return payment success status |
$payment->failed() | Return payment failed status |
$payment->message() | Get the success/error message |
$payment->orderId() | Get the order ID |
$payment->currency() | Get currency code |
$payment->amount() | Get the amount |
$payment->customerOrderId() | Get customer order ID |
$payment->paymentMethod() | Get the payment method name |
$payment->dateTime() | Get the transaction date time |
$payment->toArray() | Get all the data as array |
This package throws Raziul\ShurjoPay\ShurjoPayException
on error. You can use try-catch
for better error handling.
try {
// making payment
ShurjoPay::create($config)
->setCallbackUrl($success_url, $cancel_url)
->makePayment($payload);
// also for verfication
ShurjoPay::create($config)
->verify($order_id);
} catch (Raziul\ShurjoPay\ShurjoPayException $e) {
echo $e->getMessage();
}
If you found any issues or have any suggestion then please create an issue.
You can also submit PR regarding any issues.
The MIT License (MIT). Please see License File for more information.
Thanks for using this package and If you foound this package useful then consider giving it a star.