From 7818afddf8593458c633f3d02f7e5d4bbd47b733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 7 Dec 2020 14:50:30 +0100 Subject: [PATCH] getParent() ref to utilities --- app/PaymentDrivers/CheckoutCom/Utilities.php | 48 ++++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/app/PaymentDrivers/CheckoutCom/Utilities.php b/app/PaymentDrivers/CheckoutCom/Utilities.php index 455bc838a895..14a5c66c603d 100644 --- a/app/PaymentDrivers/CheckoutCom/Utilities.php +++ b/app/PaymentDrivers/CheckoutCom/Utilities.php @@ -29,6 +29,11 @@ trait Utilities return $this->company_gateway->getConfigField('publicApiKey'); } + public function getParent() + { + return static::class == 'App\PaymentDrivers\CheckoutComPaymentDriver' ? $this : $this->checkout; + } + public function convertToCheckoutAmount($amount, $currency) { $cases = [ @@ -52,42 +57,42 @@ trait Utilities private function processSuccessfulPayment(Payment $_payment) { - if ($this->checkout->payment_hash->data->store_card) { + if ($this->getParent()->payment_hash->data->store_card) { $this->storePaymentMethod($_payment); } $data = [ 'payment_method' => $_payment->source['id'], 'payment_type' => PaymentType::parseCardType(strtolower($_payment->source['scheme'])), - 'amount' => $this->checkout->payment_hash->data->raw_value, + 'amount' => $this->getParent()->payment_hash->data->raw_value, 'transaction_reference' => $_payment->id, ]; - $payment = $this->checkout->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + $payment = $this->getParent()->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); SystemLogger::dispatch( ['response' => $_payment, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_CHECKOUT, - $this->checkout->client + $this->getParent()->client ); - return redirect()->route('client.payments.show', ['payment' => $this->checkout->encodePrimaryKey($payment->id)]); + return redirect()->route('client.payments.show', ['payment' => $this->getParent()->encodePrimaryKey($payment->id)]); } public function processUnsuccessfulPayment(Payment $_payment) { PaymentFailureMailer::dispatch( - $this->checkout->client, + $this->getParent()->client, $_payment, - $this->checkout->client->company, - $this->checkout->payment_hash->data->value + $this->getParent()->client->company, + $this->getParent()->payment_hash->data->value ); $message = [ 'server_response' => $_payment, - 'data' => $this->checkout->payment_hash->data, + 'data' => $this->getParent()->payment_hash->data, ]; SystemLogger::dispatch( @@ -95,7 +100,7 @@ trait Utilities SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_CHECKOUT, - $this->checkout->client + $this->getParent()->client ); throw new PaymentFailed($_payment->status, $_payment->http_code); @@ -103,27 +108,10 @@ trait Utilities private function processPendingPayment(Payment $_payment) { - $data = [ - 'payment_method' => $_payment->source->id, - 'payment_type' => PaymentType::CREDIT_CARD_OTHER, - 'amount' => $this->checkout->payment_hash->data->value, - 'transaction_reference' => $_payment->id, - ]; - - $payment = $this->checkout->createPayment($data, \App\Models\Payment::STATUS_PENDING); - - SystemLogger::dispatch( - ['response' => $_payment, 'data' => $data], - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_SUCCESS, - SystemLog::TYPE_CHECKOUT, - $this->checkout->client - ); - try { return redirect($_payment->_links['redirect']['href']); } catch (Exception $e) { - return $this->processInternallyFailedPayment($this->checkout, $e); + return $this->processInternallyFailedPayment($this->getParent(), $e); } } @@ -140,10 +128,10 @@ trait Utilities $data = [ 'payment_meta' => $payment_meta, 'token' => $response->source['id'], - 'payment_method_id' => $this->checkout->payment_hash->data->payment_method_id, + 'payment_method_id' => $this->getParent()->payment_hash->data->payment_method_id, ]; - return $this->checkout->storePaymentMethod($data); + return $this->getParent()->storePaymentMethod($data); } catch (Exception $e) { session()->flash('message', ctrans('texts.payment_method_saving_failed')); }