定制 herepay/herepay-php-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

herepay/herepay-php-sdk

最新稳定版本:v1.2.3

Composer 安装命令:

composer require herepay/herepay-php-sdk

包简介

Herepay payment gateway PHP SDK.

README 文档

README

A PHP SDK for integrating with the Herepay payment gateway. This package provides a simple and efficient way to interact with the Herepay API for managing transactions, retrieving payment channels, and more.

Installation

Install the package via Composer:

composer require Herepay/herepay-php-sdk

If using Laravel, publish the configuration file:

php artisan vendor:publish --provider="HerepaySDK\HerepayServiceProvider" --tag=config

Configuration

Ensure you add the following environment variables to your .env file:

HEREPAY_SANDBOX=true
HEREPAY_SECRET_KEY=your_secret_key
HEREPAY_API_KEY=your_api_key
HEREPAY_PRIVATE_KEY=your_private_key

Or you can manually configure the SDK by passing the configuration array when initializing the HerepayService.

Usage

Initialize the SDK

use HerepaySDK\HerepayService;

$config = [
    'sandbox' => true, // Use false for production
    'secret_key' => 'your_secret_key',
    'api_key' => 'your_api_key',
    'private_key' => 'your_private_key',
];

$herepay = new HerepayService($config);

Get Payment Channels

Retrieve available payment channels:

$paymentChannels = $herepay->getPaymentChannels();
echo $paymentChannels;

Initiate transaction

Initiate transaction, response will redirect to Acquiring Bank

$transactionData = [
    'payment_code' => 'REF-123',
    'created_at' => date('Y-m-d H:i:s'),
    'amount' => 100,
    'name' => 'John Doe',
    'email' => 'john.doe@example.com',
    'phone' => '0123456789',
    'description' => 'Test Transaction',
    'bank_prefix' => 'TEST0021',
    'payment_method' => 'Online Banking',
];

$transactionData['checksum'] = $herepay->generateChecksum($transactionData);
$response = $herepay->initiate($transactionData);
header($response);

Get Transaction Details

Retrieve the details of a transaction:

$referenceCode = 'HP-INVAPI-XXXXXXXXXX';
$transactionDetails = $herepay->getTransactionDetails($referenceCode);
echo $transactionDetails;

Get Latest Transaction

Retrieve the latest transaction:

$transactions = $herepay->getTransactions();
echo $transactions;

Generate Checksum

Generate a checksum for data validation:

$transactionData = [
    'payment_code' => 'REF-123',
    'created_at' => date('Y-m-d H:i:s'),
    'amount' => 100,
    'name' => 'John Doe',
    'email' => 'john.doe@example.com',
    'phone' => '0123456789',
    'description' => 'Test Transaction',
    'bank_prefix' => 'TEST0021',
    'payment_method' => 'Online Banking',
];

$checksum = $herepay->generateChecksum($transactionData);
echo $checksum;

Testing

Run the tests using PHPUnit:

vendor/bin/phpunit --testdox tests

Ensure that the .env.testing file is properly set up with sandbox credentials.

Contributing

Contributions are welcome! Please fork this repository, make your changes, and submit a pull request.

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-28