將支付解決方案整合到您的 PHP 應用程式中變得更加容易。我們很高興地宣布發布 Pesapal PHP SDK,這是一個強大且用戶友好的庫,旨在簡化您與 Pesapal 支付網關的交互。
?為什麼選擇 Pesapal PHP SDK?
Pesapal 是非洲領先的支付平台,為各種規模的企業提供安全可靠的支付處理。然而,直接整合 Pesapal 的 API 可能既耗時又複雜。我們的 SDK 抽象化了 API 的複雜性,為開發人員提供了乾淨直覺的介面。
主要特點
- 輕鬆驗證:使用 Pesapal 簡化 OAuth 驗證。
- 無縫支付整合:快速發起付款並處理回調。
- 交易管理:輕鬆查看交易狀態並處理退款。
- 符合 PSR-4:遵循 PHP-FIG 自動載入標準。
- 廣泛的文件:有詳細記錄的方法和範例,可協助您入門。
?入門
安裝
透過 Composer 安裝 SDK:
composer require katorymnd/pesapal-php-sdk
要求
- PHP 8.0 或更高版本
- 作曲家
- Pesapal 商家帳號
配置
使用您的 Pesapal 憑證初始化客戶端:
require 'vendor/autoload.php'; use Katorymnd\PesapalPhpSdk\Api\PesapalClient; use Katorymnd\PesapalPhpSdk\Config\PesapalConfig; $consumerKey = 'YOUR_CONSUMER_KEY'; $consumerSecret = 'YOUR_CONSUMER_SECRET'; // Initialize PesapalConfig and PesapalClient $configPath = __DIR__ . '/../pesapal_dynamic.json'; $config = new PesapalConfig($consumerKey, $consumerSecret, $configPath); $environment = 'sandbox'; $sslVerify = false; // Enable SSL verification for production $pesapal = new PesapalClient($config, $environment, $sslVerify);
?發起付款
以下是您如何使用最少的程式碼啟動付款:
use Katorymnd\PesapalPhpSdk\Utils\PesapalHelpers; $merchantReference = PesapalHelpers::generateMerchantReference(); $notificationId = 'adbd39cc-a48e-4789-b42b-79ad8deb32df'; // Replace with actual notification ID from IPN registration // Define the order data as an associative array for the POST request $paymentDetails= [ "id" => $merchantReference, "currency" => "USD", "amount" => 100.00, "description" => "Payment for invoice " . $merchantReference, "callback_url" => "https://www.example.com/payment-callback", "notification_id" => $notificationId, "redirect_mode" => "PARENT_WINDOW", "cancellation_url" => "https://www.example.com/payment-cancel", "billing_address" => [ "phone_number" => "0700000000", "email_address" => "john.doe@example.com", "country_code" => "UG", "first_name" => "John", "middle_name" => "", "last_name" => "Doe", "line_1" => "123 Example Street", "line_2" => "", "city" => "Kampala", "state" => "KMP", "postal_code" => 256 ] ]; // Obtain a valid access token $accessToken = $clientApi->getAccessToken(); if (!$accessToken) { throw new PesapalException('Failed to obtain access token'); } // Submit order request to Pesapal $response = $clientApi->submitOrderRequest($orderData); if ($response['status'] === 200 && isset($response['response']['redirect_url'])) { $redirectUrl = $response['response']['redirect_url']; $orderTrackingId = $response['response']['order_tracking_id']; } else { // Handle errors $response['response']['error'] }
?檢查交易狀態
檢查交易狀態:
use Katorymnd\PesapalPhpSdk\Exceptions\PesapalException; // Obtain a valid access token $accessToken = $clientApi->getAccessToken(); if (!$accessToken) { throw new PesapalException('Failed to obtain access token'); } // Get the transaction status $response = $clientApi->getTransactionStatus($orderTrackingId); if ($response['status'] === 200 && isset($response['response'])) { $transactionStatusData = $response['response']; }
?處理退款
輕鬆退款:
// Prepare refund data with user-provided values $refundData = [ 'confirmation_code' => '7323605385336397404011', // the code is received by checking the transaction status 'amount' => 50.00, 'username' => 'John Doe', 'remarks' => 'Customer Requested Refund' ]; try { // Request Refund $refundResponse = $clientApi->requestRefund($refundData); if ($refundResponse['status'] === 200 && isset($refundResponse['response'])) { $refundDataResponse = $refundResponse['response']; // Add refund response to the output $responseData['refund_response'] = $refundDataResponse; } else { $errorMessage = $refundResponse['response']['error']['message'] ?? 'Unknown error occurred while requesting a refund.'; throw new PesapalException($errorMessage); } } catch (PesapalException $e) { // Add the error to the response $responseData['refund_error'] = [ 'error' => $e->getMessage(), 'details' => $e->getErrorDetails(), ]; }
?測試與開發
我們提供了一套全面的測試套件,以確保 SDK 的可靠性。運行測試:
vendor/bin/phpunit
?文件
有關所有可用方法和功能的詳細信息,請參閱我們的 GitHub 儲存庫。
?貢獻
我們歡迎社區的貢獻!請隨意提交問題、分叉儲存庫並提出拉取請求。
?包裹配送
該 SDK 在 Packagist 上可用,可以輕鬆透過 Composer 包含在您的專案中。
?️持續集成
我們已經使用 GitHub Actions 設定了持續集成,以確保每次更新都保持最高的品質標準。
?結論
Pesapal PHP SDK 旨在節省您的時間和精力,讓您專注於建立出色的應用程序,而無需擔心支付整合的複雜性。我們很高興看到您用它建造了什麼!
?保持聯繫
- GitHub:github.com/katorymnd/pesapal-php-sdk
- Packagist:packagist.org/packages/katorymnd/pesapal-php-sdk
以上是Pesapal PHP SDK 簡介:簡化您的支付集成的詳細內容。更多資訊請關注PHP中文網其他相關文章!

