paytez/paytez-php-sdk
Composer 安装命令:
composer require paytez/paytez-php-sdk
包简介
PAYTez PHP SDK for interacting with the PAYTez API
README 文档
README
# PAYTez PHP SDK The PAYTez PHP SDK provides a convenient way to interact with the PAYTez API for handling web payments. This SDK allows you to create and verify web payments using PHP and cURL. ## Installation You can install the PAYTez PHP SDK via Composer. Run the following command in your project's root directory: ```bash composer require paytez/paytez-php-sdk
Usage
Using Composer:
To use the PAYTez PHP SDK with Composer, follow the steps below:
- Include the Composer autoloader in your PHP script:
require_once 'vendor/autoload.php';
- Create an instance of the PaytezApiClient class with your PAYTez API key:
use Paytez\PaytezApi\PaytezApiClient; $apiKey = 'your-api-key'; $paytezClient = new PaytezApiClient($apiKey, true); // Set to true for sandbox, false for live environment
- Create a Web Payment:
$invoiceAmount = "10"; $currencySymbol = "USD"; $successUrl = "http://example.com/success"; $failureUrl = "http://example.com/failure"; try { $redirectLink = $paytezClient->createWebPayment($invoiceAmount, $currencySymbol, $successUrl, $failureUrl); // Redirect the user to the payment page header("Location: " . $redirectLink); //FOR LARAVEL INTEGRATION USE THIS REDIRECT // return redirect()->away($redirectLink); exit(); } catch (\Exception $e) { // Handle any exceptions that may occur during the API call echo "Error: " . $e->getMessage(); }
- Verify a Web Payment:
$invoiceNo = "123456"; try { $verificationResult = $paytezClient->verifyWebPayment($invoiceNo); // Process the verification result as needed var_dump($verificationResult); } catch (\Exception $e) { // Handle any exceptions that may occur during the API call echo "Error: " . $e->getMessage(); }
Without Using Composer:
To use the PAYTez PHP SDK without Composer, follow these steps:
-
Download the SDK Files: Download the PAYTez PHP SDK files, including all the PHP files and the
srcfolder containing the classes. https://github.com/unpyn/paytez-php-sdk -
Include the SDK Files: Include the necessary SDK files in your PHP script using the
require_onceorinclude_oncestatements. Make sure to adjust the paths according to your project's file structure.For example:
// Replace 'path/to/paytez-php-sdk/src/' with the actual path to the SDK files require_once 'path/to/paytez-php-sdk/src/PaytezApi/PaytezApiClient.php';
-
Create an Instance of PaytezApiClient: Create an instance of the
PaytezApiClientclass with your PAYTez API key. Also, specify whether you want to use the sandbox or live environment.For example:
$apiKey = 'your-api-key'; $paytezClient = new Paytez\PaytezApi\PaytezApiClient($apiKey, true); // Set to true for sandbox, false for live environment
-
Use the Package's Methods: Now, you can use the methods provided by the PAYTez PHP SDK, such as
createWebPaymentandverifyWebPayment, in your PHP code.For example:
// Create a Web Payment $invoiceAmount = "10"; $currencySymbol = "USD"; $successUrl = "http://example.com/success"; $failureUrl = "http://example.com/failure"; try { $redirectLink = $paytezClient->createWebPayment($invoiceAmount, $currencySymbol, $successUrl, $failureUrl); // Redirect the user to the payment page header("Location: " . $redirectLink); exit(); } catch (\Exception $e) { // Handle any exceptions that may occur during the API call echo "Error: " . $e->getMessage(); } // Verify a Web Payment $invoiceNo = "123456"; try { $verificationResult = $paytezClient->verifyWebPayment($invoiceNo); // Process the verification result as needed var_dump($verificationResult); } catch (\Exception $e) { // Handle any exceptions that may occur during the API call echo "Error: " . $e->getMessage(); }
Requirements
- PHP 7.0 or higher
- cURL extension enabled
License
The PAYTez PHP SDK is open-source software licensed under the MIT License.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-02