From 607a47ffd9441b25744056e7807de5e5157f50e6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 3 Sep 2020 20:55:33 +1000 Subject: [PATCH] Working on gateway fees to authorize.net --- .env.example | 2 +- .../Authorize/AuthorizeCreditCard.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 83c5abe747..ef6a007e6b 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ APP_NAME="Invoice Ninja" -APP_ENV=local +APP_ENV=production APP_KEY= APP_DEBUG=false diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 48f0053627..b58bb5bb7a 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -47,6 +47,7 @@ class AuthorizeCreditCard public function processPaymentView($data) { + $tokens = ClientGatewayToken::where('client_id', $this->authorize->client->id) ->where('company_gateway_id', $this->authorize->company_gateway->id) ->where('gateway_type_id', GatewayType::CREDIT_CARD) @@ -63,6 +64,7 @@ class AuthorizeCreditCard public function processPaymentResponse($request) { + if($request->token) return $this->processTokenPayment($request); @@ -90,15 +92,18 @@ class AuthorizeCreditCard private function processTokenPayment($request) { + $client_gateway_token = ClientGatewayToken::find($this->decodePrimaryKey($request->token)); $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($client_gateway_token->gateway_customer_reference, $client_gateway_token->token, $request->input('amount_with_fee')); return $this->handleResponse($data, $request); + } private function tokenBilling($cgt, $amount, $invoice) { + $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($cgt->gateway_customer_reference, $cgt->token, $amounts); if($data['response'] != null && $data['response']->getMessages()->getResultCode() == "Ok") { @@ -133,16 +138,19 @@ class AuthorizeCreditCard private function handleResponse($data, $request) { + $response = $data['response']; if($response != null && $response->getMessages()->getResultCode() == "Ok") return $this->processSuccessfulResponse($data, $request); return $this->processFailedResponse($data, $request); + } private function storePayment($payment_hash, $data) { + $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; $payment = $this->createPaymentRecord($data, $amount); @@ -154,6 +162,7 @@ class AuthorizeCreditCard event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); return $payment; + } private function createPaymentRecord($data, $amount) :?Payment @@ -170,16 +179,18 @@ class AuthorizeCreditCard $payment->save(); return $payment; + } private function processSuccessfulResponse($data, $request) { + $payment_hash = PaymentHash::whereRaw("BINARY `hash`= ?", [$request->input('payment_hash')])->firstOrFail(); $payment = $this->storePayment($payment_hash, $data); $vars = [ - 'hashed_ids' => $request->input('hashed_ids'), - 'amount' => $request->input('amount') + 'invoices' => $payment_hash->invoice(), + 'amount' => array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total ]; $logger_message = [ @@ -201,6 +212,7 @@ class AuthorizeCreditCard private function formatGatewayResponse($data, $vars) { + $response = $data['response']; return [ @@ -209,8 +221,9 @@ class AuthorizeCreditCard 'auth_code' => $response->getTransactionResponse()->getAuthCode(), 'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(), 'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(), - 'invoices' => $vars['hashed_ids'], + 'invoices' => $vars['invoices'], ]; + } } \ No newline at end of file