Merge pull request #6855 from turbo124/v5-stable

v5.3.24
This commit is contained in:
David Bomba 2021-10-18 10:36:29 +11:00 committed by GitHub
commit df309c0546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
178 changed files with 425606 additions and 408882 deletions

View File

@ -1 +1 @@
5.3.23
5.3.24

View File

@ -486,7 +486,7 @@ class DemoMode extends Command
if (rand(0, 1)) {
$invoice->assigned_user_id = $assigned_user_id;
}
$invoice->number = $this->getNextRecurringInvoiceNumber($client);
$invoice->number = $this->getNextRecurringInvoiceNumber($client, $invoice);
$invoice->save();
}

View File

@ -70,10 +70,15 @@ class Kernel extends ConsoleKernel
$schedule->job(new SchedulerCheck)->daily()->withoutOverlapping();
if(Ninja::isSelfHost())
{
$schedule->call(function () {
Account::whereNotNull('id')->update(['is_scheduler_running' => true]);
})->everyFiveMinutes();
}
/* Run hosted specific jobs */
if (Ninja::isHosted()) {

View File

@ -24,6 +24,7 @@ class ClientContactFactory
$client_contact->company_id = $company_id;
$client_contact->contact_key = Str::random(40);
$client_contact->id = 0;
$client_contact->send_email = true;
return $client_contact;
}

View File

@ -29,9 +29,11 @@ class CloneQuoteToInvoiceFactory
unset($quote_array['id']);
unset($quote_array['invitations']);
unset($quote_array['terms']);
unset($quote_array['public_notes']);
// unset($quote_array['public_notes']);
unset($quote_array['footer']);
unset($quote_array['design_id']);
unset($quote_array['user']);
foreach ($quote_array as $key => $value) {
$invoice->{$key} = $value;

View File

@ -38,7 +38,7 @@ class RecurringExpenseToExpenseFactory
$expense->date = now()->format('Y-m-d');
$expense->payment_date = $recurring_expense->payment_date;
$expense->amount = $recurring_expense->amount;
$expense->foreign_amount = $recurring_expense->foreign_amount;
$expense->foreign_amount = $recurring_expense->foreign_amount ?: 0;
$expense->private_notes = $recurring_expense->private_notes;
$expense->public_notes = $recurring_expense->public_notes;
$expense->transaction_reference = $recurring_expense->transaction_reference;

View File

@ -207,4 +207,17 @@ abstract class QueryFilters
return $this->builder;
}
public function with_trashed($value)
{
if($value == 'true'){
$this->builder->withTrashed();
}
return $this->builder;
}
}

View File

@ -53,6 +53,9 @@ class InvoiceSum
{
$this->invoice = $invoice;
// if(!$this->invoice->relationLoaded('client'))
// $this->invoice->load('client');
$this->tax_map = new Collection;
}
@ -200,7 +203,7 @@ class InvoiceSum
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}
@ -208,7 +211,7 @@ class InvoiceSum
public function getQuote()
{
$this->setCalculatedAttributes();
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}
@ -216,7 +219,7 @@ class InvoiceSum
public function getCredit()
{
$this->setCalculatedAttributes();
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}
@ -227,7 +230,7 @@ class InvoiceSum
$this->invoice->total_taxes = $this->getTotalTaxes();
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}

View File

@ -191,7 +191,7 @@ class InvoiceSumInclusive
$this->invoice->total_taxes = $this->getTotalTaxes();
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}
@ -206,7 +206,7 @@ class InvoiceSumInclusive
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}
@ -215,7 +215,7 @@ class InvoiceSumInclusive
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}
@ -224,7 +224,7 @@ class InvoiceSumInclusive
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}

View File

@ -114,7 +114,7 @@ class PaymentController extends Controller
} else {
$payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id);
$payment->client_id = $payment_hash->fee_invoice->client_id;
$payment->save();
$payment->saveQuietly();
$payment_hash->payment_id = $payment->id;
$payment_hash->save();
@ -122,6 +122,8 @@ class PaymentController extends Controller
$payment = $payment->service()->applyCredits($payment_hash)->save();
event('eloquent.created: App\Models\Payment', $payment);
if (property_exists($payment_hash->data, 'billing_context')) {
$billing_subscription = \App\Models\Subscription::find($payment_hash->data->billing_context->subscription_id);

View File

@ -499,7 +499,7 @@ class CompanyController extends BaseController
$account->delete();
if(Ninja::isHosted())
if(Ninja::isHosted() && $request->has('cancellation_message') && strlen($request->input('cancellation_message')) > 1)
\Modules\Admin\Jobs\Account\NinjaDeletedAccount::dispatch($account_key, $request->all());
LightLogs::create(new AccountDeleted())

View File

@ -496,6 +496,7 @@ class DesignController extends BaseController
$company = auth()->user()->getCompany();
$design = Design::where('company_id', $company->id)
->orWhereNull('company_id')
->where('id', $design_id)
->exists();

View File

@ -204,6 +204,7 @@ class PreviewController extends BaseController
if($request->has('entity_id')){
$entity_obj = $class::on(config('database.default'))
->with('client.company')
->where('id', $this->decodePrimaryKey($request->input('entity_id')))
->where('company_id', $company->id)
->withTrashed()
@ -216,11 +217,11 @@ class PreviewController extends BaseController
if(!$request->has('entity_id'))
$entity_obj->service()->fillDefaults()->save();
$entity_obj->load('client.contacts','company');
// $entity_obj->load('client.contacts','client.company');
App::forgetInstance('translator');
$t = app('translator');
App::setLocale($entity_obj->client->contacts()->first()->preferredLocale());
App::setLocale($entity_obj->client->locale());
$t->replace(Ninja::transformTranslations($entity_obj->client->getMergedSettings()));
$html = new HtmlEngine($entity_obj->invitations()->first());

View File

@ -208,7 +208,11 @@ class RecurringInvoiceController extends BaseController
$offset = $recurring_invoice->client->timezone_offset();
$recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset);
$recurring_invoice->save();
$recurring_invoice->saveQuietly();
$recurring_invoice->service()
->triggeredActions($request)
->save();
return $this->itemResponse($recurring_invoice);
}

View File

@ -268,7 +268,7 @@ class BillingPortalPurchase extends Component
$client = $client_repo->save($data, ClientFactory::create($company->id, $user->id));
return $client->contacts->first();
return $client->fresh()->contacts->first();
}
/**

View File

@ -23,7 +23,7 @@ class UpdateAutoBilling extends Component
{
if ($this->invoice->auto_bill == 'optin' || $this->invoice->auto_bill == 'optout') {
$this->invoice->auto_bill_enabled = !$this->invoice->auto_bill_enabled;
$this->invoice->save();
$this->invoice->saveQuietly();
}
}

View File

@ -13,6 +13,7 @@ namespace App\Http\Middleware;
use App\Libraries\MultiDB;
use Closure;
use Hashids\Hashids;
use Illuminate\Http\Request;
use stdClass;
@ -45,6 +46,30 @@ class SetInviteDb
if($entity == "pay")
$entity = "invoice";
/* Try and determine the DB from the invitation key STRING*/
if (config('ninja.db.multi_db_enabled')) {
// nlog("/ Try and determine the DB from the invitation key /");
$hashids = new Hashids(config('ninja.hash_salt'), 10);
$segments = explode('-', $request->route('invitation_key'));
$hashed_db = false;
if(is_array($segments)){
$hashed_db = $hashids->decode($segments[0]);
}
if($hashed_db && is_array($hashed_db) && ($hashed_db[0] == "01" || $hashed_db[0] == "02")){
MultiDB::setDB(MultiDB::DB_PREFIX.str_pad($hashed_db[0], 2, '0', STR_PAD_LEFT));
return $next($request);
}
}
/* Attempt to set DB from invitatation key*/
if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByInvitation($entity, $request->route('invitation_key'))) {
if (request()->json) {
return response()->json($error, 403);

View File

@ -16,6 +16,7 @@ use App\Http\ValidationRules\Credit\UniqueCreditNumberRule;
use App\Models\Credit;
use App\Utils\Traits\CleanLineItems;
use App\Utils\Traits\MakesHash;
use Illuminate\Validation\Rule;
class StoreCreditRequest extends Request
{
@ -53,7 +54,11 @@ class StoreCreditRequest extends Request
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
$rules['number'] = new UniqueCreditNumberRule($this->all());
// $rules['number'] = new UniqueCreditNumberRule($this->all());
$rules['number'] = ['nullable', Rule::unique('credits')->where('company_id', auth()->user()->company()->id)];
$rules['line_items'] = 'array';
return $rules;

View File

@ -39,8 +39,6 @@ class StorePaymentRequest extends Request
{
$input = $this->all();
// nlog(print_r($input,1));
$invoices_total = 0;
$credits_total = 0;

View File

@ -63,6 +63,10 @@ class StoreRecurringExpenseRequest extends Request
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '';
if(array_key_exists('foreign_amount', $input) && is_null($input['foreign_amount']))
$input['foreign_amount'] = 0;
$this->replace($input);
}

View File

@ -105,7 +105,7 @@ class StoreRecurringInvoiceRequest extends Request
if (isset($input['auto_bill'])) {
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} else {
if ($client = Client::find($input['client_id'])) {
if (array_key_exists('client_id', $input) && $client = Client::find($input['client_id'])) {
$input['auto_bill'] = $client->getSetting('auto_bill');
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
}

View File

@ -51,6 +51,6 @@ class CreateStatementRequest extends Request
public function client(): ?Client
{
return Client::where('id', $this->client_id)->first();
return Client::with('company')->where('id', $this->client_id)->withTrashed()->first();
}
}

View File

@ -336,6 +336,14 @@ class CompanyExport implements ShouldQueue
})->all();
$this->export_data['recurring_expenses'] = $this->company->recurring_expenses->map(function ($expense){
$expense = $this->transformBasicEntities($expense);
$expense = $this->transformArrayOfKeys($expense, ['vendor_id', 'invoice_id', 'client_id', 'category_id', 'project_id']);
return $expense->makeVisible(['id']);
})->all();
$this->export_data['recurring_invoices'] = $this->company->recurring_invoices->makeVisible(['id'])->map(function ($ri){

View File

@ -47,6 +47,7 @@ use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
use App\Models\QuoteInvitation;
use App\Models\RecurringExpense;
use App\Models\RecurringInvoice;
use App\Models\RecurringInvoiceInvitation;
use App\Models\Subscription;
@ -76,6 +77,8 @@ use ZipArchive;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;
use function GuzzleHttp\json_encode;
class CompanyImport implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesHash, GeneratesCounter;
@ -135,6 +138,7 @@ class CompanyImport implements ShouldQueue
'quote_invitations',
'credits',
'credit_invitations',
'recurring_expenses',
'expenses',
'tasks',
'payments',
@ -452,6 +456,26 @@ class CompanyImport implements ShouldQueue
}
private function import_recurring_expenses()
{
//unset / transforms / object_property / match_key
$this->genericImport(RecurringExpense::class,
['assigned_user_id', 'user_id', 'client_id', 'company_id', 'id', 'hashed_id', 'project_id', 'vendor_id'],
[
['users' => 'user_id'],
['users' => 'assigned_user_id'],
['clients' => 'client_id'],
['projects' => 'project_id'],
['vendors' => 'vendor_id'],
['invoices' => 'invoice_id'],
['expense_categories' => 'category_id'],
],
'expenses',
'number');
return $this;
}
private function import_payment_terms()
{
@ -795,6 +819,8 @@ class CompanyImport implements ShouldQueue
['projects' => 'project_id'],
['vendors' => 'vendor_id'],
['invoices' => 'invoice_id'],
['recurring_expenses' => 'recurring_expense_id'],
['expense_categories' => 'category_id'],
],
'expenses',
'number');
@ -1248,6 +1274,7 @@ class CompanyImport implements ShouldQueue
if($class == 'App\Models\Subscription'){
$obj_array['product_ids'] = $this->recordProductIds($obj_array['product_ids']);
$obj_array['recurring_product_ids'] = $this->recordProductIds($obj_array['recurring_product_ids']);
$obj_array['webhook_configuration'] = json_encode($obj_array['webhook_configuration']);
}
$new_obj = $class::firstOrNew(
@ -1297,7 +1324,8 @@ class CompanyImport implements ShouldQueue
if($class == 'App\Models\Subscription'){
//$obj_array['product_ids'] = $this->recordProductIds($obj_array['product_ids']);
//$obj_array['recurring_product_ids'] = $this->recordProductIds($obj_array['recurring_product_ids']);
//
// $obj_array['webhook_configuration'] = json_encode($obj_array['webhook_configuration']);
$obj_array['webhook_configuration'] = '';
$obj_array['recurring_product_ids'] = '';
$obj_array['product_ids'] = '';
}

View File

@ -93,6 +93,7 @@ class CreateEntityPdf implements ShouldQueue
$this->contact = $invitation->contact;
$this->client = $invitation->contact->client;
$this->client->load('company');
$this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk;
@ -100,6 +101,8 @@ class CreateEntityPdf implements ShouldQueue
public function handle()
{
$start = microtime(true);
// nlog("Start ". $start);
/* Forget the singleton*/
App::forgetInstance('translator');
@ -107,11 +110,14 @@ class CreateEntityPdf implements ShouldQueue
/* Init a new copy of the translator*/
$t = app('translator');
/* Set the locale*/
App::setLocale($this->contact->preferredLocale());
App::setLocale($this->client->locale());
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->client->getMergedSettings()));
$translate = microtime(true);
// nlog("Translate ". $translate - $start);
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->generate($this->invitation);
}
@ -147,6 +153,9 @@ class CreateEntityPdf implements ShouldQueue
$html = new HtmlEngine($this->invitation);
$design_time = microtime(true);
// nlog("Design ". $design_time - $translate);
if ($design->is_custom) {
$options = [
'custom_partials' => json_decode(json_encode($design->design), true)
@ -158,6 +167,9 @@ class CreateEntityPdf implements ShouldQueue
$variables = $html->generateLabelsAndValues();
$labels_time = microtime(true);
// nlog("Labels ". $labels_time - $design_time);
$state = [
'template' => $template->elements([
'client' => $this->client,
@ -180,6 +192,10 @@ class CreateEntityPdf implements ShouldQueue
->design($template)
->build();
$template_time = microtime(true);
// nlog("Template Build ". $template_time - $labels_time);
$pdf = null;
try {
@ -200,6 +216,9 @@ class CreateEntityPdf implements ShouldQueue
}
$pdf_time = microtime(true);
// nlog("PDF time " . $pdf_time - $template_time);
if ($pdf) {
try{

View File

@ -0,0 +1,109 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Mail;
use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Libraries\MultiDB;
use App\Mail\Admin\EntityNotificationMailer;
use App\Mail\Admin\PaymentFailureObject;
use App\Models\Client;
use App\Models\Company;
use App\Models\PaymentHash;
use App\Models\User;
use App\Utils\Traits\Notifications\UserNotifies;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
/*Multi Mailer implemented*/
class PaymentFailedMailer implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
public PaymentHash $payment_hash;
public string $error;
public Company $company;
public Client $client;
/**
* Create a new job instance.
*
* @param $client
* @param $message
* @param $company
* @param $amount
*/
public function __construct(?PaymentHash $payment_hash, Company $company, Client $client, string $error)
{
$this->payment_hash = $payment_hash;
$this->client = $client;
$this->error = $error;
$this->company = $company;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//Set DB
MultiDB::setDb($this->company->db);
$settings = $this->client->getMergedSettings();
$amount = 0;
if($this->payment_hash)
$amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
//iterate through company_users
$this->company->company_users->each(function ($company_user) use($amount, $settings){
//determine if this user has the right permissions
$methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure','all_notifications']);
//if mail is a method type -fire mail!!
if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]);
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $amount, $this->payment_hash))->build();
$nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer($mail_obj);
$nmo->company = $this->company;
$nmo->to_user = $company_user->user;
$nmo->settings = $settings;
NinjaMailerJob::dispatch($nmo);
}
});
//add client payment failures here.
}
}

View File

@ -86,7 +86,7 @@ class PaymentFailureMailer implements ShouldQueue
if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]);
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount))->build();
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount, null))->build();
$nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer($mail_obj);
@ -98,5 +98,7 @@ class PaymentFailureMailer implements ShouldQueue
}
});
//add client payment failures here.
}
}

View File

@ -65,11 +65,11 @@ class ApplyQuoteNumber implements ShouldQueue
switch ($this->settings->quote_number_applied) {
case 'when_saved':
$this->quote->number = $this->getNextQuoteNumber($this->quote->client);
$this->quote->number = $this->getNextQuoteNumber($this->quote->client, $this->quote);
break;
case 'when_sent':
if ($this->quote->status_id == Quote::STATUS_SENT) {
$this->quote->number = $this->getNextQuoteNumber($this->quote->client);
$this->quote->number = $this->getNextQuoteNumber($this->quote->client, $this->quote);
}
break;

View File

@ -1,68 +0,0 @@
<?php
/**
* Quote Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Quote Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Quote;
use App\Factory\QuoteInvitationFactory;
use App\Libraries\MultiDB;
use App\Models\Company;
use App\Models\Quote;
use App\Models\QuoteInvitation;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class CreateQuoteInvitations implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $quote;
private $company;
/**
* Create a new job instance.
*
* @param Quote $quote
* @param Company $company
*/
public function __construct(Quote $quote, Company $company)
{
$this->quote = $quote;
$this->company = $company;
}
public function handle()
{
MultiDB::setDB($this->company->db);
$contacts = $this->quote->client->contacts;
$contacts->each(function ($contact) {
$invitation = QuoteInvitation::whereCompanyId($this->quote->company_id)
->whereClientContactId($contact->id)
->whereQuoteId($this->quote->id)
->first();
if (! $invitation && $contact->send) {
$ii = QuoteInvitationFactory::create($this->quote->company_id, $this->quote->user_id);
$ii->quote_id = $this->quote->id;
$ii->client_contact_id = $contact->id;
$ii->save();
} elseif ($invitation && ! $contact->send) {
$invitation->delete();
}
});
}
}

View File

@ -126,7 +126,7 @@ class SendRecurring implements ShouldQueue
if ($invitation->contact && !$invitation->contact->trashed() && strlen($invitation->contact->email) >=1 && $invoice->client->getSetting('auto_email_invoice')) {
try{
EmailEntity::dispatch($invitation, $invoice->company);
EmailEntity::dispatch($invitation, $invoice->company)->delay(now()->addSeconds(1));
}
catch(\Exception $e) {
nlog($e->getMessage());
@ -152,9 +152,6 @@ class SendRecurring implements ShouldQueue
}
//important catch all here - we should never leave contacts send_email to false incase they are permanently set to false in the future.
// $this->recurring_invoice->client->contacts()->update(['send_email' => true]);
}
public function failed($exception = null)

View File

@ -43,18 +43,19 @@ class WebhookHandler implements ShouldQueue
public $deleteWhenMissingModels = true;
private string $includes;
/**
* Create a new job instance.
*
* @param $event_id
* @param $entity
*/
public function __construct($event_id, $entity, $company)
public function __construct($event_id, $entity, $company, $includes = '')
{
$this->event_id = $event_id;
$this->entity = $entity;
$this->company = $company;
$this->includes = $includes;
}
/**
@ -90,6 +91,7 @@ class WebhookHandler implements ShouldQueue
// generate JSON data
$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
$manager->parseIncludes($this->includes);
$class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity));

View File

@ -332,7 +332,7 @@ class MultiDB
$current_db = config('database.default');
foreach (self::$dbs as $db) {
if ($invite = $class::on($db)->whereRaw('BINARY `key`= ?', [$invitation_key])->exists()) {
if ($invite = $class::on($db)->where('key', $invitation_key)->exists()) {
self::setDb($db);
return true;
}

View File

@ -1,51 +0,0 @@
<?php
/**
* Invoice Ninja (https://creditninja.com).
*
* @link https://github.com/creditninja/creditninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://creditninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Listeners\Credit;
use App\Factory\CreditInvitationFactory;
use App\Libraries\MultiDB;
use App\Models\CreditInvitation;
use Illuminate\Contracts\Queue\ShouldQueue;
class CreateCreditInvitation implements ShouldQueue
{
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$credit = $event->credit;
$contacts = $credit->client->contacts;
$contacts->each(function ($contact) use ($credit) {
$invitation = CreditInvitation::whereCompanyId($credit->company_id)
->whereClientContactId($contact->id)
->whereCreditId($credit->id)
->first();
if (! $invitation && $contact->send_credit) {
$ii = CreditInvitationFactory::create($credit->company_id, $credit->user_id);
$ii->credit_id = $credit->id;
$ii->client_contact_id = $contact->id;
$ii->save();
} elseif ($invitation && ! $contact->send_credit) {
$invitation->delete();
}
});
}
}

View File

@ -1,51 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Listeners\Invoice;
use App\Factory\InvoiceInvitationFactory;
use App\Libraries\MultiDB;
use App\Models\InvoiceInvitation;
use Illuminate\Contracts\Queue\ShouldQueue;
class CreateInvoiceInvitation implements ShouldQueue
{
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$invoice = $event->invoice;
$contacts = $invoice->client->contacts;
$contacts->each(function ($contact) use ($invoice) {
$invitation = InvoiceInvitation::whereCompanyId($invoice->company_id)
->whereClientContactId($contact->id)
->whereInvoiceId($invoice->id)
->first();
if (! $invitation && $contact->send) {
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
$ii->invoice_id = $invoice->id;
$ii->client_contact_id = $contact->id;
$ii->save();
} elseif ($invitation && ! $contact->send) {
$invitation->delete();
}
});
}
}

View File

@ -14,10 +14,13 @@ namespace App\Listeners\Quote;
use App\Factory\QuoteInvitationFactory;
use App\Libraries\MultiDB;
use App\Models\QuoteInvitation;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
class CreateQuoteInvitation implements ShouldQueue
{
use MakesHash;
/**
* Handle the event.
*
@ -40,6 +43,7 @@ class CreateQuoteInvitation implements ShouldQueue
if (! $invitation && $contact->send_credit) {
$ii = QuoteInvitationFactory::create($quote->company_id, $quote->user_id);
$ii->key = $this->createDbHash(config('database.default'));
$ii->quote_id = $quote->id;
$ii->client_contact_id = $contact->id;
$ii->save();

View File

@ -62,7 +62,7 @@ class ClientPaymentFailureObject
/* Init a new copy of the translator*/
$t = app('translator');
/* Set the locale*/
App::setLocale($this->company->getLocale());
App::setLocale($this->client->locale());
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->company->settings));

View File

@ -49,6 +49,7 @@ class EntityCreatedObject
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->entity->company->settings));
$this->entity->load('client.country', 'client.company');
$this->client = $this->entity->client;
$this->company = $this->entity->company;

View File

@ -11,25 +11,29 @@
namespace App\Mail\Admin;
use App\Models\Client;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\PaymentHash;
use App\Utils\Ninja;
use App\Utils\Number;
use App\Utils\Traits\MakesHash;
use stdClass;
use Illuminate\Support\Facades\App;
use stdClass;
class PaymentFailureObject
{
use MakesHash;
public $client;
public Client $client;
public $error;
public string $error;
public $company;
public Company $company;
public $amount;
public PaymentHash $payment_hash;
// private $invoices;
/**
@ -40,7 +44,7 @@ class PaymentFailureObject
* @param $company
* @param $amount
*/
public function __construct($client, $error, $company, $amount)
public function __construct(Client $client, string $error, Company $company, $amount, ?PaymentHash $payment_hash)
{
$this->client = $client;
@ -52,6 +56,8 @@ class PaymentFailureObject
$this->company = $company;
$this->payment_hash = $payment_hash;
}
public function build()
@ -65,8 +71,6 @@ class PaymentFailureObject
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->company->settings));
// $this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
$mail_obj = new stdClass;
$mail_obj->amount = $this->getAmount();
$mail_obj->subject = $this->getSubject();
@ -106,32 +110,33 @@ class PaymentFailureObject
'client' => $this->client->present()->name()
]
),
'message' => $this->error,
'content' => ctrans(
'texts.notification_invoice_payment_failed',
[
'client' => $this->client->present()->name(),
'invoice' => $this->getDescription(),
'amount' => Number::formatMoney($this->amount, $this->client)
]),
'signature' => $signature,
'logo' => $this->company->present()->logo(),
'settings' => $this->client->getMergedSettings(),
'whitelabel' => $this->company->account->isPaid() ? true : false,
'url' => config('ninja.app_url'),
'button' => ctrans('texts.login'),
'additional_info' => $this->buildFailedInvoices()
'additional_info' => $this->error
];
return $data;
}
private function buildFailedInvoices()
public function getDescription(bool $abbreviated = false)
{
if(!$this->payment_hash)
return "";
$text = '';
// foreach($this->invoices as $invoice)
// {
// $text .= ctrans('texts.notification_invoice_payment_failed_subject', ['invoice' => $invoice->number]) . "\n";
// }
return $text;
return \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray());
}
}

View File

@ -46,7 +46,7 @@ class PaymentEmailEngine extends BaseEmailEngine
$this->payment = $payment;
$this->company = $payment->company;
$this->client = $payment->client;
$this->contact = $contact ?: $this->client->primary_contact()->first();
$this->contact = $contact ?: $this->client->contacts()->first();
$this->contact->load('client.company');
$this->settings = $this->client->getMergedSettings();
$this->template_data = $template_data;
@ -239,10 +239,20 @@ class PaymentEmailEngine extends BaseEmailEngine
$data['$invoices'] = ['value' => $this->formatInvoices(), 'label' => ctrans('texts.invoices')];
$data['$invoice_references'] = ['value' => $this->formatInvoiceReferences(), 'label' => ctrans('texts.invoices')];
$data['$invoice'] = ['value' => $this->formatInvoice(), 'label' => ctrans('texts.invoices')];
return $data;
}
private function formatInvoice()
{
$invoice = '';
if($this->payment->invoices()->exists())
$invoice = ctrans('texts.invoice_number_short') . implode(",", $this->payment->invoices->pluck('number')->toArray());
return $invoice;
}
private function formatInvoices()
{
$invoice_list = '<br><br>';

View File

@ -87,7 +87,7 @@ class TemplateEmail extends Mailable
$this->from(config('mail.from.address'), $email_from_name);
if (strlen($settings->bcc_email) > 1)
$this->bcc(explode(",",$settings->bcc_email));
$this->bcc(explode(",",str_replace(" ", "", $settings->bcc_email)));//remove whitespace if any has been inserted.
$this->subject($this->build_email->getSubject())
->text('email.template.plain', [

View File

@ -519,31 +519,7 @@ class Client extends BaseModel implements HasLocalePreference
}
return null;
// $company_gateways = $this->getSetting('company_gateway_ids');
// if (strlen($company_gateways) >= 1) {
// $transformed_ids = $this->transformKeys(explode(',', $company_gateways));
// $gateways = $this->company
// ->company_gateways
// ->whereIn('id', $transformed_ids)
// ->sortby(function ($model) use ($transformed_ids) {
// return array_search($model->id, $transformed_ids);
// });
// } else {
// $gateways = $this->company->company_gateways;
// }
// foreach ($gateways as $gateway) {
// if ($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::BANK_TRANSFER))) {
// return $gateway;
// }
// if ($this->currency()->code == 'EUR' && in_array(GatewayType::SEPA, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::SEPA))) {
// return $gateway;
// }
// }
// return null;
}
public function getBankTransferMethodType()

View File

@ -12,7 +12,6 @@
namespace App\Models;
use App\Models\GatewayType;
use App\PaymentDrivers\BasePaymentDriver;
use App\Utils\Number;
use Illuminate\Database\Eloquent\SoftDeletes;
use stdClass;
@ -134,11 +133,10 @@ class CompanyGateway extends BaseModel
$class = 'App\\PaymentDrivers\\'.$this->gateway->provider.'PaymentDriver';
$class = str_replace('_', '', $class);
if (class_exists($class)) {
if (class_exists($class))
return $class;
} else {
return BasePaymentDriver::class;
}
throw new \Exception("Payment Driver does not exist");
}
/**

View File

@ -61,7 +61,7 @@ class Gateway extends StaticModel
$link = 'https://bitpay.com/dashboard/signup';
} elseif ($this->id == 18) {
$link = 'https://applications.sagepay.com/apply/2C02C252-0F8A-1B84-E10D-CF933EFCAA99';
} elseif ($this->id == 20) {
} elseif ($this->id == 20 || $this->id == 56) {
$link = 'https://dashboard.stripe.com/account/apikeys';
}
@ -89,17 +89,20 @@ class Gateway extends StaticModel
break;
case 7:
return [
GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true], // Mollie
GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true],
GatewayType::KBC => ['refund' => false, 'token_billing' => false],
GatewayType::BANCONTACT => ['refund' => false, 'token_billing' => false],
GatewayType::IDEAL => ['refund' => false, 'token_billing' => false],
GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], // Mollie
GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']],
GatewayType::KBC => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']],
GatewayType::BANCONTACT => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']],
GatewayType::IDEAL => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']],
];
case 15:
return [GatewayType::PAYPAL => ['refund' => true, 'token_billing' => false]]; //Paypal
return [
GatewayType::PAYPAL => ['refund' => true, 'token_billing' => false]
]; //Paypal
break;
case 20:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable','charge.succeeded']],
GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false],
GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false],
@ -109,30 +112,41 @@ class Gateway extends StaticModel
GatewayType::GIROPAY => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']]];
GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
];
case 39:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Checkout
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']]]; //Checkout
break;
case 46:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Paytrace
case 49:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true]]; //WePay
return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']]
]; //WePay
break;
case 50:
return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], //Braintree
GatewayType::PAYPAL => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']],
];
break;
case 56:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable','charge.succeeded']],
GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false],
GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false],
GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']]]; //Stripe
GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], //Stripe
GatewayType::SEPA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::PRZELEWY24 => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::GIROPAY => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
];
break;
case 57:
return [
@ -141,12 +155,12 @@ class Gateway extends StaticModel
break;
case 52:
return [
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true] // GoCardless
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']] // GoCardless
];
break;
case 58:
return [
GatewayType::HOSTED_PAGE => ['refund' => false, 'token_billing' => false] // Razorpay
GatewayType::HOSTED_PAGE => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']] // Razorpay
];
break;
default:

View File

@ -72,7 +72,6 @@ class CompanyPresenter extends EntityPresenter
else
return "data:image/png;base64, ". base64_encode(file_get_contents(asset('images/new_logo.png'), false, stream_context_create($context_options)));
}
public function address($settings = null)

View File

@ -36,9 +36,7 @@ class InvoiceObserver
if ($subscriptions) {
$invoice->load('client');
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client');
}
}
@ -50,17 +48,14 @@ class InvoiceObserver
*/
public function updated(Invoice $invoice)
{
$subscriptions = Webhook::where('company_id', $invoice->company_id)
->where('event_id', Webhook::EVENT_UPDATE_INVOICE)
->exists();
if ($subscriptions) {
$invoice->load('client');
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client');
}
@ -80,9 +75,7 @@ class InvoiceObserver
if ($subscriptions) {
$invoice->load('client');
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client');
}
}

View File

@ -29,11 +29,8 @@ class PaymentObserver
->where('event_id', Webhook::EVENT_CREATE_PAYMENT)
->exists();
if($payment->invoices()->exists())
$payment->load('invoices');
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices');
}
}
@ -60,7 +57,7 @@ class PaymentObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company, 'invoices');
}
}

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Authorize;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -134,7 +133,15 @@ class AuthorizeCreditCard
'data' => $this->formatGatewayResponse($data, $vars),
];
PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransId(), $this->authorize->client->company, $amount);
$code = "Error";
$description = "There was an error processing the payment";
if ($response->getErrors() != null) {
$code = $response->getErrors()[0]->getErrorCode();
$description = $response->getErrors()[0]->getErrorText();
}
$this->authorize->sendFailureMail($description);
SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_AUTHORIZE, $this->authorize->client, $this->authorize->client->company);
@ -212,9 +219,9 @@ class AuthorizeCreditCard
$description = $response->getErrors()[0]->getErrorText();
}
PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransId(), $this->authorize->client->company, $amount);
$this->authorize->sendFailureMail($description);
$payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->firstOrFail();
$payment_hash = PaymentHash::where('hash', $request->input('payment_hash'))->firstOrFail();
$vars = [
'invoices' => $payment_hash->invoices(),

View File

@ -19,7 +19,7 @@ use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Mail\PaymentFailedMailer;
use App\Jobs\Util\SystemLogger;
use App\Mail\Admin\ClientPaymentFailureObject;
use App\Models\Client;
@ -236,7 +236,7 @@ class BaseDriver extends AbstractPaymentDriver
$payment->type_id = $data['payment_type'];
$payment->transaction_reference = $data['transaction_reference'];
$payment->client_contact_id = $client_contact_id;
$payment->save();
$payment->saveQuietly();
$this->payment_hash->payment_id = $payment->id;
$this->payment_hash->save();
@ -248,6 +248,8 @@ class BaseDriver extends AbstractPaymentDriver
$payment->service()->updateInvoicePayment($this->payment_hash);
event('eloquent.created: App\Models\Payment', $payment);
if ($this->client->getSetting('client_online_payment_notification'))
$payment->service()->sendEmail();
@ -371,19 +373,44 @@ class BaseDriver extends AbstractPaymentDriver
} else
$error = $e->getMessage();
PaymentFailureMailer::dispatch(
$amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
$this->sendFailureMail($error);
SystemLogger::dispatch(
$gateway->payment_hash,
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_ERROR,
$gateway::SYSTEM_LOG_TYPE,
$gateway->client,
$error,
$gateway->client->company,
$this->payment_hash
);
if (!is_null($this->payment_hash)) {
throw new PaymentFailed($error, $e->getCode());
}
public function sendFailureMail(string $error)
{
PaymentFailedMailer::dispatch(
$this->payment_hash,
$this->client->company,
$this->client,
$error
);
}
public function clientPaymentFailureMailer($error)
{
if ($this->payment_hash && is_array($this->payment_hash->invoices())) {
$nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($gateway->client, $error, $gateway->client->company, $this->payment_hash))->build());
$nmo->company = $gateway->client->company;
$nmo->settings = $gateway->client->company->settings;
$nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build());
$nmo->company = $this->client->company;
$nmo->settings = $this->client->company->settings;
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
@ -403,20 +430,8 @@ class BaseDriver extends AbstractPaymentDriver
});
}
SystemLogger::dispatch(
$gateway->payment_hash,
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_ERROR,
$gateway::SYSTEM_LOG_TYPE,
$gateway->client,
$gateway->client->company,
);
throw new PaymentFailed($error, $e->getCode());
}
/**
@ -442,7 +457,7 @@ class BaseDriver extends AbstractPaymentDriver
$this->unWindGatewayFees($this->payment_hash);
PaymentFailureMailer::dispatch($this->client, $error, $this->client->company, $this->payment_hash->data->amount_with_fee);
$this->sendFailureMail($error);
$nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer( (new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build() );
@ -459,7 +474,7 @@ class BaseDriver extends AbstractPaymentDriver
$invoices->first()->invitations->each(function ($invitation) use ($nmo){
if (!$invitation->contact->trashed() && $invitation->contact->email) {
if (!$invitation->contact->trashed()) {
$nmo->to_user = $invitation->contact;
NinjaMailerJob::dispatch($nmo);
@ -620,21 +635,27 @@ class BaseDriver extends AbstractPaymentDriver
{
$types = [];
// if($type == GatewayType::BANK_TRANSFER && $this->company_gateway->fees_and_limits->{GatewayType::BANK_TRANSFER}->is_enabled)
// {
// $types[] = $type;
// }
// elseif($type == GatewayType::CREDIT_CARD && $this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled)
// {
// $types[] = $type;
// }
$types[] = GatewayType::CREDIT_CARD;
$types[] = GatewayType::BANK_TRANSFER;
return $types;
}
/**
* Generic description handler
*/
public function getDescription(bool $abbreviated = true)
{
if(!$this->payment_hash)
return "";
if($abbreviated)
return \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray());
return sprintf('%s: %s', ctrans('texts.invoices'), \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray()));
}
public function disconnect()
{
return true;

View File

@ -1,313 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\PaymentDrivers;
use App\Factory\PaymentFactory;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\CompanyGateway;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SystemLogTrait;
use Illuminate\Support\Carbon;
use Omnipay\Omnipay;
/**
* Class BasePaymentDriver.
'amount' => $invoice->getRequestedAmount(),
'currency' => $invoice->getCurrencyCode(),
'returnUrl' => $completeUrl,
'cancelUrl' => $this->invitation->getLink(),
'description' => trans('texts.' . $invoice->getEntityType()) . " {$invoice->number}",
'transactionId' => $invoice->number,
'transactionType' => 'Purchase',
'clientIp' => Request::getClientIp(),
];
*/
class BasePaymentDriver
{
use SystemLogTrait;
use MakesHash;
/* The company gateway instance*/
public $company_gateway;
/* The Omnipay payment driver instance*/
protected $gateway;
/* The Invitation */
protected $invitation;
/* Gateway capabilities */
protected $refundable = false;
/* Token billing */
public $token_billing = false;
/* Authorise payment methods */
protected $can_authorise_credit_card = false;
public function __construct(CompanyGateway $company_gateway, Client $client, $invitation = false)
{
$this->company_gateway = $company_gateway;
$this->invitation = $invitation;
$this->client = $client;
}
/**
* Returns the Omnipay driver.
* @return stdClass Omnipay initialized object
*/
protected function gateway()
{
$this->gateway = Omnipay::create($this->company_gateway->gateway->provider);
$this->gateway->initialize((array) $this->company_gateway->getConfig());
return $this;
}
/**
* Return the configuration fields for the
* Gatway.
* @return array The configuration fields
*/
public function getFields()
{
return $this->gateway->getDefaultParameters();
}
/**
* Returns the default gateway type.
*/
public function gatewayTypes()
{
return [
GatewayType::CREDIT_CARD,
];
}
public function getCompanyGatewayId(): int
{
return $this->company_gateway->id;
}
/**
* Returns whether refunds are possible with the gateway.
* @return bool TRUE|FALSE
*/
public function getRefundable(): bool
{
return $this->refundable;
}
/**
* Returns whether token billing is possible with the gateway.
* @return bool TRUE|FALSE
*/
public function getTokenBilling(): bool
{
return $this->token_billing;
}
/**
* Returns whether gateway can
* authorise and credit card.
* @return bool [type] [description]
*/
public function canAuthoriseCreditCard(): bool
{
return $this->can_authorise_credit_card;
}
/**
* Refunds a given payment.
* @param $payment
* @param int $amount
* @return false
*/
public function refundPayment($payment, $amount = 0)
{
if ($amount) {
$amount = min($amount, $payment->getCompletedAmount());
} else {
$amount = $payment->getCompletedAmount();
}
if ($payment->is_deleted || ! $amount) {
return false;
}
if ($payment->type_id == Payment::TYPE_CREDIT_CARD) {
return $payment->recordRefund($amount);
}
$details = $this->refundDetails($payment, $amount);
$response = $this->gateway()->refund($details)->send();
if ($response->isSuccessful()) {
return $payment->recordRefund($amount);
} elseif ($this->attemptVoidPayment($response, $payment, $amount)) {
$details = ['transactionReference' => $payment->transaction_reference];
$response = $this->gateway->void($details)->send();
if ($response->isSuccessful()) {
return $payment->markVoided();
}
}
return false;
}
protected function attemptVoidPayment($response, $payment, $amount)
{
// Partial refund not allowed for unsettled transactions
return $amount == $payment->amount;
}
public function authorizeCreditCardView(array $data)
{
}
public function authorizeCreditCardResponse($request)
{
}
public function processPaymentView(array $data)
{
}
public function processPaymentResponse($request)
{
}
/**
* Return the contact if possible.
*
* @return ClientContact The ClientContact object
*/
public function getContact()
{
if ($this->invitation) {
return ClientContact::find($this->invitation->client_contact_id);
} elseif (auth()->guard('contact')->user()) {
return auth()->user();
} else {
return false;
}
}
/************************************* Omnipay ******************************************
* authorize($options) - authorize an amount on the customer's card
* completeAuthorize($options) - handle return from off-site gateways after authorization
* capture($options) - capture an amount you have previously authorized
* purchase($options) - authorize and immediately capture an amount on the customer's card
* completePurchase($options) - handle return from off-site gateways after purchase
* refund($options) - refund an already processed transaction
* void($options) - generally can only be called up to 24 hours after submitting a transaction
* acceptNotification() - convert an incoming request from an off-site gateway to a generic notification object for further processing
* @param $input
* @return array
*/
protected function paymentDetails($input): array
{
$data = [
'currency' => $this->client->getCurrencyCode(),
'transactionType' => 'Purchase',
'clientIp' => request()->getClientIp(),
];
return $data;
}
public function purchase($data, $items)
{
$this->gateway();
$response = $this->gateway
->purchase($data)
->setItems($items)
->send();
return $response;
}
public function completePurchase($data)
{
$this->gateway();
return $this->gateway
->completePurchase($data)
->send();
}
public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment
{
$payment = PaymentFactory::create($this->client->company->id, $this->client->user->id);
$payment->client_id = $this->client->id;
$payment->company_gateway_id = $this->company_gateway->id;
$payment->status_id = $status;
$payment->currency_id = $this->client->getSetting('currency_id');
$payment->date = Carbon::now();
return $payment->service()->applyNumber()->save();
}
public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment
{
$paid_invoices = $payment_hash->invoices();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$payment->invoices()->sync($invoices);
$payment->save();
return $payment;
}
/**
* When a successful payment is made, we need to append the gateway fee
* to an invoice.
*
* @param PaymentResponseRequest $request The incoming payment request
* @return void Success/Failure
*/
public function confirmGatewayFee(PaymentResponseRequest $request) :void
{
/*Payment meta data*/
$payment_hash = $request->getPaymentHash();
/*Payment invoices*/
$payment_invoices = $payment_hash->invoices();
// /*Fee charged at gateway*/
$fee_total = $payment_hash->fee_total;
// Sum of invoice amounts
// $invoice_totals = array_sum(array_column($payment_invoices,'amount'));
/*Hydrate invoices*/
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) use ($fee_total) {
if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->save();
$invoice->client->service()->updateBalance($fee_total)->save();
$invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for Invoice {$invoice->number}");
}
});
}
}

View File

