diff --git a/.env.example b/.env.example index 83c5abe7471e..ef6a007e6b0a 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ APP_NAME="Invoice Ninja" -APP_ENV=local +APP_ENV=production APP_KEY= APP_DEBUG=false diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 4c2997ae6bd2..b58bb5bb7a00 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -47,6 +47,7 @@ class AuthorizeCreditCard public function processPaymentView($data) { + $tokens = ClientGatewayToken::where('client_id', $this->authorize->client->id) ->where('company_gateway_id', $this->authorize->company_gateway->id) ->where('gateway_type_id', GatewayType::CREDIT_CARD) @@ -63,6 +64,7 @@ class AuthorizeCreditCard public function processPaymentResponse($request) { + if($request->token) return $this->processTokenPayment($request); @@ -72,14 +74,10 @@ class AuthorizeCreditCard $gateway_customer_reference = $authorise_create_customer->create($data); - //info($gateway_customer_reference); - $authorise_payment_method = new AuthorizePaymentMethod($this->authorize); $payment_profile = $authorise_payment_method->addPaymentMethodToClient($gateway_customer_reference, $data); $payment_profile_id = $payment_profile->getPaymentProfile()->getCustomerPaymentProfileId(); - - //info($request->input('store_card')); if($request->has('store_card') && $request->input('store_card') === 'true'){ $authorise_payment_method->payment_method = GatewayType::CREDIT_CARD; @@ -94,15 +92,18 @@ class AuthorizeCreditCard private function processTokenPayment($request) { + $client_gateway_token = ClientGatewayToken::find($this->decodePrimaryKey($request->token)); $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($client_gateway_token->gateway_customer_reference, $client_gateway_token->token, $request->input('amount_with_fee')); return $this->handleResponse($data, $request); + } 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") { @@ -137,12 +138,31 @@ class AuthorizeCreditCard private function handleResponse($data, $request) { + $response = $data['response']; if($response != null && $response->getMessages()->getResultCode() == "Ok") return $this->processSuccessfulResponse($data, $request); return $this->processFailedResponse($data, $request); + + } + + private function storePayment($payment_hash, $data) + { + + $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; + + $payment = $this->createPaymentRecord($data, $amount); + + $this->authorize->attachInvoices($payment, $payment_hash); + + $payment->service()->updateInvoicePayment($payment_hash); + + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); + + return $payment; + } private function createPaymentRecord($data, $amount) :?Payment @@ -159,30 +179,18 @@ class AuthorizeCreditCard $payment->save(); return $payment; + } private function processSuccessfulResponse($data, $request) { + $payment_hash = PaymentHash::whereRaw("BINARY `hash`= ?", [$request->input('payment_hash')])->firstOrFail(); - - - - - - $payment = $this->createPaymentRecord($data, $request->input('amount_with_fee')); - - - - - $this->authorize->attachInvoices($payment, $request->hashed_ids); - - $payment->service()->updateInvoicePayment(); - - event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); + $payment = $this->storePayment($payment_hash, $data); $vars = [ - 'hashed_ids' => $request->input('hashed_ids'), - 'amount' => $request->input('amount') + 'invoices' => $payment_hash->invoice(), + 'amount' => array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total ]; $logger_message = [ @@ -204,6 +212,7 @@ class AuthorizeCreditCard private function formatGatewayResponse($data, $vars) { + $response = $data['response']; return [ @@ -212,8 +221,9 @@ class AuthorizeCreditCard 'auth_code' => $response->getTransactionResponse()->getAuthCode(), 'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(), 'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(), - 'invoices' => $vars['hashed_ids'], + 'invoices' => $vars['invoices'], ]; + } } \ No newline at end of file diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 1996280fdc51..e650fcf458a1 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -49,9 +49,9 @@ class ExampleIntegrationTest extends TestCase ->design(Playful::class) ->build(); - exec('echo "" > storage/logs/laravel.log'); + // exec('echo "" > storage/logs/laravel.log'); - info($maker->getCompiledHTML(true)); +// info($maker->getCompiledHTML(true)); $this->assertTrue(true); } diff --git a/tests/Feature/PdfMaker/PdfMakerDesignsTest.php b/tests/Feature/PdfMaker/PdfMakerDesignsTest.php index 712b8036398a..add845c9309e 100644 --- a/tests/Feature/PdfMaker/PdfMakerDesignsTest.php +++ b/tests/Feature/PdfMaker/PdfMakerDesignsTest.php @@ -145,9 +145,9 @@ class PdfMakerDesignsTest extends TestCase ->design(Business::class) ->build(); - exec('echo "" > storage/logs/laravel.log'); + // exec('echo "" > storage/logs/laravel.log'); - info($maker->getCompiledHTML()); + // info($maker->getCompiledHTML()); $this->assertTrue(true); } @@ -256,7 +256,7 @@ class PdfMakerDesignsTest extends TestCase ->design(Clean::class) ->build(); - info($maker->getCompiledHTML(true)); + // info($maker->getCompiledHTML(true)); $this->assertTrue(true); } @@ -369,7 +369,7 @@ class PdfMakerDesignsTest extends TestCase ->design(Modern::class) ->build(); - info($maker->getCompiledHTML()); + // info($maker->getCompiledHTML()); //exec('echo "" > storage/logs/laravel.log'); @@ -486,7 +486,7 @@ class PdfMakerDesignsTest extends TestCase ->design(Bold::class) ->build(); - info($maker->getCompiledHTML()); + // info($maker->getCompiledHTML()); $this->assertTrue(true); } @@ -591,9 +591,9 @@ class PdfMakerDesignsTest extends TestCase ->design(Plain::class) ->build(); - exec('echo "" > storage/logs/laravel.log'); + // exec('echo "" > storage/logs/laravel.log'); - info($maker->getCompiledHTML(true)); + // info($maker->getCompiledHTML(true)); $this->assertTrue(true); } @@ -702,7 +702,7 @@ class PdfMakerDesignsTest extends TestCase ->design(Hipster::class) ->build(); - info($maker->getCompiledHTML(true)); + // info($maker->getCompiledHTML(true)); $this->assertTrue(true); } @@ -815,7 +815,7 @@ class PdfMakerDesignsTest extends TestCase ->design(Elegant::class) ->build(); - info($maker->getCompiledHTML(true)); + // info($maker->getCompiledHTML(true)); $this->assertTrue(true); } @@ -929,7 +929,7 @@ class PdfMakerDesignsTest extends TestCase ->build(); - info($maker->getCompiledHTML(true)); + // info($maker->getCompiledHTML(true)); $this->assertTrue(true); } @@ -1035,7 +1035,7 @@ class PdfMakerDesignsTest extends TestCase ->design(Playful::class) ->build(); - info($maker->getCompiledHTML(true)); + // info($maker->getCompiledHTML(true)); $this->assertTrue(true); } diff --git a/tests/Feature/PdfMaker/PdfMakerTest.php b/tests/Feature/PdfMaker/PdfMakerTest.php index 147d36dd1472..88aa58c70619 100644 --- a/tests/Feature/PdfMaker/PdfMakerTest.php +++ b/tests/Feature/PdfMaker/PdfMakerTest.php @@ -367,9 +367,9 @@ class PdfMakerTest extends TestCase ->design(ExampleDesign::class) ->build(); - exec('echo "" > storage/logs/laravel.log'); + // exec('echo "" > storage/logs/laravel.log'); - info($maker->getCompiledHTML(true)); + // info($maker->getCompiledHTML(true)); $this->assertTrue(true); } diff --git a/tests/Integration/CompanyLedgerTest.php b/tests/Integration/CompanyLedgerTest.php index 905c2b77f246..aa0703a709ef 100644 --- a/tests/Integration/CompanyLedgerTest.php +++ b/tests/Integration/CompanyLedgerTest.php @@ -226,7 +226,7 @@ class CompanyLedgerTest extends TestCase $payment_ledger = $payment->company_ledger->sortByDesc('id')->first(); -info($payment->client->balance); + //info($payment->client->balance); $this->assertEquals($payment->client->balance, $payment_ledger->balance); $this->assertEquals($payment->client->paid_to_date, 10);