getParent() ref to utilities

This commit is contained in:
Benjamin Beganović 2020-12-07 14:50:30 +01:00
parent fdafc068bb
commit 7818afddf8

View File

@ -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'));
}