2020-04-09 14:04:26 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-04-09 14:04:26 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Listeners\Payment\PaymentNotification
|
|
|
|
*/
|
|
|
|
class GoogleAnalyticsTest extends TestCase
|
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2020-04-09 14:04:26 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-09 14:04:26 +02:00
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGoogleAnalyticsLogic()
|
|
|
|
{
|
2020-05-20 00:49:58 +02:00
|
|
|
$this->withoutEvents();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$analytics_id = 'analytics_id';
|
2020-04-09 14:04:26 +02:00
|
|
|
$invoice = $this->invoice;
|
|
|
|
$client = $this->client;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-08-29 10:15:50 +02:00
|
|
|
$invoice = $invoice->service()->markPaid()->save();
|
2020-04-09 14:04:26 +02:00
|
|
|
|
|
|
|
$payment = $invoice->payments->first();
|
|
|
|
|
|
|
|
$amount = $payment->amount;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
if ($invoice) {
|
2020-04-09 14:04:26 +02:00
|
|
|
$items = $invoice->line_items;
|
|
|
|
$item = end($items)->product_key;
|
|
|
|
$entity_number = $invoice->number;
|
2020-04-15 02:30:52 +02:00
|
|
|
} else {
|
2020-04-09 14:04:26 +02:00
|
|
|
$item = $payment->number;
|
|
|
|
$entity_number = $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
$currency_code = $client->getCurrencyCode();
|
|
|
|
|
|
|
|
if (Ninja::isHosted()) {
|
|
|
|
$item .= ' [R]';
|
|
|
|
}
|
|
|
|
|
|
|
|
$base = "v=1&tid={$analytics_id}&cid={$client->id}&cu={$currency_code}&ti={$entity_number}";
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$url = $base."&t=transaction&ta=ninja&tr={$amount}";
|
|
|
|
|
|
|
|
$url = $base."&t=item&in={$item}&ip={$amount}&iq=1";
|
2020-04-09 14:04:26 +02:00
|
|
|
|
|
|
|
$this->assertNotNull($url);
|
|
|
|
}
|
|
|
|
}
|