Download the PHP package xentixar/khalti-sdk without Composer
On this page you can find all versions of the php package xentixar/khalti-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package khalti-sdk
KhaltiSdk PHP Library
The KhaltiSdk
is a PHP library for integrating the Khalti payment gateway into your application. This library simplifies the process of initializing payments, validating transactions, and more.
Installation
To use this library, you'll need to include it in your project. You can install it via Composer. If you don't have Composer installed, you can download it from getcomposer.org.
Step-by-step Installation
-
Install Composer:
-
Add the package to your project:
- Include Composer's autoloader in your script:
Usage
Setting Up the Khalti Instance
Create a new instance of the Khalti
class and set your secret key using the setSecretKey
method. The secret key is required for authorization when making API requests.
Example Code
Configuration Details
The config
method allows you to specify several parameters:
$return_url
: The URL where the user will be redirected after payment.$website_url
: Your website's URL.$amount
: The payment amount in rupees.$purchase_order_id
: A unique identifier for the purchase order.$purchase_order_name
: The name of the purchase order.$customer_info
: An optional array containing customer details (name
,email
,phone
).$amount_breakdown
: Optional breakdown of the amount (e.g., tax, shipping).$product_details
: Optional product details.
Initiating a Payment
The init
method sends a request to the Khalti API to initiate the payment process. It handles the request server-side, and if the response contains a payment_url
, it redirects the user to the Khalti payment page.
Note: For production, set the $production
flag to true
in the init
method.
Validating a Transaction
To validate a transaction, use the validate
method. This method sends a request to the Khalti API to check the status of a transaction.
Note: For production, set the $production
flag to true
in the validate
method.
Decoding the Response
To decode the response data from Khalti:
Error Handling
The init
method includes basic error handling for cURL requests. You may want to add additional error handling based on your application's requirements.
Contribution
Contributions are welcome! Please submit a pull request or create an issue to report bugs or request features.
License
This library is licensed under the MIT License. See the LICENSE file for more details.