定制 nikba/paynet 二次开发

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

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

nikba/paynet

最新稳定版本:v1.4

Composer 安装命令:

composer require nikba/paynet

包简介

Paynet payment module for Laravel

README 文档

README

This package provides integration with the Paynet payment gateway for Laravel applications.

Installation

Install the package via Composer:

composer require nikba/paynet

Publish the configuration file:

php artisan vendor:publish --provider="Nikba\Paynet\Providers\PaynetServiceProvider" --tag="config"

Add the following environment variables to your .env file:

PAYNET_MERCHANT_CODE=862491
PAYNET_SECRET_KEY=F822E47B-6F4F-4D9D-92EB-566ED89E3D76
PAYNET_USERNAME=388018
PAYNET_PASSWORD=6olmfsQX
PAYNET_TEST_MODE=true

Usage

Initiate a Payment

Use the Paynet facade to initiate a payment:

use Nikba\Paynet\Facades\Paynet;

$paymentData = [
    'Invoice' => 20160622010101,
    'Currency' => 498,
    'LinkUrlSuccess' => 'http://localhost:8000/pay/1?status=success',
    'LinkUrlCancel' => 'http://localhost:8000/pay/1?status=cancel',
    'Customer' => [
        'Code' => 'CustomerCode',
        'NameFirst' => 'FirstName',
        'NameLast' => 'LastName',
        'PhoneNumber' => 'PhoneNumber',
        'email' => 'customer@example.com',
        'Country' => 'Country',
        'City' => 'City',
        'Address' => 'Address',
    ],
    'ExternalDate' => '2025-01-01T00:00:00',
    'ExpiryDate' => '2025-01-02T00:00:00',
    'Services' => [
        [
            'Name' => 'ServiceName',
            'Description' => 'ServiceDescription',
            'amount' => 100,
            'Products' => [
                [
                    'Amount' => 100,
                    'Code' => 'PRODUCT1',
                    'Description' => 'ProductDescription',
                    'LineNo' => 1,
                    'Name' => 'ProductName',
                    'UnitPrice' => 100,
                    'UnitProduct' => 1,
                ],
            ],
        ],
    ],
    'SignVersion' => 'v01',
    'MoneyType' => null
];

$response = Paynet::sendPayment($paymentData);

Handle Paynet Notifications

Add a route to handle Paynet notifications in your routes/web.php file:

Route::post('/paynet/notification', [\Nikba\Paynet\Http\Controllers\PaynetController::class, 'handleNotification']);

Create a controller method to process the notifications:

public function handleNotification(Request $request)
{
    $notificationData = $request->all();

    try {
        $response = Paynet::handleNotification($notificationData);
        return response()->json(['status' => 'success', 'data' => $response]);
    } catch (\Exception $e) {
        Log::error('Paynet notification failed: ' . $e->getMessage());
        return response()->json(['error' => $e->getMessage()], 400);
    }
}

Testing

Install necessary dependencies for testing:

composer require --dev mockery/mockery

Run the tests:

vendor/bin/phpunit --filter PaynetServiceTest

Postman

Postman Collections (JSON file) for a quicker and easier usage of RESTful APIs.

How to import and configure

  • Download the postman_collection.json repository.
  • Click the Import button. On Postman for Mac, for example, the button is at the top left

统计信息

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

GitHub 信息

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

其他信息

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