diff --git a/app/Http/Requests/Payment/UpdatePaymentRequest.php b/app/Http/Requests/Payment/UpdatePaymentRequest.php index 9dca927e45fb..6149d3d142a8 100644 --- a/app/Http/Requests/Payment/UpdatePaymentRequest.php +++ b/app/Http/Requests/Payment/UpdatePaymentRequest.php @@ -72,17 +72,17 @@ class UpdatePaymentRequest extends Request unset($input['amount']); } - if (isset($input['type_id'])) { - unset($input['type_id']); - } + // if (isset($input['type_id'])) { + // unset($input['type_id']); + // } - if (isset($input['date'])) { - unset($input['date']); - } + // if (isset($input['date'])) { + // unset($input['date']); + // } - if (isset($input['transaction_reference'])) { - unset($input['transaction_reference']); - } + // if (isset($input['transaction_reference'])) { + // unset($input['transaction_reference']); + // } if (isset($input['number'])) { unset($input['number']); diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 8221423bb961..3d667610e42c 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -254,7 +254,6 @@ class CompanyGateway extends BaseModel $fee += $pre_tax_fee * $this->fee_tax_rate2 / 100; } - return $fee; } diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index d19e6698786f..3d3c63358628 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -102,6 +102,18 @@ class AuthorizeCreditCard private function tokenBilling($cgt, $amount, $invoice) { + $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($cgt->gateway_customer_reference, $cgt->token, $amounts); + + if($data['response'] != null && $data['response']->getMessages()->getResultCode() == "Ok") { + + $payment = $this->createPaymentRecord($data, $amount); + + $this->authorize->attachInvoices($payment, $invoice->hashed_id); + //up to here + } + else { + + } } @@ -115,10 +127,11 @@ class AuthorizeCreditCard return $this->processFailedResponse($data, $request); } - private function processSuccessfulResponse($data, $request) + private function createPaymentRecord($data, $amount) :?Payment { + $response = $data['response']; - //create a payment record and fire notifications and then return + //create a payment record $payment = PaymentFactory::create($this->authorize->client->company_id, $this->authorize->client->user_id); $payment->client_id = $this->authorize->client->id; @@ -129,11 +142,18 @@ class AuthorizeCreditCard $payment->currency_id = $this->authorize->client->getSetting('currency_id'); $payment->date = Carbon::now(); $payment->transaction_reference = $response->getTransactionResponse()->getTransId(); - $payment->amount = $request->input('amount_with_fee'); + $payment->amount = $amount; $payment->currency_id = $this->authorize->client->getSetting('currency_id'); $payment->client->getNextPaymentNumber($this->authorize->client); $payment->save(); + return $payment; + } + + private function processSuccessfulResponse($data, $request) + { + $payment = $this->createPaymentRecord($data, $request->input('amount_with_fee')); + $this->authorize->attachInvoices($payment, $request->hashed_ids); $payment->service()->updateInvoicePayment(); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 6b3922a254a2..30eec874b51c 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -59,10 +59,11 @@ class AutoBillInvoice extends AbstractService $amount = $this->invoice->balance + $fee; } + /* Make sure we remove any stale fees*/ + $this->purgeStaleGatewayFees(); + if($fee > 0) - $this->purgeStaleGatewayFees()->addFeeToInvoice($fee); - - + $this->addFeeToInvoice($fee); $response = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);