diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 10569e081c9f..0c0a3d0283d0 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -12,6 +12,7 @@ namespace App\PaymentDrivers\Authorize; +use App\Exceptions\PaymentFailed; use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; @@ -81,7 +82,14 @@ class AuthorizeCreditCard private function processTokenPayment($request) { - $client_gateway_token =ClientGatewayToken::where('token', $request->token)->firstOrFail(); + $client_gateway_token = ClientGatewayToken::query() + ->where('id', $this->decodePrimaryKey($request->token)) + ->where('company_id', auth('contact')->user()->client->company->id) + ->first(); + + if (!$client_gateway_token) { + throw new PaymentFailed(ctrans('texts.payment_token_not_found'), 401); + } $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($client_gateway_token->gateway_customer_reference, $client_gateway_token->token, $request->input('amount_with_fee')); @@ -129,7 +137,7 @@ class AuthorizeCreditCard PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransactionResponse()->getTransId(), $this->authorize->client->company, $amount); SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_AUTHORIZE, $this->authorize->client); - + return false; } } @@ -157,7 +165,7 @@ class AuthorizeCreditCard $payment_record = []; $payment_record['amount'] = $amount; $payment_record['payment_type'] = PaymentType::CREDIT_CARD_OTHER; - $payment_record['gateway_type_id'] = GatewayType::CREDIT_CARD; + $payment_record['gateway_type_id'] = GatewayType::CREDIT_CARD; $payment_record['transaction_reference'] = $response->getTransactionResponse()->getTransId(); $payment = $this->authorize->createPayment($payment_record); diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index d9855594d12b..4c9faca90d67 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -12,9 +12,12 @@ namespace App\PaymentDrivers\CheckoutCom; +use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Jobs\Mail\PaymentFailureMailer; +use App\Models\ClientGatewayToken; use App\PaymentDrivers\CheckoutComPaymentDriver; +use App\Utils\Traits\MakesHash; use Checkout\Library\Exceptions\CheckoutHttpException; use Checkout\Models\Payments\IdSource; use Checkout\Models\Payments\Payment; @@ -25,6 +28,7 @@ use Illuminate\View\View; class CreditCard { use Utilities; + use MakesHash; /** * @var CheckoutComPaymentDriver @@ -78,6 +82,15 @@ class CreditCard { $this->checkout->init(); + $cgt = ClientGatewayToken::query() + ->where('id', $this->decodePrimaryKey($request->input('token'))) + ->where('company_id', auth('contact')->user()->client->company->id) + ->first(); + + if (!$cgt) { + throw new PaymentFailed(ctrans('texts.payment_token_not_found'), 401); + } + $state = [ 'server_response' => json_decode($request->gateway_response), 'value' => $request->value, @@ -90,11 +103,12 @@ class CreditCard $state = array_merge($state, $request->all()); $state['store_card'] = boolval($state['store_card']); + $state['token'] = $cgt; - $this->checkout->payment_hash->data = array_merge((array) $this->checkout->payment_hash->data, $state); + $this->checkout->payment_hash->data = array_merge((array)$this->checkout->payment_hash->data, $state); $this->checkout->payment_hash->save(); - if ($request->has('token') && !is_null($request->token) && !empty($request->token)) { + if ($request->has('token')) { return $this->attemptPaymentUsingToken($request); } @@ -103,7 +117,7 @@ class CreditCard private function attemptPaymentUsingToken(PaymentResponseRequest $request) { - $method = new IdSource($this->checkout->payment_hash->data->token); + $method = new IdSource($this->checkout->payment_hash->data->token->token); return $this->completePayment($method, $request); } @@ -125,7 +139,7 @@ class CreditCard $payment->amount = $this->checkout->payment_hash->data->value; $payment->reference = $this->checkout->payment_hash->data->reference; - $this->checkout->payment_hash->data = array_merge((array) $this->checkout->payment_hash->data, ['checkout_payment_ref' => $payment]); + $this->checkout->payment_hash->data = array_merge((array)$this->checkout->payment_hash->data, ['checkout_payment_ref' => $payment]); $this->checkout->payment_hash->save(); if ($this->checkout->client->currency()->code === 'EUR') { @@ -156,7 +170,7 @@ class CreditCard if ($response->status == 'Declined') { $this->checkout->unWindGatewayFees($this->checkout->payment_hash); - PaymentFailureMailer::dispatch($this->checkout->client, $response->response_summary, $this->checkout->client->company, $this->checkout->payment_hash->data->value); + PaymentFailureMailer::dispatch($this->checkout->client, $response->response_summary, $this->checkout->client->company, $this->checkout->payment_hash->data->value); return $this->processUnsuccessfulPayment($response); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 79dc87e19fd3..2dbaf436b3ad 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3383,5 +3383,5 @@ return [ 'create_webhook_failure' => 'Failed to create Webhook', 'number' => 'Number', 'payment_message_extended' => 'Thank you for your payment of :amount for :invoice', - + 'payment_token_not_found' => 'Payment token not found, please try again. If an issue still persist, try with another payment method', ]; diff --git a/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php index b121661b94af..486d045a33b3 100644 --- a/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php @@ -38,7 +38,7 @@