hedeqiang/alchemypay

AlchemyPay SDK for PHP

v1.0.0 2022-10-30 13:59 UTC

This package is auto-updated.

Last update: 2024-10-29 06:13:22 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require Tests

环境需求

支持主流框架 LaravelHyperfYii2 快捷使用,具体使用方法请滑到底部

Installing

$ composer require hedeqiang/alchemypay -vvv

Usage

require __DIR__ .'/vendor/autoload.php';
use Hedeqiang\AlchemyPay\Pay;
$app = new Pay([
    'endpoint'     => 'xxx',
    'merchantCode' => 'xxx',
    'privateKey' => 'xxx',
]);

创建订单

$uri = 'openApi/createOrder';

$params = [
    "amount"           => "10.0",
    "fiatType"         => "CNY",
    "callbackUrl"      => "http://147.243.170.11:9091/transnotify",
    "merchantOrderNum" => "testqwe1234567891035",
    "payMent"          => "w1",
    "email"            => "123456@qq.com",
];

$response = $app->request($uri,$params);

回调通知

$result = $app->handleNotify();
// TODO

return 'SUCCESS' ; // retuen 'Fail';

在 Laravel 中使用

发布配置文件

php artisan vendor:publish --tag=alchemy
or 
php artisan vendor:publish --provider="Hedeqiang\AlchemyPay\ServiceProvider"
编写 .env 文件
ALCHEMY_PAY_ENDPOINT=
ALCHEMY_PAY_MERCHANT_CODE=
ALCHEMY_PAY_PRIVATE_KEY=

使用

服务名访问

public function index()
{
    return app('pay')->request($uri,$params);
}

Facades 门面使用(可以提示)

use Hedeqiang\AlchemyPay\Facades\Pay;

public function index()
{
   return Pay::pay()->request($uri,$params)
}

public function notify(Request $request)
{
   $result = Pay::pay()->handleNotify();
}

在 Hyperf 中使用

发布配置文件

php bin/hyperf.php vendor:publish hedeqiang/alchemypay
编写 .env 文件
ALCHEMY_PAY_ENDPOINT=
ALCHEMY_PAY_MERCHANT_CODE=
ALCHEMY_PAY_PRIVATE_KEY=

使用

<?php

use Hedeqiang\AlchemyPay\Pay;
use Hyperf\Utils\ApplicationContext;

// 请求
response = ApplicationContext::getContainer()->get(Pay::class)->request($uri,$parmas);

// 回调
$response = ApplicationContext::getContainer()->get(Pay::class)->handleNotify();

在 Yii2 中使用

配置

Yii2 配置文件 config/main.phpcomponents 中添加:

'components' => [
    // ...
    'pay' => [
        'class' => 'Hedeqiang\AlchemyPay\YiiPay',
        'options' => [
            'endpoint'     => 'xxx',
            'merchantCode' => 'xxx',
            'privateKey' => 'xxx',
        ],
    ],
    // ...
]

使用

Yii::$app->response->format = Response::FORMAT_JSON;

// 请求
$results = Yii::$app->pay->getPay()->request($uri,$params);
// 回调
$results = Yii::$app->pay->getPay()->handleNotify();

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

MIT