uddoktapay/laravel-sdk
Composer 安装命令:
composer require uddoktapay/laravel-sdk
包简介
UddoktaPay offers a range of payment automation solutions for small entrepreneurs in Bangladesh.
README 文档
README
The UddoktaPay Laravel SDK allows you to seamlessly integrate the UddoktaPay payment gateway into your Laravel applications.
Table of Contents
Installation
Install the UddoktaPay Laravel SDK using Composer:
composer require uddoktapay/laravel-sdk
Usage
Initializing the SDK
Add your UddoktaPay API credentials to the .env file:
UDDOKTAPAY_API_KEY=your_api_key UDDOKTAPAY_API_URL=https://sandbox.uddoktapay.com/api/checkout-v2
Use the following code to initialize the SDK:
use UddoktaPay\LaravelSDK\UddoktaPay; $uddoktapay = UddoktaPay::make(env('UDDOKTAPAY_API_KEY'), env('UDDOKTAPAY_API_URL'));
Initializing a Payment (Bangladeshi Methods)
To initiate a payment:
use UddoktaPay\LaravelSDK\Requests\CheckoutRequest; try { $checkoutRequest = CheckoutRequest::make() ->setFullName('John Doe') ->setEmail('john@doe.com') ->setAmount('10') ->addMetadata('order_id', '12345') ->setRedirectUrl(route('uddoktapay.verify')) ->setCancelUrl(route('uddoktapay.cancel')) ->setWebhookUrl(route('uddoktapay.ipn')); $response = $uddoktapay->checkout($checkoutRequest); if ($response->failed()) { dd($response->message()); } return redirect($response->paymentURL()); } catch (\UddoktaPay\LaravelSDK\Exceptions\UddoktaPayException $e) { dd("Initialization Error: " . $e->getMessage()); }
Initializing a Payment (Global Methods)
To initiate a payment:
use UddoktaPay\LaravelSDK\Requests\CheckoutRequest; try { $checkoutRequest = CheckoutRequest::make() ->setFullName('John Doe') ->setEmail('john@doe.com') ->setAmount('10') ->addMetadata('order_id', '12345') ->setRedirectUrl(route('uddoktapay.verify')) ->setCancelUrl(route('uddoktapay.cancel')) ->setWebhookUrl(route('uddoktapay.ipn')); $response = $uddoktapay->checkoutGlobal($checkoutRequest); if ($response->failed()) { dd($response->message()); } return redirect($response->paymentURL()); } catch (\UddoktaPay\LaravelSDK\Exceptions\UddoktaPayException $e) { dd("Initialization Error: " . $e->getMessage()); }
Verifying a Payment
After the payment is complete, verify it using the VerifyResponse class to understand the structure and available methods for processing the response:
try { $response = $uddoktapay->verify($request); if ($response->success()) { // Handle successful status dd($response->toArray()); // Handle success } elseif ($response->pending()) { // Handle pending status } elseif ($response->failed()) { // Handle failure } } catch (\UddoktaPay\LaravelSDK\Exceptions\UddoktaPayException $e) { dd("Verification Error: " . $e->getMessage()); }
Handling IPN Notifications (Optional)
To handle Instant Payment Notifications (IPN):
try { $response = $uddoktapay->ipn($request); if ($response->success()) { // Handle successful IPN } elseif ($response->pending()) { // Handle pending IPN } elseif ($response->failed()) { // Handle failed IPN } } catch (\UddoktaPay\LaravelSDK\Exceptions\UddoktaPayException $e) { dd("IPN Error: " . $e->getMessage()); }
Processing Refunds (Optional)
To process a refund:
use UddoktaPay\LaravelSDK\Requests\RefundRequest; try { $refundRequest = RefundRequest::make() ->setAmount('10') ->setTransactionId('12345') ->setPaymentMethod('bkash') ->setProductName('Sample Product') ->setReason('Customer Request'); $response = $uddoktapay->refund($refundRequest); if ($response->success()) { // Handle refund success } elseif ($response->failed()) { // Handle refund failure } } catch (\UddoktaPay\LaravelSDK\Exceptions\UddoktaPayException $e) { dd("Refund Error: " . $e->getMessage()); }
Routes
Add the following routes to your web.php file:
use App\Http\Controllers\UddoktaPayController; Route::get('/checkout', [UddoktaPayController::class, 'checkout'])->name('uddoktapay.checkout'); Route::get('/verify', [UddoktaPayController::class, 'verify'])->name('uddoktapay.verify'); Route::get('/cancel', [UddoktaPayController::class, 'cancel'])->name('uddoktapay.cancel'); Route::post('/ipn', [UddoktaPayController::class, 'ipn'])->name('uddoktapay.ipn'); Route::post('/refund', [UddoktaPayController::class, 'refund'])->name('uddoktapay.refund');
Notes
- Replace placeholders like
your_api_keywith actual credentials. - Use appropriate routes for success, cancel, and IPN handling.
- Always wrap SDK calls with
try-catchto handle errors effectively.
License
This project is open-source and available under the MIT License.
uddoktapay/laravel-sdk 适用场景与选型建议
uddoktapay/laravel-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.75k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 uddoktapay/laravel-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 uddoktapay/laravel-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-12