invoiceninja/app/Listeners/AnalyticsListener.php
Hillel Coren b233aa0744 Merge branch 'release-2.6'
Conflicts:
	.travis.yml
	CONTRIBUTING.md
	README.md
	app/Http/Controllers/AccountController.php
	app/Http/Controllers/AppController.php
	app/Http/Controllers/BaseAPIController.php
	app/Http/Controllers/CreditController.php
	app/Http/Controllers/DashboardController.php
	app/Http/Controllers/DocumentController.php
	app/Http/Controllers/PaymentController.php
	app/Http/Controllers/QuoteApiController.php
	app/Http/Requests/EntityRequest.php
	app/Http/routes.php
	app/Listeners/AnalyticsListener.php
	app/Models/Account.php
	app/Models/Credit.php
	app/Models/Document.php
	app/Models/EntityModel.php
	app/Models/Expense.php
	app/Models/Invoice.php
	app/Models/Task.php
	app/Models/VendorContact.php
	app/Ninja/Notifications/PushFactory.php
	app/Ninja/Repositories/DocumentRepository.php
	app/Ninja/Repositories/ExpenseRepository.php
	app/Ninja/Repositories/InvoiceRepository.php
	app/Services/PushService.php
	composer.json
	composer.lock
	database/migrations/2014_05_17_175626_add_quotes.php
	database/seeds/UserTableSeeder.php
	resources/lang/en/texts.php
	resources/views/accounts/customize_design.blade.php
	resources/views/accounts/invoice_design.blade.php
	resources/views/accounts/management.blade.php
	resources/views/expenses/edit.blade.php
	resources/views/header.blade.php
	resources/views/invoices/edit.blade.php
	resources/views/master.blade.php
	resources/views/payments/payment.blade.php
	resources/views/users/edit.blade.php
2016-07-11 23:33:58 +03:00

60 lines
1.4 KiB
PHP

<?php namespace App\Listeners;
use Utils;
use App\Events\PaymentWasCreated;
/**
* Class AnalyticsListener
*/
class AnalyticsListener
{
/**
* @param PaymentWasCreated $event
*/
public function trackRevenue(PaymentWasCreated $event)
{
if ( ! Utils::isNinja() || ! env('ANALYTICS_KEY')) {
return;
}
$payment = $event->payment;
$invoice = $payment->invoice;
$account = $payment->account;
if ($account->account_key != NINJA_ACCOUNT_KEY) {
return;
}
$analyticsId = env('ANALYTICS_KEY');
$client = $payment->client;
$amount = $payment->amount;
$base = "v=1&tid={$analyticsId}&cid={$client->public_id}&cu=USD&ti={$invoice->invoice_number}";
$url = $base . "&t=transaction&ta=ninja&tr={$amount}";
$this->sendAnalytics($url);
$url = $base . "&t=item&in=plan&ip={$amount}&iq=1";
$this->sendAnalytics($url);
}
/**
* @param $data
*/
private function sendAnalytics($data)
{
$data = json_encode($data);
$curl = curl_init();
$opts = [
CURLOPT_URL => GOOGLE_ANALYITCS_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => 'POST',
CURLOPT_POSTFIELDS => $data,
];
curl_setopt_array($curl, $opts);
curl_close($curl);
}
}