PHP code example of tamimiqbal / dgepay-php
1. Go to this page and download the library: Download tamimiqbal/dgepay-php 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/ */
tamimiqbal / dgepay-php example snippets
use DgePay\DgePay;
// Initialize
$dgepay = new DgePay([
'client_id' => 'your_client_id',
'client_secret' => 'your_client_secret',
'client_api_key' => 'your_api_key',
]);
// Create a payment
$orderId = DgePay::generateTransactionId(); // "DG20260317112339128"
$result = $dgepay->initiatePayment([
'amount' => 2499.00,
'description' => 'Pro Plan - 1 Year',
'orderId' => $orderId,
'redirectUrl' => 'https://yoursite.com/payment/callback',
]);
if ($result['success']) {
// Redirect user to DGePay payment page
header('Location: ' . $result['payment_url']);
exit;
}
'providers' => [
DgePay\Laravel\DgePayServiceProvider::class,
],
'aliases' => [
'DgePay' => DgePay\Laravel\Facades\DgePay::class,
],
use DgePay\DgePay;
class PaymentController extends Controller
{
public function __construct(
protected DgePay $dgepay,
) {}
public function initiate(Request $request)
{
$result = $this->dgepay->initiatePayment([
'amount' => 2499.00,
'description' => 'Pro Plan',
'orderId' => DgePay::generateTransactionId(),
'redirectUrl' => route('payment.callback'),
]);
if ($result['success']) {
return redirect()->away($result['payment_url']);
}
return back()->with('error', $result['message']);
}
}
$auth = $dgepay->authenticate();
if ($auth['success']) {
echo $auth['access_token']; // JWT token
}
$result = $dgepay->initiatePayment([
// Required
'amount' => 2499.00, // Payment amount (BDT)
'redirectUrl' => 'https://...', // Where to redirect after payment
'orderId' => 'DG20260317...', // Your unique transaction ID
// Optional
'description' => 'Plan subscription',
'payment_method' => null, // Force: "bKash", "Nagad", etc.
'customer_token' => null, // Returning customer token
'payee_information' => null, // Payee info
'unique_user_reference' => '123', // Your user ID
'meta_data' => [ // Up to 3 custom fields
'custom_field_1' => 'pro',
'custom_field_2' => '[email protected] ',
'custom_field_3' => 'COUPON50',
],
]);
[
'success' => true,
'payment_url' => 'https://checkout.dgepay.net/payment-methods?data=...',
'transaction_id' => 'DG20260317112339128',
]
[
'success' => false,
'message' => 'Error description',
]
// Step 1: Get and fix the raw data
$rawData = str_replace(' ', '+', $_GET['data']);
// Step 2: Decrypt
$decrypted = $dgepay->decryptCallbackData($rawData);
// Step 3: Parse the result
$result = $dgepay->parseCallbackResult($decrypted ?? $_GET);
if ($result['is_success']) {
// Payment successful!
$orderId = $result['unique_txn_id']; // Your order ID
$txnNumber = $result['txn_number']; // DGePay txn number
$method = $result['payment_method']; // "bKash", "Nagad", etc.
// RECOMMENDED: Verify with API before activating
$status = $dgepay->getTransactionStatus($orderId);
if ($status['success'] && $status['data']['status_code'] == 3) {
// Verified! Activate the order.
}
} elseif ($result['is_cancelled']) {
// User cancelled
} else {
// Payment failed
}
[
'status_code' => 3, // 3 = success, 8 = cancelled
'customer_token' => null,
'unique_txn_id' => 'DG20260317112339128', // Your order ID
'payment_method' => 'bKash',
'txn_number' => '46629357', // DGePay txn number
'third_party_txn_number' => 'TR0011ITaWLiz1773746629790', // MFS provider txn
'message' => 'TRANSACTION SUCCESS',
'txn_id' => '42836aac54c4...', // DGePay internal ID
'amount' => 100,
'created_date' => 1773746629, // Unix timestamp
'metadata' => [
'custom_field_1' => 'pro',
'custom_field_2' => '[email protected] ',
'custom_field_3' => 'COUPON50',
],
]
$result = $dgepay->getTransactionStatus('DG20260317112339128');
if ($result['success']) {
$data = $result['data'];
echo $data['status_code']; // "3" = success
echo $data['message']; // "TRANSACTION SUCCESS"
echo $data['txn_number']; // Gateway transaction number
echo $data['payment_method']; // "bKash", "Nagad", etc.
echo $data['amount']; // Payment amount
}
$txnId = DgePay::generateTransactionId(); // "DG20260317112339128"
$txnId = DgePay::generateTransactionId('PAY'); // "PAY20260317112339128"
DgePay::STATUS_SUCCESS; // "3"
DgePay::STATUS_CANCELLED; // "8"
DgePay::isSuccessStatus('3'); // true
DgePay::isCancelledStatus('8'); // true
$encrypted = $dgepay->encryptPayload(['key' => 'value']);
$decrypted = $dgepay->decryptPayload($encrypted);
$signature = $dgepay->generateSignature($data);
$dgepay->setLogger(function (string $level, string $message, array $context) {
error_log("[{$level}] {$message}: " . json_encode($context));
});
$rawData = str_replace(' ', '+', $_GET['data']);
bash
composer bash
php artisan vendor:publish --tag=dgepay-config
dgepay-api/
├── src/
│ ├── DgePay.php # Main SDK class
│ └── Laravel/
│ ├── DgePayServiceProvider.php # Laravel service provider
│ └── Facades/
│ └── DgePay.php # Laravel facade
├── config/
│ └── dgepay.php # Configuration file
├── examples/
│ ├── initiate-payment.php # Plain PHP: initiate payment
│ ├── handle-callback.php # Plain PHP: handle callback
│ ├── check-status.php # Plain PHP: check transaction status
│ └── laravel-controller.php # Laravel: complete controller example
├── tests/
│ ├── SignatureTest.php # Signature generation tests
│ └── CallbackTest.php # Callback handling tests
├── composer.json
├── phpunit.xml
├── LICENSE
├── .gitignore
└── README.md