paytez/paytez-php-sdk

PAYTez PHP SDK,用于与 PAYTez API 交互

dev-master 2023-08-18 07:46 UTC

This package is not auto-updated.

Last update: 2024-09-27 12:37:57 UTC


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

用法

使用 Composer

要使用 Composer 与 PAYTez PHP SDK,请按照以下步骤操作

  1. 在您的 PHP 脚本中包含 Composer 自动加载器
require_once 'vendor/autoload.php';
  1. 使用您的 PAYTez API 密钥创建 PaytezApiClient 类的实例
use Paytez\PaytezApi\PaytezApiClient;

$apiKey = 'your-api-key';
$paytezClient = new PaytezApiClient($apiKey, true); // Set to true for sandbox, false for live environment
  1. 创建网络支付
$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();
}
  1. 验证网络支付
$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();
}

不使用 Composer

要使用不使用 Composer 的 PAYTez PHP SDK,请按照以下步骤操作

  1. 下载 SDK 文件:下载 PAYTez PHP SDK 文件,包括所有 PHP 文件和包含类的 src 文件夹。https://github.com/unpyn/paytez-php-sdk

  2. 包含 SDK 文件:使用 require_onceinclude_once 语句在您的 PHP 脚本中包含必要的 SDK 文件。请确保根据您项目的文件结构调整路径。

    例如

    // 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';
  3. 创建 PaytezApiClient 的实例:使用您的 PAYTez API 密钥创建 PaytezApiClient 类的实例。同时,指定您是否想使用沙盒或生产环境。

    例如

    $apiKey = 'your-api-key';
    $paytezClient = new Paytez\PaytezApi\PaytezApiClient($apiKey, true); // Set to true for sandbox, false for live environment
  4. 使用包的函数:现在,您可以在 PHP 代码中使用 PAYTez PHP SDK 提供的函数,如 createWebPaymentverifyWebPayment

    例如

    // 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();
    }

要求

  • PHP 7.0 或更高版本
  • cURL 扩展已启用

许可协议

PAYTez PHP SDK 是开源软件,许可协议为 MIT 许可协议