mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for payments with gateway fees
This commit is contained in:
parent
e342c02063
commit
2bd8581592
@ -76,6 +76,7 @@ class Payment extends BaseModel
|
||||
'created_at' => 'timestamp',
|
||||
'deleted_at' => 'timestamp',
|
||||
'is_deleted' => 'bool',
|
||||
'meta' => 'object',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
|
@ -20,6 +20,7 @@ use App\Models\ClientGatewayToken;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\PaymentDrivers\AbstractPaymentDriver;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -110,25 +111,19 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
* @param array $hashed_ids The array of invoice hashed_ids
|
||||
* @return Payment The payment object
|
||||
*/
|
||||
public function attachInvoices(Payment $payment, $hashed_ids): Payment
|
||||
|
||||
public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment
|
||||
{
|
||||
$transformed = $this->transformKeys($hashed_ids);
|
||||
$array = is_array($transformed) ? $transformed : [$transformed];
|
||||
|
||||
$invoices = Invoice::whereIn('id', $array)
|
||||
->whereClientId($this->client->id)
|
||||
->get();
|
||||
|
||||
$paid_invoices = $payment_hash->invoices();
|
||||
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->get();
|
||||
$payment->invoices()->sync($invoices);
|
||||
$payment->save();
|
||||
|
||||
$payment->service()->applyNumber()->save();
|
||||
|
||||
$invoices->each(function ($invoice) use($payment){
|
||||
event(new InvoiceWasPaid($invoice, $payment->company, Ninja::eventVars()));
|
||||
});
|
||||
|
||||
return $payment;
|
||||
return $payment->service()->applyNumber()->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ use App\Models\CompanyGateway;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\SystemLogTrait;
|
||||
use Illuminate\Support\Carbon;
|
||||
@ -247,8 +248,7 @@ class BasePaymentDriver
|
||||
->send();
|
||||
|
||||
return $response;
|
||||
/*
|
||||
$this->purchaseResponse = (array)$response->getData();*/
|
||||
|
||||
}
|
||||
|
||||
public function completePurchase($data)
|
||||
@ -273,15 +273,11 @@ class BasePaymentDriver
|
||||
}
|
||||
|
||||
|
||||
public function attachInvoices(Payment $payment, $hashed_ids): Payment
|
||||
public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment
|
||||
{
|
||||
$transformed = $this->transformKeys($hashed_ids);
|
||||
$array = is_array($transformed) ? $transformed : [$transformed];
|
||||
|
||||
$invoices = Invoice::whereIn('id', $array)
|
||||
->whereClientId($this->client->id)
|
||||
->get();
|
||||
|
||||
$paid_invoices = $payment_hash->invoices();
|
||||
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->get();
|
||||
$payment->invoices()->sync($invoices);
|
||||
$payment->save();
|
||||
|
||||
|
@ -169,6 +169,13 @@ class CreditCard
|
||||
'type' => $payment_method_object['type'],
|
||||
];
|
||||
|
||||
$payment_meta = new \stdClass;
|
||||
$payment_meta->exp_month = $payment_method_object['card']['exp_month'];
|
||||
$payment_meta->exp_year = $payment_method_object['card']['exp_year'];
|
||||
$payment_meta->brand = $payment_method_object['card']['brand'];
|
||||
$payment_meta->last4 = $payment_method_object['card']['last4'];
|
||||
$payment_meta->type = $payment_method_object['type'];
|
||||
|
||||
$payment_type = PaymentType::parseCardType($payment_method_object['card']['brand']);
|
||||
|
||||
if ($state['save_card'] == true) {
|
||||
@ -188,8 +195,9 @@ class CreditCard
|
||||
];
|
||||
|
||||
$payment = $this->stripe->createPayment($data, $status = Payment::STATUS_COMPLETED);
|
||||
$payment->meta = $payment_meta;
|
||||
|
||||
$this->stripe->attachInvoices($payment, $state['hashed_ids']);
|
||||
$payment = $this->stripe->attachInvoices($payment, $state['payment_hash']);
|
||||
|
||||
$payment->service()->updateInvoicePayment($state['payment_hash']);
|
||||
|
||||
|
@ -38,9 +38,6 @@ class UpdateInvoicePayment
|
||||
|
||||
public function run()
|
||||
{
|
||||
// $invoices = $this->payment->invoices()->get();
|
||||
// $invoices_total = $invoices->sum('balance');
|
||||
|
||||
$paid_invoices = $this->payment_hash->invoices();
|
||||
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->get();
|
||||
|
||||
@ -66,9 +63,14 @@ class UpdateInvoicePayment
|
||||
->updatePaidToDate($paid_amount)
|
||||
->save();
|
||||
|
||||
/*i think to interact with this correct - we need to do this form $payment->invoice()->pivot*/
|
||||
// $invoice->pivot->amount = $paid_amount;
|
||||
// $invoice->pivot->save();
|
||||
$pivot_invoice = $this->payment->invoices->first(function ($inv) use($paid_invoice){
|
||||
return $inv->hashed_id == $paid_invoice->invoice_id;
|
||||
});
|
||||
|
||||
/*update paymentable record*/
|
||||
$pivot_invoice->pivot->amount = $paid_amount;
|
||||
$pivot_invoice->save();
|
||||
|
||||
|
||||
$invoice->service() //caution what if we amount paid was less than partial - we wipe it!
|
||||
->clearPartial()
|
||||
|
@ -34,13 +34,13 @@
|
||||
@include('setup._issues')
|
||||
@else
|
||||
|
||||
@if(!$check['npm_status'])
|
||||
@if(isset($check['npm_status']) && !$check['npm_status'])
|
||||
<div class="alert alert-success mt-4">
|
||||
<p>NPM Version => {{$check['npm_status']}}</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(!$check['node_status'])
|
||||
@if(isset($check['node_status']) && !$check['node_status'])
|
||||
<div class="alert alert-success mt-4">
|
||||
<p>Node Version => {{$check['node_status']}}</p>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user