Commit e30c41c9 authored by Ivan Belitskii's avatar Ivan Belitskii

Initial commit

parents
# Digitalquill DQ Billing API for laravel
## Installation
Add this to your `composer.json` file:
"require": {
"dq/dqbilling-api": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "http://gitlab.digitalquill.co.uk/useful/dqbilling-api.git"
}
]
Then register service provider in `config/app.php`:
Dq\DqBillingApi\DqBillingApiServiceProvider::class
And add this to `aliases`:
'DqBilling' => Dq\DqBillingApi\Facades\DqBilling::class,
In your `.env` file define url to api and api token:
DQ_BILLING_HOST=http://dqbilling.dev
DQ_BILLING_SECRET=123
{
"name": "dq/dqbilling-api",
"description": "Api wrapper for dq billing",
"type": "library",
"authors": [
{
"name": "Ivan Belitskii",
"email": "belitskii@gmail.com"
}
],
"require": {
"guzzlehttp/guzzle": "^6.2",
"staskjs/simple-api": "^1.1"
},
"autoload": {
"classmap": [
],
"psr-4": {
"Dq\\DqBillingApi\\": "src/"
}
}
}
<?php
return [
'api_token' => env('DQ_BILLING_SECRET'),
'api_url' => env('DQ_BILLING_HOST'),
];
<?php namespace Dq\DqBillingApi;
use GuzzleHttp\Exception\RequestException;
class DqBilling extends \Staskjs\SimpleApi\SimpleJsonApi {
public function __construct() {
$url = config('dqbilling-api.api_url') . '/api';
if (empty($url)) {
throw new \Exception('DQ_BILLING_HOST is not specified');
}
$token = config('dqbilling-api.api_token');
if (empty($token)) {
throw new \Exception('DQ_BILLING_SECRET is not specified');
}
parent::__construct($url, ['token' => $token]);
}
public function pay(array $customerData, array $paymentData) {
$customer = [
'id' => $customerData['id']
];
$payment = [
'card_identifier' => $paymentData['card_identifier'],
'merchantSessionKey' => $paymentData['merchant_session_key'],
'description' => $paymentData['payment_type'],
'type' => $paymentData['payment_type'],
'amount' => $paymentData['amount'],
'currency' => $paymentData['currency'],
'save_card' => $paymentData['save_data'],
'applicationAlias' => $paymentData['application_alias']
];
return $this->request('POST', 'pay', [
'customer' => $customer,
'payment' => $payment,
]);
}
public function getPaymentSession() {
return $this->request('GET', 'payment_session');
}
}
<?php
namespace Dq\DqBillingApi;
use Illuminate\Support\ServiceProvider;
class DqBillingApiServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot() {
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'dqbilling-api');
}
/**
* Register the application services.
*
* @return void
*/
public function register() {
$this->app->bind('dqbilling', function() {
return new \Dq\DqBillingApi\DqBilling;
});
}
}
<?php
namespace Dq\DqBillingApi\Facades;
use Illuminate\Support\Facades\Facade;
class DqBilling extends Facade {
/**
* Get the binding in the IoC container
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'dqbilling'; // the IoC binding.
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment