Fixes for Payment Webhooks

This commit is contained in:
David Bomba 2021-10-15 18:47:41 +11:00
parent 384642acde
commit c26afd69e2
7 changed files with 23 additions and 10 deletions

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

@ -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();
@ -392,11 +394,9 @@ class BaseDriver extends AbstractPaymentDriver
public function clientPaymentFailureMailer($error)
{
nlog("outside");
if ($this->payment_hash && is_array($this->payment_hash->invoices())) {
nlog("inside");
$nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build());

View File

@ -273,7 +273,9 @@ class BasePaymentDriver
$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();
$payment->saveQuietly();
event('eloquent.created: App\Models\Payment', $payment);
return $payment;
}

View File

@ -65,7 +65,7 @@ class ApplyPaymentAmount extends AbstractService
$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();
}

View File

@ -175,6 +175,8 @@ class AutoBillInvoice extends AbstractService
}
event('eloquent.created: App\Models\Payment', $payment);
$payment->ledger()
->updatePaymentBalance($amount * -1)
->save();
@ -190,6 +192,7 @@ class AutoBillInvoice extends AbstractService
->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}")
->save();
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
return $this->invoice

View File

@ -64,7 +64,7 @@ class MarkPaid extends AbstractService
if((int)$payment_type_id > 0)
$payment->type_id = (int)$payment_type_id;
$payment->save();
$payment->saveQuietly();
$this->setExchangeRate($payment);
@ -73,6 +73,8 @@ class MarkPaid extends AbstractService
'amount' => $payment->amount,
]);
event('eloquent.created: App\Models\Payment', $payment);
$this->invoice->next_send_date = null;
$this->invoice->service()

View File

@ -39,12 +39,14 @@ class PaymentService
$payment->transaction_reference = ctrans('texts.manual_entry');
$payment->currency_id = $invoice->client->getSetting('currency_id');
/* Create a payment relationship to the invoice entity */
$payment->save();
$payment->saveQuietly();
$payment->invoices()->attach($invoice->id, [
'amount' => $payment->amount,
]);
event('eloquent.created: App\Models\Payment', $payment);
return $payment;
}
@ -145,7 +147,7 @@ class PaymentService
public function save()
{
$this->payment->save();
$this->payment->saveQuietly();
return $this->payment->fresh();
}