diff --git a/app/Http/Middleware/SessionDomains.php b/app/Http/Middleware/SessionDomains.php index 5fedfd187bf3..d24ab7955796 100644 --- a/app/Http/Middleware/SessionDomains.php +++ b/app/Http/Middleware/SessionDomains.php @@ -41,7 +41,8 @@ class SessionDomains Cookie::queue(Cookie::forget('invoice_ninja_session', '/')); - config(['session.domain' => $request->getHost()]); + config(['session.domain' => $domain_name]); + } return $next($request); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index a1e3e279eb38..bd232b655d41 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -222,7 +222,9 @@ class BaseDriver extends AbstractPaymentDriver */ 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*/ if(array_key_exists('transaction_reference', $data)){ @@ -253,6 +255,10 @@ class BaseDriver extends AbstractPaymentDriver $payment->client_contact_id = $client_contact_id; $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->save(); diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index 78e6b495c295..4ddccd9fe5cb 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -312,11 +312,12 @@ class MolliePaymentDriver extends BaseDriver if($record){ $client = $record->client; + $this->client = $client; } else{ $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 // 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. @@ -326,6 +327,9 @@ class MolliePaymentDriver extends BaseDriver /* Harvest Payment Hash*/ $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 = [ 'gateway_type_id' => $payment->metadata->gateway_type_id, 'amount' => $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total,