


Integrating payment solutions into your PHP applications just got a whole lot easier. We are thrilled to announce the release of our Pesapal PHP SDK, a robust and user-friendly library designed to streamline your interaction with the Pesapal payment gateway.
? Why Pesapal PHP SDK?
Pesapal is a leading payment platform in Africa, offering secure and reliable payment processing for businesses of all sizes. However, integrating Pesapal's API directly can be time-consuming and complex. Our SDK abstracts the intricacies of the API, providing a clean and intuitive interface for developers.
Key Features
- Easy Authentication: Simplifies OAuth authentication with Pesapal.
- Seamless Payment Integration: Quickly initiate payments and handle callbacks.
- Transaction Management: Easily check transaction statuses and process refunds.
- PSR-4 Compliant: Follows PHP-FIG standards for autoloading.
- Extensive Documentation: Well-documented methods and examples to get you started.
? Getting Started
Installation
Install the SDK via Composer:
composer require katorymnd/pesapal-php-sdk
Requirements
- PHP 8.0 or higher
- Composer
- Pesapal Merchant Account
Configuration
Initialize the client with your Pesapal credentials:
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);
? Initiating a Payment
Here's how you can initiate a payment with minimal code:
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'] }
? Checking Transaction Status
To check the status of a transaction:
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']; }
? Processing Refunds
Issue a refund with ease:
// 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(), ]; }
? Testing and Development
We have included a comprehensive test suite to ensure the reliability of the SDK. To run the tests:
vendor/bin/phpunit
? Documentation
For detailed information on all available methods and features, please refer to our GitHub repository.
? Contributing
We welcome contributions from the community! Feel free to submit issues, fork the repository, and make pull requests.
? Package Distribution
The SDK is available on Packagist, making it easy to include in your projects via Composer.
?️ Continuous Integration
We have set up continuous integration using GitHub Actions to ensure that every update maintains the highest quality standards.
? Conclusion
The Pesapal PHP SDK is designed to save you time and effort, allowing you to focus on building great applications without worrying about the complexities of payment integration. We are excited to see what you build with it!
? Stay in Touch
- GitHub: github.com/katorymnd/pesapal-php-sdk
- Packagist: packagist.org/packages/katorymnd/pesapal-php-sdk
The above is the detailed content of Introducing the Pesapal PHP SDK: Simplify Your Payment Integration. For more information, please follow other related articles on the PHP Chinese website!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools
