mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #4032 from turbo124/v2
Working on Gateway fees & Online Payments
This commit is contained in:
commit
7315b70983
@ -1,5 +1,5 @@
|
||||
APP_NAME="Invoice Ninja"
|
||||
APP_ENV=local
|
||||
APP_ENV=production
|
||||
APP_KEY=
|
||||
APP_DEBUG=false
|
||||
|
||||
|
@ -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'],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user