mirovit / borica-api
通过他们的API与BORICA进行通信的包
1.1
2017-12-13 22:07 UTC
Requires
- nesbot/carbon: ^1.21
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: 4.8.*
README
这是BORICA API的一个简单实现,用于添加支付服务。
安装
从Composer拉取
composer require mirovit/borica-api
如何使用
一种方法是创建一个Mirovit\Borica\Factory
实例,它接受Mirovit\Borica\Request
和Mirovit\Borica\Response
作为构造函数参数。或者单独使用请求和响应类。
请求负责生成对BORICA API的请求URL - 可能的请求包括:注册交易、检查交易状态、注册延迟交易请求、完成延迟交易请求、撤销延迟交易请求和从已注册交易中部分或全部撤销金额。
<?php require __DIR__ . '/vendor/autoload.php'; $factory = new Factory( new Request('<terminal id from BORICA>', '<private key signed from BORICA>', '<private key password (optional)>', '<language (optional - BG or EN)>', '<debug (optional, whether you're testing or accepting payments)>'), new Response('<public certificate from BORICA>') );
注册交易
$factory->request() ->amount('1') // 1 EUR ->orderID(1) // Unique identifier in your system ->description('testing the process') // Short description of the purchase (up to 125 chars) ->currency('EUR') // The currency of the payment ->register(); // Type of the request
检查交易状态
$factory->request() ->amount('1') // 1 EUR ->orderID(1) // Unique identifier in your system ->description('testing the process') // Short description of the purchase (up to 125 chars) ->currency('EUR') // The currency of the payment ->status(); // Type of the request
撤销交易
$factory->request() ->amount('1') // 1 EUR - partial reversal (amount less than the original), full reversal the original amount ->orderID(1) // Unique identifier in your system ->reverse(); // Type of the request
与Laravel 5一起使用
创建以下服务提供程序并将其注册到应用中。您可以将它添加到config/app.php
或将其注册到Providers/AppServiceProvider.php
中。
<?php
namespace App\Providers;
use Mirovit\Borica\Factory;
use Mirovit\Borica\Request;
use Mirovit\Borica\Response;
use Illuminate\Support\ServiceProvider;
class BoricaServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind(Request::class, function(){
return new Request(env('BORICA_TERMINAL_ID'), 'path/to/private.key', '', app()->getLocale());
});
$this->app->bind(Response::class, function(){
return new Response('path/to/public.cer');
});
$this->app->bind(Factory::class, function(){
return new Factory(app(Request::class), app(Response::class));
}, true);
}
}
贡献
如果您想贡献,请随意发送拉取请求!