Init class variables if they do not exist

This commit is contained in:
David Bomba 2022-01-15 22:08:48 +11:00
parent 9bca3ef170
commit 05cb4be207
3 changed files with 14 additions and 3 deletions

View File

@ -41,7 +41,8 @@ class SessionDomains
Cookie::queue(Cookie::forget('invoice_ninja_session', '/')); Cookie::queue(Cookie::forget('invoice_ninja_session', '/'));
config(['session.domain' => $request->getHost()]); config(['session.domain' => $domain_name]);
} }
return $next($request); return $next($request);

View File

@ -222,7 +222,9 @@ class BaseDriver extends AbstractPaymentDriver
*/ */
public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment
{ {
$this->confirmGatewayFee();
if(in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING]) )
$this->confirmGatewayFee();
/*Never create a payment with a duplicate transaction reference*/ /*Never create a payment with a duplicate transaction reference*/
if(array_key_exists('transaction_reference', $data)){ if(array_key_exists('transaction_reference', $data)){
@ -253,6 +255,10 @@ class BaseDriver extends AbstractPaymentDriver
$payment->client_contact_id = $client_contact_id; $payment->client_contact_id = $client_contact_id;
$payment->saveQuietly(); $payment->saveQuietly();
/* Return early if the payment is no completed or pending*/
if(!in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING]) )
return $payment;
$this->payment_hash->payment_id = $payment->id; $this->payment_hash->payment_id = $payment->id;
$this->payment_hash->save(); $this->payment_hash->save();

View File

@ -312,11 +312,12 @@ class MolliePaymentDriver extends BaseDriver
if($record){ if($record){
$client = $record->client; $client = $record->client;
$this->client = $client;
} }
else{ else{
$client = Client::withTrashed()->find($this->decodePrimaryKey($payment->metadata->client_id)); $client = Client::withTrashed()->find($this->decodePrimaryKey($payment->metadata->client_id));
$this->client = $client;
// sometimes if the user is not returned to the site with a response from Mollie // sometimes if the user is not returned to the site with a response from Mollie
// we may not have a payment record - in these cases we need to re-construct the payment // we may not have a payment record - in these cases we need to re-construct the payment
// record from the meta data in the payment hash. // record from the meta data in the payment hash.
@ -326,6 +327,9 @@ class MolliePaymentDriver extends BaseDriver
/* Harvest Payment Hash*/ /* Harvest Payment Hash*/
$payment_hash = PaymentHash::where('hash', $payment->metadata->hash)->first(); $payment_hash = PaymentHash::where('hash', $payment->metadata->hash)->first();
/* If we are here, then we do not have access to the class payment hash, so lets set it here*/
$this->payment_hash = $payment_hash;
$data = [ $data = [
'gateway_type_id' => $payment->metadata->gateway_type_id, 'gateway_type_id' => $payment->metadata->gateway_type_id,
'amount' => $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total, 'amount' => $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total,