絕對會話超時從會話創建時開始計時,閒置會話超時則從用戶無操作時開始計時。絕對會話超時適用於需要嚴格控制會話生命週期的場景,如金融應用;閒置會話超時適合希望用戶長時間保持會話活躍的應用,如社交媒體。

服務器會話失效可以通過以下步驟解決:1.檢查服務器配置,確保會話設置正確。 2.驗證客戶端cookies,確認瀏覽器支持並正確發送。 3.檢查會話存儲服務,如Redis,確保其正常運行。 4.審查應用代碼,確保會話邏輯正確。通過這些步驟,可以有效診斷和修復會話問題,提升用戶體驗。

session_start()iscucialinphpformanagingusersessions.1)ItInitiateSanewsessionifnoneexists,2)resumesanexistingsessions,and3)setsasesessionCookieforContinuityActinuityAccontinuityAcconActInityAcconActInityAcconAccRequests,EnablingApplicationsApplicationsLikeUseAppericationLikeUseAthenticationalticationaltication and PersersonalizedContentent。

設置httponly標誌對會話cookie至關重要,因為它能有效防止XSS攻擊,保護用戶會話信息。具體來說,1)httponly標誌阻止JavaScript訪問cookie,2)在PHP和Flask中可以通過setcookie和make_response設置該標誌,3)儘管不能防範所有攻擊,但應作為整體安全策略的一部分。

phpsessions solvathepromblymaintainingStateAcrossMultipleHttpRequestsbyStoringDataTaNthEserVerAndAssociatingItwithaIniquesestionId.1)他們儲存了AtoredAtaserver side,通常是Infilesordatabases,InseasessessionIdStoreDistordStoredStoredStoredStoredStoredStoredStoreDoreToreTeReTrestaa.2)

tostartaphpsession,usesesses_start()attheScript'Sbeginning.1)placeitbeforeanyOutputtosetThesessionCookie.2)useSessionsforuserDatalikeloginstatusorshoppingcarts.3)regenerateSessiveIdStopreventFentfixationAttacks.s.4)考慮使用AttActAcks.s.s.4)

會話再生是指在用戶進行敏感操作時生成新會話ID並使舊ID失效,以防會話固定攻擊。實現步驟包括:1.檢測敏感操作,2.生成新會話ID,3.銷毀舊會話ID,4.更新用戶端會話信息。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

WebStorm Mac版
好用的JavaScript開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。