diff --git a/app/PaymentDrivers/CheckoutCom/Utilities.php b/app/PaymentDrivers/CheckoutCom/Utilities.php index 2ac8e27b8c..62d5676a3a 100644 --- a/app/PaymentDrivers/CheckoutCom/Utilities.php +++ b/app/PaymentDrivers/CheckoutCom/Utilities.php @@ -55,7 +55,7 @@ trait Utilities return round($amount * 100); } - private function processSuccessfulPayment(Payment $_payment, $return_payment = false) + private function processSuccessfulPayment(Payment $_payment) { if ($this->getParent()->payment_hash->data->store_card) { $this->storePaymentMethod($_payment); @@ -78,10 +78,6 @@ trait Utilities $this->getParent()->client ); - if ($return_payment) { - return $payment; - } - return redirect()->route('client.payments.show', ['payment' => $this->getParent()->encodePrimaryKey($payment->id)]); } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 0e51959dd3..09b7562559 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -213,7 +213,9 @@ class CheckoutComPaymentDriver extends BaseDriver $request = new PaymentResponseRequest(); $request->setMethod('POST'); - $request->request->add(['payment_hash' => $payment_hash]); + $request->request->add(['payment_hash' => $payment_hash->hash]); + + $this->setPaymentHash($payment_hash); try { $response = $this->gateway->payments()->request($payment); @@ -221,7 +223,24 @@ class CheckoutComPaymentDriver extends BaseDriver if ($response->status == 'Authorized') { $this->confirmGatewayFee($request); - return $this->processSuccessfulPayment($response, true); + $data = [ + 'payment_method' => $response->source['id'], + 'payment_type' => PaymentType::parseCardType(strtolower($response->source['scheme'])), + 'amount' => $amount, + 'transaction_reference' => $response->id, + ]; + + $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + + SystemLogger::dispatch( + ['response' => $response, 'data' => $data], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_CHECKOUT, + $this->client + ); + + return $payment; } if ($response->status == 'Declined') { @@ -230,17 +249,46 @@ class CheckoutComPaymentDriver extends BaseDriver PaymentFailureMailer::dispatch( $this->client, $response->response_summary, $this->client->company, - $this->payment_hash->data->value + $amount ); - $this->processUnsuccessfulPayment($response, false); + PaymentFailureMailer::dispatch( + $this->client, + $response, + $this->client->company, + $amount + ); + + $message = [ + 'server_response' => $response, + 'data' => $payment_hash->data, + ]; + + SystemLogger::dispatch( + $message, + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_CHECKOUT, + $this->client + ); return false; } } catch (\Exception | CheckoutHttpException $e) { $this->unWindGatewayFees($payment_hash); + $message = $e instanceof CheckoutHttpException + ? $e->getBody() + : $e->getMessage(); - // .. + $data = [ + 'status' => '', + 'error_type' => '', + 'error_code' => $e->getCode(), + 'param' => '', + 'message' => $message, + ]; + + SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_CHECKOUT, $this->client); } }