mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
- Extract $payment_hash property onto BaseDriver
- Handle internally failed payments inside BaseDriver - Add SYSTEM_LOG_TYPE property on CheckoutComPaymentDriver - Remove resolving of $payment_hash inside of payment methods
This commit is contained in:
parent
f3e578cc5c
commit
223ae4cb5b
@ -220,17 +220,19 @@ class PaymentController extends Controller
|
||||
return $gateway
|
||||
->driver(auth()->user()->client)
|
||||
->setPaymentMethod($payment_method_id)
|
||||
->setPaymentHash($payment_hash)
|
||||
->processPaymentView($data);
|
||||
}
|
||||
|
||||
public function response(PaymentResponseRequest $request)
|
||||
{
|
||||
/*Payment Gateway*/
|
||||
$gateway = CompanyGateway::find($request->input('company_gateway_id'))->firstOrFail();
|
||||
$payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->payment_hash])->first();
|
||||
|
||||
return $gateway
|
||||
->driver(auth()->user()->client)
|
||||
->setPaymentMethod($request->input('payment_method_id'))
|
||||
->setPaymentHash($payment_hash)
|
||||
->processPaymentResponse($request);
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,11 @@ namespace App\PaymentDrivers;
|
||||
|
||||
use App\Events\Invoice\InvoiceWasPaid;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Exceptions\PaymentFailed;
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
||||
use App\Jobs\Mail\PaymentFailureMailer;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\ClientGatewayToken;
|
||||
@ -23,6 +26,7 @@ use App\Models\CompanyGateway;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\AbstractPaymentDriver;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -58,6 +62,11 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
/* The initiated gateway driver class*/
|
||||
public $payment_method;
|
||||
|
||||
/**
|
||||
* @var \App\Models\PaymentHash
|
||||
*/
|
||||
public $payment_hash;
|
||||
|
||||
public static $methods = [];
|
||||
|
||||
public function __construct(CompanyGateway $company_gateway, Client $client = null, $invitation = false)
|
||||
@ -112,6 +121,13 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
{
|
||||
}
|
||||
|
||||
public function setPaymentHash(PaymentHash $payment_hash)
|
||||
{
|
||||
$this->payment_hash = $payment_hash;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to attach invoices to a payment.
|
||||
*
|
||||
@ -274,4 +290,32 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
|
||||
return $company_gateway_token;
|
||||
}
|
||||
|
||||
public function processInternallyFailedPayment($gateway, $e)
|
||||
{
|
||||
if ($e instanceof \Exception) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
if ($e instanceof \Checkout\Library\Exceptions\CheckoutHttpException) {
|
||||
$error = $e->getBody();
|
||||
}
|
||||
|
||||
PaymentFailureMailer::dispatch(
|
||||
$gateway->client,
|
||||
$error,
|
||||
$gateway->client->company,
|
||||
$this->payment_hash->data->value
|
||||
);
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$this->checkout->payment_hash,
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_ERROR,
|
||||
$gateway::SYSTEM_LOG_TYPE,
|
||||
$this->checkout->client,
|
||||
);
|
||||
|
||||
throw new PaymentFailed($error, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
@ -85,12 +85,8 @@ class CreditCard
|
||||
$state = array_merge($state, $request->all());
|
||||
$state['store_card'] = boolval($state['store_card']);
|
||||
|
||||
$payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->payment_hash])->first();
|
||||
|
||||
$payment_hash->data = array_merge((array) $payment_hash->data, $state);
|
||||
$payment_hash->save();
|
||||
|
||||
$this->checkout->payment_hash = $payment_hash;
|
||||
$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)) {
|
||||
return $this->attemptPaymentUsingToken($request);
|
||||
|
@ -118,38 +118,10 @@ trait Utilities
|
||||
try {
|
||||
return redirect($_payment->_links['redirect']['href']);
|
||||
} catch (\Exception $e) {
|
||||
return $this->processInternallyFailedPayment($e);
|
||||
return $this->processInternallyFailedPayment($this->checkout, $e);
|
||||
}
|
||||
}
|
||||
|
||||
private function processInternallyFailedPayment($e)
|
||||
{
|
||||
if ($e instanceof \Checkout\Library\Exceptions\CheckoutHttpException) {
|
||||
$error = $e->getBody();
|
||||
}
|
||||
|
||||
if ($e instanceof \Exception) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
PaymentFailureMailer::dispatch(
|
||||
$this->checkout->client,
|
||||
$error,
|
||||
$this->checkout->client->company,
|
||||
$this->checkout->payment_hash->data->value
|
||||
);
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$this->checkout->payment_hash,
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_ERROR,
|
||||
SystemLog::TYPE_CHECKOUT,
|
||||
$this->checkout->client,
|
||||
);
|
||||
|
||||
throw new PaymentFailed($error, $e->getCode());
|
||||
}
|
||||
|
||||
private function storePaymentMethod(\Checkout\Models\Payments\Payment $response)
|
||||
{
|
||||
try {
|
||||
|
@ -16,6 +16,7 @@ use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\BaseDriver;
|
||||
use App\PaymentDrivers\CheckoutCom\Utilities;
|
||||
use App\Utils\Traits\SystemLogTrait;
|
||||
@ -48,15 +49,12 @@ class CheckoutComPaymentDriver extends BaseDriver
|
||||
|
||||
public $payment_method; //the gateway type id
|
||||
|
||||
/**
|
||||
* @var \App\Models\PaymentHash
|
||||
*/
|
||||
public $payment_hash;
|
||||
|
||||
public static $methods = [
|
||||
GatewayType::CREDIT_CARD => \App\PaymentDrivers\CheckoutCom\CreditCard::class,
|
||||
];
|
||||
|
||||
const SYSTEM_LOG_TYPE = SystemLog::TYPE_CHECKOUT;
|
||||
|
||||
/**
|
||||
* Returns the default gateway type.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user