diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 38353eddb229..76b1641db904 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -76,6 +76,7 @@ class Payment extends BaseModel 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', 'is_deleted' => 'bool', + 'meta' => 'object', ]; protected $with = [ diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index f95b97e9c449..8572ed559345 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -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(); } /** diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 81fd86fe97b6..fb499b6b1659 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -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; @@ -241,14 +242,13 @@ class BasePaymentDriver { $this->gateway(); - $response = $this->gateway - ->purchase($data) - ->setItems($items) - ->send(); + $response = $this->gateway + ->purchase($data) + ->setItems($items) + ->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(); diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index b00552e87a30..48ae2cc50797 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -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']); diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 914a277ea259..ba5fa7ea88fb 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -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,14 +63,19 @@ 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; + }); - $invoice->service() //caution what if we amount paid was less than partial - we wipe it! - ->clearPartial() - ->updateBalance($paid_amount*-1) - ->save(); + /*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() + ->updateBalance($paid_amount*-1) + ->save(); }); diff --git a/resources/views/setup/index.blade.php b/resources/views/setup/index.blade.php index 04f4107579a5..39c61bcdfe0d 100644 --- a/resources/views/setup/index.blade.php +++ b/resources/views/setup/index.blade.php @@ -34,13 +34,13 @@ @include('setup._issues') @else - @if(!$check['npm_status']) + @if(isset($check['npm_status']) && !$check['npm_status'])

NPM Version => {{$check['npm_status']}}

@endif - @if(!$check['node_status']) + @if(isset($check['node_status']) && !$check['node_status'])

Node Version => {{$check['node_status']}}