Refator payments and gateway fees

This commit is contained in:
David Bomba 2020-09-04 07:23:34 +10:00
parent 9fdbed4472
commit 9dce4c3de1
2 changed files with 11 additions and 10 deletions

View File

@ -18,6 +18,7 @@ use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Payment; use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\CheckoutCom\Utilities; use App\PaymentDrivers\CheckoutCom\Utilities;
@ -109,6 +110,7 @@ class CheckoutComPaymentDriver extends BasePaymentDriver
'value' => $request->value, 'value' => $request->value,
'raw_value' => $request->raw_value, 'raw_value' => $request->raw_value,
'currency' => $request->currency, 'currency' => $request->currency,
'payment_hash' =>$request->payment_hash,
]; ];
$state = array_merge($state, $request->all()); $state = array_merge($state, $request->all());
@ -163,10 +165,9 @@ class CheckoutComPaymentDriver extends BasePaymentDriver
]; ];
$payment = $this->createPayment($data, Payment::STATUS_COMPLETED); $payment = $this->createPayment($data, Payment::STATUS_COMPLETED);
$payment_hash = PaymentHash::whereRaw("BINARY `hash`= ?", [$state['payment_hash']])->firstOrFail();
$this->attachInvoices($payment, $state['hashed_ids']); $this->attachInvoices($payment, $payment_hash);
$payment->service()->updateInvoicePayment($payment_hash);
$payment->service()->updateInvoicePayment();
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));

View File

@ -18,6 +18,7 @@ use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Payment; use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\Utils\Ninja; use App\Utils\Ninja;
@ -91,7 +92,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
* @var $data['amount_with_fee'] * @var $data['amount_with_fee']
* @var $data['token'] * @var $data['token']
* @var $data['payment_method_id'] * @var $data['payment_method_id']
* @var $data['hashed_ids'] * @var $data['payment_hash']
* *
* @param array $data variables required to build payment page * @param array $data variables required to build payment page
* @return view Gateway and payment method specific view * @return view Gateway and payment method specific view
@ -163,10 +164,9 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
} }
$payment = $this->createPayment($response->getData()); $payment = $this->createPayment($response->getData());
$payment_hash = PaymentHash::whereRaw("BINARY `hash`= ?", [$request->input('payment_hash')])->firstOrFail();
$this->attachInvoices($payment, $request->input('hashed_ids')); $this->attachInvoices($payment, $payment_hash);
$payment->service()->updateInvoicePayment($payment_hash);
$payment->service()->UpdateInvoicePayment();
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
@ -194,7 +194,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
{ {
$url = $this->client->company->domain() . "/client/payments/process/response"; $url = $this->client->company->domain() . "/client/payments/process/response";
$url .= "?company_gateway_id={$this->company_gateway->id}&gateway_type_id=" . GatewayType::PAYPAL; $url .= "?company_gateway_id={$this->company_gateway->id}&gateway_type_id=" . GatewayType::PAYPAL;
$url .= "&hashed_ids=" . implode(",", $input['hashed_ids']); $url .= "&payment_hash=" . $input['payment_hash'];
$url .= "&amount=" . $input['amount']; $url .= "&amount=" . $input['amount'];
$url .= "&fee=" . $input['fee']; $url .= "&fee=" . $input['fee'];