mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 07:02:34 +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_NAME="Invoice Ninja"
|
||||||
APP_ENV=local
|
APP_ENV=production
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=false
|
APP_DEBUG=false
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ class AuthorizeCreditCard
|
|||||||
|
|
||||||
public function processPaymentView($data)
|
public function processPaymentView($data)
|
||||||
{
|
{
|
||||||
|
|
||||||
$tokens = ClientGatewayToken::where('client_id', $this->authorize->client->id)
|
$tokens = ClientGatewayToken::where('client_id', $this->authorize->client->id)
|
||||||
->where('company_gateway_id', $this->authorize->company_gateway->id)
|
->where('company_gateway_id', $this->authorize->company_gateway->id)
|
||||||
->where('gateway_type_id', GatewayType::CREDIT_CARD)
|
->where('gateway_type_id', GatewayType::CREDIT_CARD)
|
||||||
@ -63,6 +64,7 @@ class AuthorizeCreditCard
|
|||||||
|
|
||||||
public function processPaymentResponse($request)
|
public function processPaymentResponse($request)
|
||||||
{
|
{
|
||||||
|
|
||||||
if($request->token)
|
if($request->token)
|
||||||
return $this->processTokenPayment($request);
|
return $this->processTokenPayment($request);
|
||||||
|
|
||||||
@ -72,15 +74,11 @@ class AuthorizeCreditCard
|
|||||||
|
|
||||||
$gateway_customer_reference = $authorise_create_customer->create($data);
|
$gateway_customer_reference = $authorise_create_customer->create($data);
|
||||||
|
|
||||||
//info($gateway_customer_reference);
|
|
||||||
|
|
||||||
$authorise_payment_method = new AuthorizePaymentMethod($this->authorize);
|
$authorise_payment_method = new AuthorizePaymentMethod($this->authorize);
|
||||||
|
|
||||||
$payment_profile = $authorise_payment_method->addPaymentMethodToClient($gateway_customer_reference, $data);
|
$payment_profile = $authorise_payment_method->addPaymentMethodToClient($gateway_customer_reference, $data);
|
||||||
$payment_profile_id = $payment_profile->getPaymentProfile()->getCustomerPaymentProfileId();
|
$payment_profile_id = $payment_profile->getPaymentProfile()->getCustomerPaymentProfileId();
|
||||||
|
|
||||||
//info($request->input('store_card'));
|
|
||||||
|
|
||||||
if($request->has('store_card') && $request->input('store_card') === 'true'){
|
if($request->has('store_card') && $request->input('store_card') === 'true'){
|
||||||
$authorise_payment_method->payment_method = GatewayType::CREDIT_CARD;
|
$authorise_payment_method->payment_method = GatewayType::CREDIT_CARD;
|
||||||
$client_gateway_token = $authorise_payment_method->createClientGatewayToken($payment_profile, $gateway_customer_reference);
|
$client_gateway_token = $authorise_payment_method->createClientGatewayToken($payment_profile, $gateway_customer_reference);
|
||||||
@ -94,15 +92,18 @@ class AuthorizeCreditCard
|
|||||||
|
|
||||||
private function processTokenPayment($request)
|
private function processTokenPayment($request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$client_gateway_token = ClientGatewayToken::find($this->decodePrimaryKey($request->token));
|
$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'));
|
$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);
|
return $this->handleResponse($data, $request);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function tokenBilling($cgt, $amount, $invoice)
|
private function tokenBilling($cgt, $amount, $invoice)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($cgt->gateway_customer_reference, $cgt->token, $amounts);
|
$data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($cgt->gateway_customer_reference, $cgt->token, $amounts);
|
||||||
|
|
||||||
if($data['response'] != null && $data['response']->getMessages()->getResultCode() == "Ok") {
|
if($data['response'] != null && $data['response']->getMessages()->getResultCode() == "Ok") {
|
||||||
@ -137,12 +138,31 @@ class AuthorizeCreditCard
|
|||||||
|
|
||||||
private function handleResponse($data, $request)
|
private function handleResponse($data, $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$response = $data['response'];
|
$response = $data['response'];
|
||||||
|
|
||||||
if($response != null && $response->getMessages()->getResultCode() == "Ok")
|
if($response != null && $response->getMessages()->getResultCode() == "Ok")
|
||||||
return $this->processSuccessfulResponse($data, $request);
|
return $this->processSuccessfulResponse($data, $request);
|
||||||
|
|
||||||
return $this->processFailedResponse($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
|
private function createPaymentRecord($data, $amount) :?Payment
|
||||||
@ -159,30 +179,18 @@ class AuthorizeCreditCard
|
|||||||
$payment->save();
|
$payment->save();
|
||||||
|
|
||||||
return $payment;
|
return $payment;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processSuccessfulResponse($data, $request)
|
private function processSuccessfulResponse($data, $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$payment_hash = PaymentHash::whereRaw("BINARY `hash`= ?", [$request->input('payment_hash')])->firstOrFail();
|
$payment_hash = PaymentHash::whereRaw("BINARY `hash`= ?", [$request->input('payment_hash')])->firstOrFail();
|
||||||
|
$payment = $this->storePayment($payment_hash, $data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$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()));
|
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
'hashed_ids' => $request->input('hashed_ids'),
|
'invoices' => $payment_hash->invoice(),
|
||||||
'amount' => $request->input('amount')
|
'amount' => array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total
|
||||||
];
|
];
|
||||||
|
|
||||||
$logger_message = [
|
$logger_message = [
|
||||||
@ -204,6 +212,7 @@ class AuthorizeCreditCard
|
|||||||
|
|
||||||
private function formatGatewayResponse($data, $vars)
|
private function formatGatewayResponse($data, $vars)
|
||||||
{
|
{
|
||||||
|
|
||||||
$response = $data['response'];
|
$response = $data['response'];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -212,8 +221,9 @@ class AuthorizeCreditCard
|
|||||||
'auth_code' => $response->getTransactionResponse()->getAuthCode(),
|
'auth_code' => $response->getTransactionResponse()->getAuthCode(),
|
||||||
'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
|
'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
|
||||||
'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(),
|
'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(),
|
||||||
'invoices' => $vars['hashed_ids'],
|
'invoices' => $vars['invoices'],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -49,9 +49,9 @@ class ExampleIntegrationTest extends TestCase
|
|||||||
->design(Playful::class)
|
->design(Playful::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
exec('echo "" > storage/logs/laravel.log');
|
// exec('echo "" > storage/logs/laravel.log');
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
@ -145,9 +145,9 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Business::class)
|
->design(Business::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
exec('echo "" > storage/logs/laravel.log');
|
// exec('echo "" > storage/logs/laravel.log');
|
||||||
|
|
||||||
info($maker->getCompiledHTML());
|
// info($maker->getCompiledHTML());
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Clean::class)
|
->design(Clean::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -369,7 +369,7 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Modern::class)
|
->design(Modern::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
info($maker->getCompiledHTML());
|
// info($maker->getCompiledHTML());
|
||||||
|
|
||||||
//exec('echo "" > storage/logs/laravel.log');
|
//exec('echo "" > storage/logs/laravel.log');
|
||||||
|
|
||||||
@ -486,7 +486,7 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Bold::class)
|
->design(Bold::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
info($maker->getCompiledHTML());
|
// info($maker->getCompiledHTML());
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -591,9 +591,9 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Plain::class)
|
->design(Plain::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
exec('echo "" > storage/logs/laravel.log');
|
// exec('echo "" > storage/logs/laravel.log');
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -702,7 +702,7 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Hipster::class)
|
->design(Hipster::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -815,7 +815,7 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Elegant::class)
|
->design(Elegant::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -929,7 +929,7 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->build();
|
->build();
|
||||||
|
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -1035,7 +1035,7 @@ class PdfMakerDesignsTest extends TestCase
|
|||||||
->design(Playful::class)
|
->design(Playful::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
@ -367,9 +367,9 @@ class PdfMakerTest extends TestCase
|
|||||||
->design(ExampleDesign::class)
|
->design(ExampleDesign::class)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
exec('echo "" > storage/logs/laravel.log');
|
// exec('echo "" > storage/logs/laravel.log');
|
||||||
|
|
||||||
info($maker->getCompiledHTML(true));
|
// info($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ class CompanyLedgerTest extends TestCase
|
|||||||
|
|
||||||
$payment_ledger = $payment->company_ledger->sortByDesc('id')->first();
|
$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->balance, $payment_ledger->balance);
|
||||||
$this->assertEquals($payment->client->paid_to_date, 10);
|
$this->assertEquals($payment->client->paid_to_date, 10);
|
||||||
|
Loading…
Reference in New Issue
Block a user