@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Braintree;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -158,14 +157,7 @@ class ACH implements MethodInterface
private function processUnsuccessfulPayment($response)
{
PaymentFailureMailer::dispatch($this->braintree->client, $response->transaction->additionalProcessorResponse, $this->braintree->client->company, $this->braintree->payment_hash->data->amount_with_fee);
PaymentFailureMailer::dispatch(
$this->braintree->client,
$response,
$this->braintree->client->company,
$this->braintree->payment_hash->data->amount_with_fee,
);
$this->braintree->sendFailureMail($response->transaction->additionalProcessorResponse);
$message = [
'server_response' => $response,

View File

@ -16,7 +16,6 @@ namespace App\PaymentDrivers\Braintree;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -113,9 +112,14 @@ class CreditCard
$result = $this->braintree->gateway->transaction()->sale($data);
} catch(\Exception $e) {
if ($e instanceof \Braintree\Exception\Authorization) {
$this->braintree->sendFailureMail(ctrans('texts.generic_gateway_error'));
throw new PaymentFailed(ctrans('texts.generic_gateway_error'), $e->getCode());
}
$this->braintree->sendFailureMail($e->getMessage());
throw new PaymentFailed($e->getMessage(), $e->getCode());
}
@ -162,6 +166,8 @@ class CreditCard
return $response->paymentMethod->token;
}
$this->braintree->sendFailureMail($response->message);
throw new PaymentFailed($response->message);
}
@ -195,14 +201,8 @@ class CreditCard
*/
private function processUnsuccessfulPayment($response)
{
PaymentFailureMailer::dispatch($this->braintree->client, $response->transaction->additionalProcessorResponse, $this->braintree->client->company, $this->braintree->payment_hash->data->amount_with_fee);
PaymentFailureMailer::dispatch(
$this->braintree->client,
$response,
$this->braintree->client->company,
$this->braintree->payment_hash->data->amount_with_fee,
);
$this->braintree->sendFailureMail($response->transaction->additionalProcessorResponse);
$message = [
'server_response' => $response,

View File

@ -6,7 +6,6 @@ namespace App\PaymentDrivers\Braintree;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -149,14 +148,7 @@ class PayPal
private function processUnsuccessfulPayment($response)
{
PaymentFailureMailer::dispatch($this->braintree->client, $response->message, $this->braintree->client->company, $this->braintree->payment_hash->data->amount_with_fee);
PaymentFailureMailer::dispatch(
$this->braintree->client,
$response,
$this->braintree->client->company,
$this->braintree->payment_hash->data->amount_with_fee,
);
$this->braintree->sendFailureMail($response->message);
$message = [
'server_response' => $response,

View File

@ -14,7 +14,6 @@ namespace App\PaymentDrivers;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -240,7 +239,7 @@ class BraintreePaymentDriver extends BaseDriver
if (!$result->success) {
$this->unWindGatewayFees($payment_hash);
PaymentFailureMailer::dispatch($this->client, $result->transaction->additionalProcessorResponse, $this->client->company, $this->payment_hash->data->amount_with_fee);
$this->sendFailureMail($result->transaction->additionalProcessorResponse);
$message = [
'server_response' => $result,

View File

@ -14,9 +14,11 @@ namespace App\PaymentDrivers\CheckoutCom;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Http\Requests\Request;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\PaymentDrivers\CheckoutComPaymentDriver;
use App\PaymentDrivers\Common\MethodInterface;
use App\Utils\Traits\MakesHash;
use Checkout\Library\Exceptions\CheckoutHttpException;
use Checkout\Models\Payments\IdSource;
@ -25,7 +27,7 @@ use Checkout\Models\Payments\TokenSource;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
class CreditCard
class CreditCard implements MethodInterface
{
use Utilities;
use MakesHash;
@ -38,6 +40,8 @@ class CreditCard
public function __construct(CheckoutComPaymentDriver $checkout)
{
$this->checkout = $checkout;
$this->checkout->init();
}
/**
@ -54,15 +58,50 @@ class CreditCard
}
/**
* Checkout.com supports doesn't support direct authorization of the credit card.
* Token can be saved after the first (successful) purchase.
* Handle authorization for credit card.
*
* @param mixed $data
* @return void
* @param Request $request
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function authorizeResponse($data)
public function authorizeResponse(Request $request)
{
return;
$gateway_response = \json_decode($request->gateway_response);
$method = new TokenSource(
$gateway_response->token
);
$payment = new Payment($method, 'USD');
$payment->amount = 100; // $1
$payment->reference = '$1 payment for authorization.';
$payment->capture = false;
try {
$response = $this->checkout->gateway->payments()->request($payment);
if ($response->approved && $response->status === 'Authorized') {
$payment_meta = new \stdClass;
$payment_meta->exp_month = (string) $response->source['expiry_month'];
$payment_meta->exp_year = (string) $response->source['expiry_year'];
$payment_meta->brand = (string) $response->source['scheme'];
$payment_meta->last4 = (string) $response->source['last4'];
$payment_meta->type = (int) GatewayType::CREDIT_CARD;
$data = [
'payment_meta' => $payment_meta,
'token' => $response->source['id'],
'payment_method_id' => GatewayType::CREDIT_CARD,
];
$payment_method = $this->checkout->storeGatewayToken($data);
return redirect()->route('client.payment_methods.show', $payment_method->hashed_id);
}
} catch (CheckoutHttpException $exception) {
throw new PaymentFailed(
$exception->getMessage()
);
}
}
public function paymentView($data)
@ -80,15 +119,12 @@ class CreditCard
public function paymentResponse(PaymentResponseRequest $request)
{
$this->checkout->init();
$state = [
'server_response' => json_decode($request->gateway_response),
'value' => $request->value,
'raw_value' => $request->raw_value,
'currency' => $request->currency,
'payment_hash' => $request->payment_hash,
'reference' => $request->payment_hash,
'client_id' => $this->checkout->client->id,
];
@ -136,7 +172,7 @@ class CreditCard
{
$payment = new Payment($method, $this->checkout->payment_hash->data->currency);
$payment->amount = $this->checkout->payment_hash->data->value;
$payment->reference = $this->checkout->payment_hash->data->reference;
$payment->reference = $this->checkout->getDescription();
$this->checkout->payment_hash->data = array_merge((array)$this->checkout->payment_hash->data, ['checkout_payment_ref' => $payment]);
$this->checkout->payment_hash->save();
@ -149,13 +185,18 @@ class CreditCard
'company_gateway_id' => $this->checkout->company_gateway->hashed_id,
'hash' => $this->checkout->payment_hash->hash,
]);
$payment->{'failure_url'} = route('checkout.3ds_redirect', [
'company_key' => $this->checkout->client->company->company_key,
'company_gateway_id' => $this->checkout->company_gateway->hashed_id,
'hash' => $this->checkout->payment_hash->hash,
]);
}
try {
$response = $this->checkout->gateway->payments()->request($payment);
if ($response->status == 'Authorized') {
return $this->processSuccessfulPayment($response);
}
@ -168,12 +209,14 @@ class CreditCard
if ($response->status == 'Declined') {
$this->checkout->unWindGatewayFees($this->checkout->payment_hash);
PaymentFailureMailer::dispatch($this->checkout->client, $response->response_summary, $this->checkout->client->company, $this->checkout->payment_hash->data->value);
$this->checkout->sendFailureMail($response->response_summary);
//@todo - this will double up the checkout . com failed mails
$this->checkout->clientPaymentFailureMailer($response->status);
return $this->processUnsuccessfulPayment($response);
}
} catch (CheckoutHttpException $e) {
$this->checkout->unWindGatewayFees($this->checkout->payment_hash);
return $this->checkout->processInternallyFailedPayment($this->checkout, $e);
}

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\CheckoutCom;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\PaymentType;
@ -85,12 +84,8 @@ trait Utilities
public function processUnsuccessfulPayment(Payment $_payment, $throw_exception = true)
{
PaymentFailureMailer::dispatch(
$this->getParent()->client,
$_payment,
$this->getParent()->client->company,
$this->getParent()->payment_hash->data->value
);
$this->getParent()->sendFailureMail($_payment->status . " " . $_payment->response_summary);
$message = [
'server_response' => $_payment,
@ -107,7 +102,7 @@ trait Utilities
);
if ($throw_exception) {
throw new PaymentFailed($_payment->status, $_payment->http_code);
throw new PaymentFailed($_payment->status . " " . $_payment->response_summary, $_payment->http_code);
}
}

View File

@ -15,7 +15,6 @@ namespace App\PaymentDrivers;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Gateways\Checkout3ds\Checkout3dsRequest;
use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\Company;
@ -243,27 +242,18 @@ class CheckoutComPaymentDriver extends BaseDriver
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";
} else {
$description = "Payment with no invoice for amount {$amount} for client {$this->client->present()->name()}";
}
$this->init();
$method = new IdSource($cgt->token);
$payment = new \Checkout\Models\Payments\Payment($method, $this->client->getCurrencyCode());
$payment->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode());
//$payment->reference = $cgt->meta->last4 . '-' . now();
$payment->reference = $invoice->number . '-' . now();
$request = new PaymentResponseRequest();
$request->setMethod('POST');
$request->request->add(['payment_hash' => $payment_hash->hash]);
//$this->setPaymentHash($payment_hash);
try {
$response = $this->gateway->payments()->request($payment);
@ -293,11 +283,7 @@ class CheckoutComPaymentDriver extends BaseDriver
if ($response->status == 'Declined') {
$this->unWindGatewayFees($payment_hash);
PaymentFailureMailer::dispatch(
$this->client, $response->response_summary,
$this->client->company,
$amount
);
$this->sendFailureMail($response->status . " " . $response->response_summary);
$message = [
'server_response' => $response,
@ -328,7 +314,16 @@ class CheckoutComPaymentDriver extends BaseDriver
'message' => $message,
];
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_CHECKOUT, $this->client, $this->client->company);
$this->sendFailureMail($message);
SystemLogger::dispatch(
$data,
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_CHECKOUT,
$this->client,
$this->client->company
);
}
}

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Eway;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -84,8 +83,12 @@ class CreditCard
$response_status = ErrorCode::getStatus($response->ResponseMessage);
if(!$response_status['success'])
throw new PaymentFailed($response_status['message'], 400);
if(!$response_status['success']){
$this->eway_driver->sendFailureMail($response_status['message']);
throw new PaymentFailed($response_status['message'], 400);
}
//success
$cgt = [];
@ -159,6 +162,8 @@ class CreditCard
$this->logResponse($response, false);
$this->eway_driver->sendFailureMail($response_status['message']);
throw new PaymentFailed($response_status['message'], 400);
}
@ -238,6 +243,8 @@ class CreditCard
$this->logResponse($response, false);
$this->eway_driver->sendFailureMail($response_status['message']);
throw new PaymentFailed($response_status['message'], 400);
}

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Eway;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -73,8 +72,8 @@ class Token
$amount = array_sum(array_column($this->eway_driver->payment_hash->invoices(), 'amount')) + $this->eway_driver->payment_hash->fee_total;
$data = [
'gateway_type_id' => $cgt->gateway_type_id,
'payment_type' => GatewayType::CREDIT_CARD_OTHER,
'gateway_type_id' => GatewayType::CREDIT_CARD,
'payment_type' => PaymentType::CREDIT_CARD_OTHER,
'transaction_reference' => $response->Customer->Reference,
'amount' => $amount,
];
@ -83,8 +82,8 @@ class Token
$payment->meta = $cgt->meta;
$payment->save();
$payment_hash->payment_id = $payment->id;
$payment_hash->save();
$this->eway_driver->payment_hash->payment_id = $payment->id;
$this->eway_driver->payment_hash->save();
return $payment;

View File

@ -15,7 +15,6 @@ namespace App\PaymentDrivers\GoCardless;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -228,14 +227,7 @@ class ACH implements MethodInterface
*/
public function processUnsuccessfulPayment(\GoCardlessPro\Resources\Payment $payment)
{
PaymentFailureMailer::dispatch($this->go_cardless->client, $payment->status, $this->go_cardless->client->company, $this->go_cardless->payment_hash->data->amount_with_fee);
PaymentFailureMailer::dispatch(
$this->go_cardless->client,
$payment,
$this->go_cardless->client->company,
$payment->amount
);
$this->go_cardless->sendFailureMail($payment->status);
$message = [
'server_response' => $payment,

View File

@ -12,7 +12,6 @@
namespace App\PaymentDrivers;
use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -148,12 +147,7 @@ class GoCardlessPaymentDriver extends BaseDriver
return $payment;
}
PaymentFailureMailer::dispatch(
$this->client,
$payment->status,
$this->client->company,
$amount
);
$this->sendFailureMail($payment->status);
$message = [
'server_response' => $payment,

View File

@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\Request;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -78,7 +77,7 @@ class Bancontact implements MethodInterface
'currency' => $this->mollie->client->currency()->code,
'value' => $this->mollie->convertToMollieAmount((float) $this->mollie->payment_hash->data->amount_with_fee),
],
'description' => \sprintf('Invoices: %s', collect($data['invoices'])->pluck('invoice_number')),
'description' => \sprintf('%s: %s', ctrans('texts.invoices'), \implode(', ', collect($data['invoices'])->pluck('invoice_number')->toArray())),
'redirectUrl' => route('client.payments.response', [
'company_gateway_id' => $this->mollie->company_gateway->id,
'payment_hash' => $this->mollie->payment_hash->hash,
@ -109,12 +108,8 @@ class Bancontact implements MethodInterface
*/
public function processUnsuccessfulPayment(\Exception $exception): void
{
PaymentFailureMailer::dispatch(
$this->mollie->client,
$exception->getMessage(),
$this->mollie->client->company,
$this->mollie->payment_hash->data->amount_with_fee
);
$this->mollie->sendFailureMail($exception->getMessage());
SystemLogger::dispatch(
$exception->getMessage(),

View File

@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -81,7 +80,7 @@ class BankTransfer implements MethodInterface
'currency' => $this->mollie->client->currency()->code,
'value' => $this->mollie->convertToMollieAmount((float) $this->mollie->payment_hash->data->amount_with_fee),
],
'description' => \sprintf('Invoices: %s', collect($data['invoices'])->pluck('invoice_number')),
'description' => \sprintf('%s: %s', ctrans('texts.invoices'), \implode(', ', collect($data['invoices'])->pluck('invoice_number')->toArray())),
'redirectUrl' => route('client.payments.response', [
'company_gateway_id' => $this->mollie->company_gateway->id,
'payment_hash' => $this->mollie->payment_hash->hash,
@ -112,12 +111,8 @@ class BankTransfer implements MethodInterface
*/
public function processUnsuccessfulPayment(\Exception $e): void
{
PaymentFailureMailer::dispatch(
$this->mollie->client,
$e->getMessage(),
$this->mollie->client->company,
$this->mollie->payment_hash->data->amount_with_fee
);
$this->mollie->sendFailureMail($e->getMessage());
SystemLogger::dispatch(
$e->getMessage(),

View File

@ -4,7 +4,6 @@ namespace App\PaymentDrivers\Mollie;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -88,6 +87,8 @@ class CreditCard
return redirect($payment->getCheckoutUrl());
}
} catch (\Exception $e) {
return $this->processUnsuccessfulPayment($e);
}
}
@ -142,6 +143,7 @@ class CreditCard
return redirect($payment->getCheckoutUrl());
}
} catch (\Exception $e) {
$this->processUnsuccessfulPayment($e);
throw new PaymentFailed($e->getMessage(), $e->getCode());
@ -196,12 +198,8 @@ class CreditCard
public function processUnsuccessfulPayment(\Exception $e)
{
PaymentFailureMailer::dispatch(
$this->mollie->client,
$e->getMessage(),
$this->mollie->client->company,
$this->mollie->payment_hash->data->amount_with_fee
);
$this->mollie->sendFailureMail($e->getMessage());
SystemLogger::dispatch(
$e->getMessage(),

View File

@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -78,7 +77,7 @@ class IDEAL implements MethodInterface
'currency' => $this->mollie->client->currency()->code,
'value' => $this->mollie->convertToMollieAmount((float) $this->mollie->payment_hash->data->amount_with_fee),
],
'description' => \sprintf('Invoices: %s', collect($data['invoices'])->pluck('invoice_number')),
'description' => \sprintf('%s: %s', ctrans('texts.invoices'), \implode(', ', collect($data['invoices'])->pluck('invoice_number')->toArray())),
'redirectUrl' => route('client.payments.response', [
'company_gateway_id' => $this->mollie->company_gateway->id,
'payment_hash' => $this->mollie->payment_hash->hash,
@ -109,12 +108,8 @@ class IDEAL implements MethodInterface
*/
public function processUnsuccessfulPayment(\Exception $exception): void
{
PaymentFailureMailer::dispatch(
$this->mollie->client,
$exception->getMessage(),
$this->mollie->client->company,
$this->mollie->payment_hash->data->amount_with_fee
);
$this->mollie->sendFailureMail($exception->getMessage());
SystemLogger::dispatch(
$exception->getMessage(),

View File

@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\Request;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -78,7 +77,7 @@ class KBC implements MethodInterface
'currency' => $this->mollie->client->currency()->code,
'value' => $this->mollie->convertToMollieAmount((float) $this->mollie->payment_hash->data->amount_with_fee),
],
'description' => \sprintf('Invoices: %s', collect($data['invoices'])->pluck('invoice_number')),
'description' => \sprintf('%s: %s', ctrans('texts.invoices'), \implode(', ', collect($data['invoices'])->pluck('invoice_number')->toArray())),
'redirectUrl' => route('client.payments.response', [
'company_gateway_id' => $this->mollie->company_gateway->id,
'payment_hash' => $this->mollie->payment_hash->hash,
@ -109,12 +108,8 @@ class KBC implements MethodInterface
*/
public function processUnsuccessfulPayment(\Exception $exception): void
{
PaymentFailureMailer::dispatch(
$this->mollie->client,
$exception->getMessage(),
$this->mollie->client->company,
$this->mollie->payment_hash->data->amount_with_fee
);
$this->mollie->sendFailureMail($exception->getMessage());
SystemLogger::dispatch(
$exception->getMessage(),

View File

@ -15,7 +15,6 @@ namespace App\PaymentDrivers;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest;
use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -247,12 +246,7 @@ class MolliePaymentDriver extends BaseDriver
$this->unWindGatewayFees($payment_hash);
PaymentFailureMailer::dispatch(
$this->client,
$payment->details,
$this->client->company,
$amount
);
$this->sendFailureMail($payment->details);
$message = [
'server_response' => $payment,

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\PayFast;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -253,14 +252,7 @@ class CreditCard
private function processUnsuccessfulPayment($server_response)
{
PaymentFailureMailer::dispatch($this->payfast->client, $server_response->cancellation_reason, $this->payfast->client->company, $server_response->amount);
PaymentFailureMailer::dispatch(
$this->payfast->client,
$server_response,
$this->payfast->client->company,
$server_response['amount_gross']
);
$this->payfast->sendFailureMail($server_response->cancellation_reason);
$message = [
'server_response' => $server_response,

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\PayFast;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -32,45 +31,11 @@ class Token
public $payfast;
//https://api.payfast.co.za/subscriptions/dc0521d3-55fe-269b-fa00-b647310d760f/adhoc
public function __construct(PayFastPaymentDriver $payfast)
{
$this->payfast = $payfast;
}
// Attributes
// merchant-id
// integer, 8 char | REQUIRED
// Header, the Merchant ID as given by the PayFast system.
// version
// string | REQUIRED
// Header, the PayFast API version (i.e. v1).
// timestamp
// ISO-8601 date and time | REQUIRED
// Header, the current timestamp (YYYY-MM-DDTHH:MM:SS[+HH:MM]).
// signature
// string | REQUIRED
// Header, MD5 hash of the alphabetised submitted header and body variables, as well as the passphrase. Characters must be in lower case.
// amount
// integer | REQUIRED
// Body, the amount which the buyer must pay, in cents (ZAR), no decimals.
// item_name
// string, 100 char | REQUIRED
// Body, the name of the item being charged for.
// item_description
// string, 255 char | OPTIONAL
// Body, the description of the item being charged for.
// itn
// boolean | OPTIONAL
// Body, specify whether an ITN must be sent for the tokenization payment (true by default).
// m_payment_id
// string, 100 char | OPTIONAL
// Body, unique payment ID on the merchants system.
// cc_cvv
// numeric | OPTIONAL
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
@ -90,73 +55,12 @@ class Token
'm_payment_id' => $payment_hash->hash,
];
nlog(array_merge($body, $header));
// $header['signature'] = md5( $this->generate_parameter_string(array_merge($header, $body), false) );
$header['signature'] = $this->payfast->generateTokenSignature(array_merge($body, $header));
nlog($header['signature']);
$result = $this->send($header, $body, $cgt->token);
nlog($result);
// $api = new \PayFast\PayFastApi(
// [
// 'merchantId' => $this->payfast->company_gateway->getConfigField('merchantId'),
// 'passPhrase' => $this->payfast->company_gateway->getConfigField('passPhrase'),
// 'testMode' => $this->payfast->company_gateway->getConfigField('testMode')
// ]
// );
// $adhocArray = $api
// ->subscriptions
// ->adhoc($cgt->token, ['amount' => $amount, 'item_name' => 'purchase']);
// nlog($adhocArray);
// /*Refactor and push to BaseDriver*/
// if ($data['response'] != null && $data['response']->getMessages()->getResultCode() == 'Ok') {
// $response = $data['response'];
// $this->storePayment($payment_hash, $data);
// $vars = [
// 'invoices' => $payment_hash->invoices(),
// 'amount' => $amount,
// ];
// $logger_message = [
// 'server_response' => $response->getTransactionResponse()->getTransId(),
// 'data' => $this->formatGatewayResponse($data, $vars),
// ];
// SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_AUTHORIZE, $this->authorize->client, $this->authorize->client->company);
// return true;
// } else {
// $vars = [
// 'invoices' => $payment_hash->invoices(),
// 'amount' => $amount,
// ];
// $logger_message = [
// 'server_response' => $response->getTransactionResponse()->getTransId(),
// 'data' => $this->formatGatewayResponse($data, $vars),
// ];
// PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransactionResponse()->getTransId(), $this->authorize->client->company, $amount);
// SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_AUTHORIZE, $this->authorize->client, $this->authorize->client->company);
// return false;
// }
}
protected function generate_parameter_string( $api_data, $sort_data_before_merge = true, $skip_empty_values = true ) {

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Invoice;
@ -94,7 +93,7 @@ class PayPalExpressPaymentDriver extends BaseDriver
return $response->redirect();
}
PaymentFailureMailer::dispatch($this->client, $response->getData(), $this->client->company, $data['total']['amount_with_fee']);
$this->sendFailureMail($response->getData());
$message = [
'server_response' => $response->getMessage(),
@ -152,7 +151,7 @@ class PayPalExpressPaymentDriver extends BaseDriver
$data = $response->getData();
PaymentFailureMailer::dispatch($this->client, $response->getMessage(), $this->client->company, $this->payment_hash->data->amount);
$this->sendFailureMail($response->getMessage());
$message = [
'server_response' => $data['L_LONGMESSAGE0'],

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\PayTrace;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;

View File

@ -16,7 +16,6 @@ namespace App\PaymentDrivers\Razorpay;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -106,6 +105,9 @@ class Hosted implements MethodInterface
]);
if (! property_exists($this->razorpay->payment_hash->data, 'order_id')) {
$this->razorpay->sendFailureMail("Missing [order_id] property. ");
throw new PaymentFailed('Missing [order_id] property. Please contact the administrator. Reference: ' . $this->razorpay->payment_hash->hash);
}
@ -163,12 +165,8 @@ class Hosted implements MethodInterface
*/
public function processUnsuccessfulPayment(\Exception $exception): void
{
PaymentFailureMailer::dispatch(
$this->razorpay->client,
$exception->getMessage(),
$this->razorpay->client->company,
$this->razorpay->payment_hash->data->amount_with_fee
);
$this->razorpay->sendFailureMail($exception->getMessage());
SystemLogger::dispatch(
$exception->getMessage(),
@ -180,5 +178,6 @@ class Hosted implements MethodInterface
);
throw new PaymentFailed($exception->getMessage(), $exception->getCode());
}
}

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Sample;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;

View File

@ -12,7 +12,6 @@
namespace App\PaymentDrivers;
use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -167,12 +166,7 @@ class SquarePaymentDriver extends BaseDriver
$this->unWindGatewayFees($payment_hash);
PaymentFailureMailer::dispatch(
$this->client,
$body->errors[0]->detail,
$this->client->company,
$amount
);
$this->sendFailureMail($body->errors[0]->detail);
$message = [
'server_response' => $response,

View File

@ -17,7 +17,6 @@ use App\Http\Requests\ClientPortal\PaymentMethod\VerifyPaymentMethodRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Mail\Gateways\ACHVerificationNotification;
use App\Models\ClientGatewayToken;
@ -194,7 +193,7 @@ class ACH
return $this->processUnsuccessfulPayment($state);
} catch (Exception $e) {
if ($e instanceof CardException) {
return redirect()->route('client.payment_methods.verification', ['payment_method' => $source->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
return redirect()->route('client.payment_methods.verification', ['payment_method' => $cgt->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
}
throw new PaymentFailed($e->getMessage(), $e->getCode());
@ -290,13 +289,7 @@ class ACH
public function processUnsuccessfulPayment($state)
{
PaymentFailureMailer::dispatch(
$this->stripe->client,
$state['charge'],
$this->stripe->client->company,
$state['amount']
);
$this->stripe->sendFailureMail($state['charge']);
$message = [
'server_response' => $state['charge'],

View File

@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -98,14 +97,7 @@ class Alipay
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch($this->stripe->client, $server_response->redirect_status, $this->stripe->client->company, $server_response->amount);
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response->redirect_status);
$message = [
'server_response' => $server_response,

View File

@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -119,12 +118,7 @@ class Bancontact
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response);
$message = [
'server_response' => $server_response,

View File

@ -81,12 +81,7 @@ class Charge
'description' => $description,
];
nlog("Stripe tokenBilling payload");
nlog($data);
$response = $this->stripe->createPaymentIntent($data, $this->stripe->stripe_connect_auth);
// $response = $local_stripe->paymentIntents->create($data);
SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client, $this->stripe->client->company);
} catch (\Exception $e) {
@ -136,7 +131,6 @@ class Charge
}
$payment_method_type = $response->charges->data[0]->payment_method_details->card->brand;
//nlog($payment_method_type);
$data = [
'gateway_type_id' => $cgt->gateway_type_id,
@ -184,302 +178,3 @@ class Charge
}
}
}
// const CREDIT = 1;
// const ACH = 4;
// const VISA = 5;
// const MASTERCARD = 6;
// const AMERICAN_EXPRESS = 7;
// const DISCOVER = 8;
// const DINERS = 9;
// const EUROCARD = 10;
// const NOVA = 11;
// const CREDIT_CARD_OTHER = 12;
// const PAYPAL = 13;
// const CARTE_BLANCHE = 16;
// const UNIONPAY = 17;
// const JCB = 18;
// const LASER = 19;
// const MAESTRO = 20;
// const SOLO = 21;
// const SWITCH = 22;
// const ALIPAY = 27;
// const SOFORT = 28;
// const SEPA = 29;
// const GOCARDLESS = 30;
// const CRYPTO = 31;
// {
// "id": "ch_1H4lp42eZvKYlo2Ch5igaUwg",
// "object": "charge",
// "amount": 2000,
// "amount_refunded": 0,
// "application": null,
// "application_fee": null,
// "application_fee_amount": null,
// "balance_transaction": "txn_19XJJ02eZvKYlo2ClwuJ1rbA",
// "billing_details": {
// "address": {
// "city": null,
// "country": null,
// "line1": null,
// "line2": null,
// "postal_code": "45465",
// "state": null
// },
// "email": null,
// "name": null,
// "phone": null
// },
// "calculated_statement_descriptor": null,
// "captured": false,
// "created": 1594724238,
// "currency": "usd",
// "customer": null,
// "description": "My First Test Charge (created for API docs)",
// "disputed": false,
// "failure_code": null,
// "failure_message": null,
// "fraud_details": {},
// "invoice": null,
// "livemode": false,
// "metadata": {},
// "on_behalf_of": null,
// "order": null,
// "outcome": null,
// "paid": true,
// "payment_intent": null,
// "payment_method": "card_1F8MLI2eZvKYlo2CvsyCzps2",
// "payment_method_details": {
// "card": {
// "brand": "visa",
// "checks": {
// "address_line1_check": null,
// "address_postal_code_check": "pass",
// "cvc_check": null
// },
// "country": "US",
// "exp_month": 12,
// "exp_year": 2023,
// "fingerprint": "Xt5EWLLDS7FJjR1c",
// "funding": "credit",
// "installments": null,
// "last4": "4242",
// "network": "visa",
// "three_d_secure": null,
// "wallet": null
// },
// "type": "card"
// },
// "receipt_email": null,
// "receipt_number": null,
// "receipt_url": "https://pay.stripe.com/receipts/acct_1032D82eZvKYlo2C/ch_1H4lp42eZvKYlo2Ch5igaUwg/rcpt_He3wuRQtzvT2Oi4OAYQSpajtmteo55J",
// "refunded": false,
// "refunds": {
// "object": "list",
// "data": [],
// "has_more": false,
// "url": "/v1/charges/ch_1H4lp42eZvKYlo2Ch5igaUwg/refunds"
// },
// "review": null,
// "shipping": null,
// "source_transfer": null,
// "statement_descriptor": null,
// "statement_descriptor_suffix": null,
// "status": "succeeded",
// "transfer_data": null,
// "transfer_group": null,
// "source": "tok_visa"
// }
//
//
// [2020-07-14 23:06:47] local.INFO: Stripe\PaymentIntent Object
// (
// [id] => pi_1H4xD0Kmol8YQE9DKhrvV6Nc
// [object] => payment_intent
// [allowed_source_types] => Array
// (
// [0] => card
// )
// [amount] => 1000
// [amount_capturable] => 0
// [amount_received] => 1000
// [application] =>
// [application_fee_amount] =>
// [canceled_at] =>
// [cancellation_reason] =>
// [capture_method] => automatic
// [charges] => Stripe\Collection Object
// (
// [object] => list
// [data] => Array
// (
// [0] => Stripe\Charge Object
// (
// [id] => ch_1H4xD0Kmol8YQE9Ds9b1ZWjw
// [object] => charge
// [amount] => 1000
// [amount_refunded] => 0
// [application] =>
// [application_fee] =>
// [application_fee_amount] =>
// [balance_transaction] => txn_1H4xD1Kmol8YQE9DE9qFoO0R
// [billing_details] => Stripe\StripeObject Object
// (
// [address] => Stripe\StripeObject Object
// (
// [city] =>
// [country] =>
// [line1] =>
// [line2] =>
// [postal_code] => 42334
// [state] =>
// )
// [email] =>
// [name] => sds
// [phone] =>
// )
// [calculated_statement_descriptor] => NODDY
// [captured] => 1
// [created] => 1594768006
// [currency] => usd
// [customer] => cus_He4VEiYldHJWqG
// [description] => Invoice 0023 for 10 for client Corwin Group
// [destination] =>
// [dispute] =>
// [disputed] =>
// [failure_code] =>
// [failure_message] =>
// [fraud_details] => Array
// (
// )
// [invoice] =>
// [livemode] =>
// [metadata] => Stripe\StripeObject Object
// (
// )
// [on_behalf_of] =>
// [order] =>
// [outcome] => Stripe\StripeObject Object
// (
// [network_status] => approved_by_network
// [reason] =>
// [risk_level] => normal
// [risk_score] => 13
// [seller_message] => Payment complete.
// [type] => authorized
// )
// [paid] => 1
// [payment_intent] => pi_1H4xD0Kmol8YQE9DKhrvV6Nc
// [payment_method] => pm_1H4mNAKmol8YQE9DUMRsuTXs
// [payment_method_details] => Stripe\StripeObject Object
// (
// [card] => Stripe\StripeObject Object
// (
// [brand] => visa
// [checks] => Stripe\StripeObject Object
// (
// [address_line1_check] =>
// [address_postal_code_check] => pass
// [cvc_check] =>
// )
// [country] => US
// [exp_month] => 4
// [exp_year] => 2024
// [fingerprint] => oCjEXlb4syFKwgbJ
// [funding] => credit
// [installments] =>
// [last4] => 4242
// [network] => visa
// [three_d_secure] =>
// [wallet] =>
// )
// [type] => card
// )
// [receipt_email] =>
// [receipt_number] =>
// [receipt_url] => https://pay.stripe.com/receipts/acct_19DXXPKmol8YQE9D/ch_1H4xD0Kmol8YQE9Ds9b1ZWjw/rcpt_HeFiiwzRZtnOpvHyohNN5JXtCYe8Rdc
// [refunded] =>
// [refunds] => Stripe\Collection Object
// (
// [object] => list
// [data] => Array
// (
// )
// [has_more] =>
// [total_count] => 0
// [url] => /v1/charges/ch_1H4xD0Kmol8YQE9Ds9b1ZWjw/refunds
// )
// [review] =>
// [shipping] =>
// [source] =>
// [source_transfer] =>
// [statement_descriptor] =>
// [statement_descriptor_suffix] =>
// [status] => succeeded
// [transfer_data] =>
// [transfer_group] =>
// )
// )
// [has_more] =>
// [total_count] => 1
// [url] => /v1/charges?payment_intent=pi_1H4xD0Kmol8YQE9DKhrvV6Nc
// )
// [client_secret] => pi_1H4xD0Kmol8YQE9DKhrvV6Nc_secret_TyE8n3Y3oaMqgqQvXvtKDOnYT
// [confirmation_method] => automatic
// [created] => 1594768006
// [currency] => usd
// [customer] => cus_He4VEiYldHJWqG
// [description] => Invoice 0023 for 10 for client Corwin Group
// [invoice] =>
// [last_payment_error] =>
// [livemode] =>
// [metadata] => Stripe\StripeObject Object
// (
// )
// [next_action] =>
// [next_source_action] =>
// [on_behalf_of] =>
// [payment_method] => pm_1H4mNAKmol8YQE9DUMRsuTXs
// [payment_method_options] => Stripe\StripeObject Object
// (
// [card] => Stripe\StripeObject Object
// (
// [installments] =>
// [network] =>
// [request_three_d_secure] => automatic
// )
// )
// [payment_method_types] => Array
// (
// [0] => card
// )
// [receipt_email] =>
// [review] =>
// [setup_future_usage] =>
// [shipping] =>
// [source] =>
// [statement_descriptor] =>
// [statement_descriptor_suffix] =>
// [status] => succeeded
// [transfer_data] =>
// [transfer_group] =>
// )

View File

@ -18,7 +18,6 @@ use App\Http\Requests\ClientPortal\PaymentMethod\VerifyPaymentMethodRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Mail\Gateways\ACHVerificationNotification;
use App\Models\ClientGatewayToken;

View File

@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -160,14 +159,7 @@ class CreditCard
public function processUnsuccessfulPayment($server_response)
{
PaymentFailureMailer::dispatch($this->stripe->client, $server_response->cancellation_reason, $this->stripe->client->company, $server_response->amount);
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$server_response->amount
);
$this->stripe->sendFailureMail($server_response->cancellation_reason);
$message = [
'server_response' => $server_response,

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -119,12 +118,7 @@ class EPS
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response);
$message = [
'server_response' => $server_response,

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -119,12 +118,7 @@ class GIROPAY
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response);
$message = [
'server_response' => $server_response,

View File

@ -162,7 +162,7 @@ class ImportCustomers
if(strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1)
throw new StripeConnectFailure('Stripe Connect has not been configured');
$customer = Customer::retrieve($customer_id, $this->stripe_connect_auth);
$customer = Customer::retrieve($customer_id, $this->stripe->stripe_connect_auth);
if(!$customer)
return;

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -119,12 +118,7 @@ class PRZELEWY24
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response);
$message = [
'server_response' => $server_response,

View File

@ -11,15 +11,14 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\PaymentDrivers\StripePaymentDriver;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\Exceptions\PaymentFailed;
use App\PaymentDrivers\StripePaymentDriver;
class SEPA
{
@ -29,6 +28,8 @@ class SEPA
public function __construct(StripePaymentDriver $stripe)
{
$this->stripe = $stripe;
$this->stripe->init();
}
public function authorizeView($data)
@ -36,7 +37,8 @@ class SEPA
return render('gateways.stripe.sepa.authorize', $data);
}
public function paymentView(array $data) {
public function paymentView(array $data)
{
$data['gateway'] = $this->stripe;
$data['payment_method_id'] = GatewayType::SEPA;
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
@ -52,11 +54,19 @@ class SEPA
'setup_future_usage' => 'off_session',
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')),
]);
$data['pi_client_secret'] = $intent->client_secret;
if (count($data['tokens']) > 0) {
$setup_intent = $this->stripe->stripe->setupIntents->create([
'payment_method_types' => ['sepa_debit'],
'customer' => $this->stripe->findOrCreateCustomer()->id,
]);
$data['si_client_secret'] = $setup_intent->client_secret;
}
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
@ -65,28 +75,24 @@ class SEPA
public function paymentResponse(PaymentResponseRequest $request)
{
$gateway_response = json_decode($request->gateway_response);
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all());
$this->stripe->payment_hash->save();
if (property_exists($gateway_response, 'status') && $gateway_response->status == 'processing') {
$this->stripe->init();
$this->storePaymentMethod($gateway_response);
if (property_exists($gateway_response, 'status') && ($gateway_response->status == 'processing' || $gateway_response->status === 'succeeded')) {
if ($request->store_card) {
$this->storePaymentMethod($gateway_response);
}
return $this->processSuccessfulPayment($gateway_response->id);
}
return $this->processUnsuccessfulPayment();
}
public function processSuccessfulPayment(string $payment_intent)
{
$this->stripe->init();
$data = [
'payment_method' => $payment_intent,
'payment_type' => PaymentType::SEPA,
@ -95,7 +101,7 @@ class SEPA
'gateway_type_id' => GatewayType::SEPA,
];
$this->stripe->createPayment($data, Payment::STATUS_PENDING);
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
SystemLogger::dispatch(
['response' => $this->stripe->payment_hash->data, 'data' => $data],
@ -106,19 +112,14 @@ class SEPA
$this->stripe->client->company,
);
return redirect()->route('client.payments.index');
return redirect()->route('client.payments.show', $payment->hashed_id);
}
public function processUnsuccessfulPayment()
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response);
$message = [
'server_response' => $server_response,
@ -141,7 +142,6 @@ class SEPA
private function storePaymentMethod($intent)
{
try {
$method = $this->stripe->getStripePaymentMethod($intent->payment_method);
$payment_meta = new \stdClass;

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -115,12 +114,7 @@ class SOFORT
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response);
$message = [
'server_response' => $server_response,

View File

@ -13,7 +13,6 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -119,12 +118,7 @@ class iDeal
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$this->stripe->sendFailureMail($server_response);
$message = [
'server_response' => $server_response,

View File

@ -13,9 +13,11 @@
namespace App\PaymentDrivers\WePay;
use App\Exceptions\PaymentFailed;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\SystemLog;
use App\PaymentDrivers\WePayPaymentDriver;
use App\PaymentDrivers\WePay\WePayCommon;
use App\Utils\Traits\MakesHash;
@ -68,6 +70,23 @@ class ACH
]);
}
catch(\Exception $e){
$this->wepay_payment_driver->sendFailureMail($e->getMessage());
$message = [
'server_response' => $e->getMessage(),
'data' => $this->wepay_payment_driver->payment_hash->data,
];
SystemLogger::dispatch(
$e->getMessage(),
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_WEPAY,
$this->wepay_payment_driver->client,
$this->wepay_payment_driver->client->company,
);
throw new PaymentFailed($e->getMessage(), 400);
}
// display the response

View File

@ -14,7 +14,6 @@ namespace App\PaymentDrivers\WePay;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
@ -153,24 +152,48 @@ use WePayCommon;
$app_fee = (config('ninja.wepay.fee_cc_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed');
// charge the credit card
$response = $this->wepay_payment_driver->wepay->request('checkout/create', array(
'unique_id' => Str::random(40),
'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'),
'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee,
'currency' => $this->wepay_payment_driver->client->getCurrencyCode(),
'short_description' => 'Goods and services',
'type' => 'goods',
'fee' => [
'fee_payer' => config('ninja.wepay.fee_payer'),
'app_fee' => $app_fee,
],
'payment_method' => array(
'type' => 'credit_card',
'credit_card' => array(
'id' => $credit_card_id
try {
$response = $this->wepay_payment_driver->wepay->request('checkout/create', array(
'unique_id' => Str::random(40),
'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'),
'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee,
'currency' => $this->wepay_payment_driver->client->getCurrencyCode(),
'short_description' => 'Goods and services',
'type' => 'goods',
'fee' => [
'fee_payer' => config('ninja.wepay.fee_payer'),
'app_fee' => $app_fee,
],
'payment_method' => array(
'type' => 'credit_card',
'credit_card' => array(
'id' => $credit_card_id
)
)
)
));
));
}
catch(\Exception $e){
$this->wepay_payment_driver->sendFailureMail($e->getMessage());
$message = [
'server_response' => $e->getMessage(),
'data' => $this->wepay_payment_driver->payment_hash->data,
];
SystemLogger::dispatch(
$e->getMessage(),
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_WEPAY,
$this->wepay_payment_driver->client,
$this->wepay_payment_driver->client->company,
);
throw new PaymentFailed($e->getMessage(), 500);
}
/* Merge all data and store in the payment hash*/
$state = [

View File

@ -12,7 +12,6 @@
namespace App\PaymentDrivers\WePay;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\PaymentType;
@ -21,7 +20,6 @@ use App\Models\SystemLog;
trait WePayCommon
{
private function processSuccessfulPayment($response, $payment_status, $gateway_type, $return_payment = false)
{
@ -56,14 +54,7 @@ trait WePayCommon
private function processUnSuccessfulPayment($response, $payment_status)
{
PaymentFailureMailer::dispatch($this->wepay_payment_driver->client, $response->state, $this->wepay_payment_driver->client->company, $response->amount);
PaymentFailureMailer::dispatch(
$this->wepay_payment_driver->client,
$response,
$this->wepay_payment_driver->client->company,
$response->gross
);
$this->wepay_payment_driver->sendFailureMail($response->state);
$message = [
'server_response' => $response,

View File

@ -12,36 +12,8 @@
namespace App\Providers;
use App\Http\Middleware\SetDomainNameDb;
use App\Models\Account;
use App\Models\Client;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyToken;
use App\Models\Credit;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Product;
use App\Models\Proposal;
use App\Models\Quote;
use App\Models\Subscription;
use App\Models\Task;
use App\Models\User;
use App\Observers\AccountObserver;
use App\Observers\ClientObserver;
use App\Observers\CompanyGatewayObserver;
use App\Observers\CompanyObserver;
use App\Observers\CompanyTokenObserver;
use App\Observers\CreditObserver;
use App\Observers\ExpenseObserver;
use App\Observers\InvoiceObserver;
use App\Observers\PaymentObserver;
use App\Observers\ProductObserver;
use App\Observers\ProposalObserver;
use App\Observers\QuoteObserver;
use App\Observers\SubscriptionObserver;
use App\Observers\TaskObserver;
use App\Observers\UserObserver;
use App\Utils\Ninja;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Database\Eloquent\Relations\Relation;
@ -80,23 +52,6 @@ class AppServiceProvider extends ServiceProvider
Schema::defaultStringLength(191);
Account::observe(AccountObserver::class);
Subscription::observe(SubscriptionObserver::class);
Client::observe(ClientObserver::class);
Company::observe(CompanyObserver::class);
CompanyGateway::observe(CompanyGatewayObserver::class);
CompanyToken::observe(CompanyTokenObserver::class);
Credit::observe(CreditObserver::class);
Expense::observe(ExpenseObserver::class);
Invoice::observe(InvoiceObserver::class);
Payment::observe(PaymentObserver::class);
Product::observe(ProductObserver::class);
Proposal::observe(ProposalObserver::class);
Quote::observe(QuoteObserver::class);
Task::observe(TaskObserver::class);
User::observe(UserObserver::class);
/* Handles setting the correct database with livewire classes */
if(Ninja::isHosted())
{

View File

@ -202,6 +202,36 @@ use App\Listeners\User\DeletedUserActivity;
use App\Listeners\User\RestoredUserActivity;
use App\Listeners\User\UpdateUserLastLogin;
use App\Listeners\User\UpdatedUserActivity;
use App\Models\Account;
use App\Models\Client;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyToken;
use App\Models\Credit;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Product;
use App\Models\Proposal;
use App\Models\Quote;
use App\Models\Subscription;
use App\Models\Task;
use App\Models\User;
use App\Observers\AccountObserver;
use App\Observers\ClientObserver;
use App\Observers\CompanyGatewayObserver;
use App\Observers\CompanyObserver;
use App\Observers\CompanyTokenObserver;
use App\Observers\CreditObserver;
use App\Observers\ExpenseObserver;
use App\Observers\InvoiceObserver;
use App\Observers\PaymentObserver;
use App\Observers\ProductObserver;
use App\Observers\ProposalObserver;
use App\Observers\QuoteObserver;
use App\Observers\SubscriptionObserver;
use App\Observers\TaskObserver;
use App\Observers\UserObserver;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Mail\Events\MessageSending;
use Illuminate\Mail\Events\MessageSent;
@ -542,5 +572,21 @@ class EventServiceProvider extends ServiceProvider
public function boot()
{
parent::boot();
Account::observe(AccountObserver::class);
Subscription::observe(SubscriptionObserver::class);
Client::observe(ClientObserver::class);
Company::observe(CompanyObserver::class);
CompanyGateway::observe(CompanyGatewayObserver::class);
CompanyToken::observe(CompanyTokenObserver::class);
Credit::observe(CreditObserver::class);
Expense::observe(ExpenseObserver::class);
Invoice::observe(InvoiceObserver::class);
Payment::observe(PaymentObserver::class);
Product::observe(ProductObserver::class);
Proposal::observe(ProposalObserver::class);
Quote::observe(QuoteObserver::class);
Task::observe(TaskObserver::class);
User::observe(UserObserver::class);
}
}

View File

@ -81,7 +81,8 @@ class ActivityRepository extends BaseRepository
|| get_class($entity) == Credit::class
|| get_class($entity) == RecurringInvoice::class
) {
$entity->load('company', 'client');
$entity->load('client');
$contact = $entity->client->primary_contact()->first();
$backup->html_backup = $this->generateHtml($entity);
$backup->amount = $entity->amount;
@ -95,7 +96,7 @@ class ActivityRepository extends BaseRepository
public function getTokenId(array $event_vars)
{
if ($event_vars['token']) {
$company_token = CompanyToken::whereRaw('BINARY `token`= ?', [$event_vars['token']])->first();
$company_token = CompanyToken::where('token', $event_vars['token'])->first();
if ($company_token) {
return $company_token->id;
@ -117,7 +118,7 @@ class ActivityRepository extends BaseRepository
$entity_design_id = 'credit_design_id';
}
$entity->load('client','client.company');
// $entity->load('client.company');
$entity_design_id = $entity->design_id ? $entity->design_id : $this->decodePrimaryKey($entity->client->getSetting($entity_design_id));
@ -128,6 +129,8 @@ class ActivityRepository extends BaseRepository
return;
}
$entity->load('client.company', 'invitations');
$html = new HtmlEngine($entity->invitations->first());
if ($design->is_custom) {

View File

@ -239,7 +239,7 @@ class BaseRepository
/* Get array of Keys which have been removed from the invitations array and soft delete each invitation */
$model->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) use ($resource) {
$invitation_class = sprintf('App\\Models\\%sInvitation', $resource);
$invitation = $invitation_class::whereRaw('BINARY `key`= ?', [$invitation])->first();
$invitation = $invitation_class::where('key', $invitation)->first();
if ($invitation)
$invitation->delete();
@ -276,6 +276,7 @@ class BaseRepository
$new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id);
$new_invitation->{$lcfirst_resource_id} = $model->id;
$new_invitation->client_contact_id = $contact->id;
$new_invitation->key = $this->createDbHash(config('database.default'));
$new_invitation->save();
}
@ -326,6 +327,8 @@ class BaseRepository
if($this->new_model)
event('eloquent.created: App\Models\Invoice', $model);
else
event('eloquent.updated: App\Models\Invoice', $model);
}
@ -339,6 +342,9 @@ class BaseRepository
if($this->new_model)
event('eloquent.created: App\Models\Credit', $model);
else
event('eloquent.updated: App\Models\Credit', $model);
}
if ($model instanceof Quote) {
@ -351,7 +357,8 @@ class BaseRepository
if($this->new_model)
event('eloquent.created: App\Models\Quote', $model);
else
event('eloquent.updated: App\Models\Quote', $model);
}
if ($model instanceof RecurringInvoice) {
@ -364,6 +371,8 @@ class BaseRepository
if($this->new_model)
event('eloquent.created: App\Models\RecurringInvoice', $model);
else
event('eloquent.updated: App\Models\RecurringInvoice', $model);
}
$model->save();

View File

@ -107,7 +107,7 @@ class PaymentMigrationRepository extends BaseRepository
/*Ensure payment number generated*/
if (! $payment->number || strlen($payment->number) == 0) {
$payment->number = $payment->client->getNextPaymentNumber($payment->client);
$payment->number = $payment->client->getNextPaymentNumber($payment->client, $payment);
}
$invoice_totals = 0;

View File

@ -89,11 +89,11 @@ class PaymentRepository extends BaseRepository {
if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) {
$_credit_totals = array_sum(array_column($data['credits'], 'amount'));
if ($data['amount'] == $_credit_totals) {
$data['amount'] = 0;
} else {
// if ($data['amount'] == $_credit_totals) {
// $data['amount'] = 0;
// } else {
$client->service()->updatePaidToDate($_credit_totals)->save();
}
// }
}
}
@ -111,7 +111,7 @@ class PaymentRepository extends BaseRepository {
/*Ensure payment number generated*/
if (! $payment->number || strlen($payment->number) == 0) {
$payment->number = $payment->client->getNextPaymentNumber($payment->client);
$payment->number = $payment->client->getNextPaymentNumber($payment->client, $payment);
}
/*Set local total variables*/
@ -170,11 +170,6 @@ class PaymentRepository extends BaseRepository {
event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null) ) );
}
// nlog("payment amount = {$payment->amount}");
// nlog("payment applied = {$payment->applied}");
// nlog("invoice totals = {$invoice_totals}");
// nlog("credit totals = {$credit_totals}");
$payment->applied += ($invoice_totals - $credit_totals); //wont work because - check tests
// $payment->applied += $invoice_totals; //wont work because - check tests

View File

@ -73,7 +73,7 @@ class Statement
$state = [
'template' => $template->elements([
'client' => $this->entity->client,
'client' => $this->client,
'entity' => $this->entity,
'pdf_variables' => (array)$this->entity->company->settings->pdf_variables,
'$product' => $this->getDesign()->design->product,
@ -219,7 +219,9 @@ class Statement
*/
protected function getInvoices(): Collection
{
return Invoice::where('company_id', $this->client->company->id)
return Invoice::withTrashed()
->where('is_deleted', false)
->where('company_id', $this->client->company_id)
->where('client_id', $this->client->id)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID])
->whereBetween('date', [$this->options['start_date'], $this->options['end_date']])
@ -234,7 +236,10 @@ class Statement
*/
protected function getPayments(): Collection
{
return Payment::where('company_id', $this->client->company->id)
return Payment::withTrashed()
->with('client.country','invoices')
->where('is_deleted', false)
->where('company_id', $this->client->company_id)
->where('client_id', $this->client->id)
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
->whereBetween('date', [$this->options['start_date'], $this->options['end_date']])
@ -285,18 +290,16 @@ class Statement
$from = $ranges[0];
$to = $ranges[1];
$client = Client::where('id', $this->client->id)->first();
$amount = Invoice::where('company_id', $this->client->company->id)
->where('client_id', $client->id)
$amount = Invoice::withTrashed()
->where('client_id', $this->client->id)
->where('company_id', $this->client->company_id)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('balance', '>', 0)
->where('is_deleted', 0)
->whereBetween('date', [$to, $from])
->whereBetween('due_date', [$to, $from])
->sum('balance');
return Number::formatMoney($amount, $client);
return Number::formatMoney($amount, $this->client);
}
/**
@ -328,7 +331,7 @@ class Statement
return $ranges;
case '120+':
$ranges[0] = now()->startOfDay()->subDays(120);
$ranges[1] = now()->startOfDay()->subYears(40);
$ranges[1] = now()->startOfDay()->subYears(20);
return $ranges;
default:
$ranges[0] = now()->startOfDay()->subDays(0);

View File

@ -37,7 +37,7 @@ class ApplyNumber extends AbstractService
return $this->credit;
}
$this->credit->number = $this->getNextCreditNumber($this->client);
$this->credit->number = $this->getNextCreditNumber($this->client, $this->credit);
return $this->credit;
}

View File

@ -16,10 +16,13 @@ use App\Factory\CreditInvitationFactory;
use App\Models\Credit;
use App\Models\CreditInvitation;
use App\Services\AbstractService;
use App\Utils\Traits\MakesHash;
use Illuminate\Support\Str;
class CreateInvitations extends AbstractService
{
use MakesHash;
private $credit;
public function __construct(Credit $credit)
@ -46,6 +49,7 @@ class CreateInvitations extends AbstractService
if (! $invitation) {
$ii = CreditInvitationFactory::create($this->credit->company_id, $this->credit->user_id);
$ii->key = $this->createDbHash(config('database.default'));
$ii->credit_id = $this->credit->id;
$ii->client_contact_id = $contact->id;
$ii->save();

View File

@ -58,14 +58,14 @@ class ApplyPaymentAmount extends AbstractService
$payment->amount = $this->amount;
$payment->applied = min($this->amount, $this->invoice->balance);
$payment->number = $this->getNextPaymentNumber($this->invoice->client);
$payment->number = $this->getNextPaymentNumber($this->invoice->client, $payment);
$payment->status_id = Payment::STATUS_COMPLETED;
$payment->client_id = $this->invoice->client_id;
$payment->transaction_reference = ctrans('texts.manual_entry');
$payment->currency_id = $this->invoice->client->getSetting('currency_id');
$payment->is_manual = true;
/* Create a payment relationship to the invoice entity */
$payment->save();
$payment->saveQuietly();
$this->setExchangeRate($payment);
@ -103,6 +103,8 @@ class ApplyPaymentAmount extends AbstractService
$this->invoice->service()->workFlow()->save();
event('eloquent.created: App\Models\Payment', $payment);
return $this->invoice;
}
@ -120,7 +122,7 @@ class ApplyPaymentAmount extends AbstractService
//$payment->exchange_currency_id = $client_currency; // 23/06/2021
$payment->exchange_currency_id = $company_currency;
$payment->save();
$payment->saveQuietly();
}

Some files were not shown because too many files have changed in this diff Show More