diff --git a/app/Observers/CompanyGatewayObserver.php b/app/Observers/CompanyGatewayObserver.php index 819fc021b3ad..4c483819824b 100644 --- a/app/Observers/CompanyGatewayObserver.php +++ b/app/Observers/CompanyGatewayObserver.php @@ -55,7 +55,10 @@ class CompanyGatewayObserver public function restored(CompanyGateway $company_gateway) { //When we restore the gateway, bring back the tokens! - ClientGatewayToken::where('company_gateway_id', $company_gateway->id)->withTrashed()->get()->restore(); + ClientGatewayToken::where('company_gateway_id', $company_gateway->id) + ->withTrashed()->cursor()->each(function ($cgt){ + $cgt->restore(); + }); } /** diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index 9696334e612b..1c954e5e8f21 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -151,6 +151,11 @@ class CreditCard ], ]; + if ($this->braintree->company_gateway->getConfigField('merchantAccountId')) { + /** https://developer.paypal.com/braintree/docs/reference/request/transaction/sale/php#full-example */ + $data['merchantAccountId'] = $this->braintree->company_gateway->getConfigField('merchantAccountId'); + } + $response = $this->braintree->gateway->paymentMethod()->create($data); if ($response->success) { diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 98cc4f798a99..6b82f1230271 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -283,9 +283,6 @@ class Statement $from = $ranges[0]; $to = $ranges[1]; -nlog("from ".$from->format("Y-m-d")); -nlog("to ".$to->format("Y-m-d")); - $client = Client::where('id', $this->client->id)->first(); $amount = Invoice::where('company_id', $this->client->company->id) diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index a64b568a988e..480ba0e7fb1c 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -70,7 +70,7 @@ class AutoBillInvoice extends AbstractService /* Determine $amount */ if ($this->invoice->partial > 0) { $is_partial = true; - $invoice_total = $this->invoice->amount; + $invoice_total = $this->invoice->balance; $amount = $this->invoice->partial; } elseif ($this->invoice->balance > 0) { $amount = $this->invoice->balance; @@ -94,10 +94,14 @@ class AutoBillInvoice extends AbstractService /* $gateway fee */ $this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $gateway_token->gateway_type_id, $amount)->save(); + //change from $this->invoice->amount to $this->invoice->balance if($is_partial) - $fee = $this->invoice->amount - $invoice_total; + $fee = $this->invoice->balance - $invoice_total; else - $fee = $this->invoice->amount - $amount; + $fee = $this->invoice->balance - $amount; + + if($fee > $amount) + $fee = 0; /* Build payment hash */ $payment_hash = PaymentHash::create([