1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #6908 from turbo124/v5-develop

Minor fixes for paypal express on failure
This commit is contained in:
David Bomba 2021-10-27 14:18:20 +11:00 committed by GitHub
commit 0e715b2b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 266 additions and 19 deletions

View File

@ -53,6 +53,7 @@ class Handler extends ExceptionHandler
CommandNotFoundException::class,
ValidationException::class,
ModelNotFoundException::class,
NotFoundHttpException::class,
];
/**

View File

@ -240,7 +240,7 @@ class CompanyController extends BaseController
/*
* Create token
*/
$user_agent = request()->input('token_name') ?: request()->server('HTTP_USER_AGENT');
$user_agent = request()->has('token_name') ? request()->input('token_name') : request()->server('HTTP_USER_AGENT');
$company_token = CreateCompanyToken::dispatchNow($company, auth()->user(), $user_agent);

View File

@ -683,8 +683,6 @@ class PaymentController extends BaseController
{
$payment = $request->payment();
// nlog($request->all());
$payment = $payment->refund($request->all());
return $this->itemResponse($payment);

View File

@ -33,9 +33,10 @@ class UpdateTaskStatusRequest extends Request
{
$rules = [];
if ($this->input('name')) {
$rules['name'] = Rule::unique('task_statuses')->where('company_id', auth()->user()->company()->id)->ignore($this->task_status->id);
}
// 26/10/2021 we disable this as it prevent updating existing task status meta data where the same name already exists
// if ($this->input('name')) {
// $rules['name'] = Rule::unique('task_statuses')->where('company_id', auth()->user()->company()->id)->ignore($this->task_status->id);
// }
return $rules;

View File

@ -51,7 +51,7 @@ class PaymentAppliedValidAmount implements Rule
$payment_amounts = 0;
$invoice_amounts = 0;
$payment_amounts = $payment->amount - $payment->applied;
$payment_amounts = $payment->amount - $payment->refunded - $payment->applied;
if (request()->input('credits') && is_array(request()->input('credits'))) {
foreach (request()->input('credits') as $credit) {

View File

@ -15,6 +15,7 @@ use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Libraries\MultiDB;
use App\Mail\Admin\ClientPaymentFailureObject;
use App\Mail\Admin\EntityNotificationMailer;
use App\Mail\Admin\PaymentFailureObject;
use App\Models\Client;
@ -102,6 +103,24 @@ class PaymentFailedMailer implements ShouldQueue
});
//add client payment failures here.
nlog("pre client failure email");
if($contact = $this->client->primary_contact()->first())
{
nlog("inside failure");
$mail_obj = (new ClientPaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build();
$nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer($mail_obj);
$nmo->company = $this->company;
$nmo->to_user = $contact;
$nmo->settings = $settings;
NinjaMailerJob::dispatch($nmo);
}
}

View File

@ -14,7 +14,6 @@ namespace App\Mail\Admin;
use App\Models\Invoice;
use App\Utils\HtmlEngine;
use App\Utils\Ninja;
use App\Utils\Number;
use App\Utils\Traits\MakesHash;
use Illuminate\Support\Facades\App;
use stdClass;
@ -91,7 +90,7 @@ class ClientPaymentFailureObject
return
ctrans(
'texts.notification_invoice_payment_failed_subject',
['invoice' => $this->client->present()->name()]
['invoice' => implode(",", $this->invoices->pluck('number')->toArray())]
);
}
@ -110,7 +109,7 @@ class ClientPaymentFailureObject
]
),
'greeting' => ctrans('texts.email_salutation', ['name' => $this->client->present()->name]),
'message' => $this->error,
'message' => ctrans('texts.client_payment_failure_body', ['invoice' => implode(",", $this->invoices->pluck('number')->toArray()), 'amount' => $this->getAmount()]),
'signature' => $signature,
'logo' => $this->company->present()->logo(),
'settings' => $this->client->getMergedSettings(),

View File

@ -93,7 +93,7 @@ class PayPalExpressPaymentDriver extends BaseDriver
return $response->redirect();
}
$this->sendFailureMail($response->getData());
$this->sendFailureMail($response->getMessage());
$message = [
'server_response' => $response->getMessage(),

View File

@ -65,7 +65,7 @@ class ClientRepository extends BaseRepository
$client->fill($data);
$client->save();
if (!isset($client->number) || empty($client->number)) {
if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) {
$client->number = $this->getNextClientNumber($client);
}

View File

@ -115,15 +115,22 @@ class DeletePayment
->updatePaidToDate($net_deletable * -1)
->save();
// $paymentable_invoice->client
// ->service()
// ->updatePaidToDate($net_deletable * -1)
// ->save();
}
});
}
else {
/* If there are no invoices - then we need to still adjust the total client->paid_to_date amount*/
$this->payment
->client
->service()
->updatePaidToDate(($this->payment->amount - $this->payment->applied)*-1)
->save();
}
return $this;
}

View File

@ -267,9 +267,17 @@ class RefundPayment
// $this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string);
$client = $this->payment->client->fresh();
//$client->service()->updatePaidToDate(-1 * $this->total_refund)->save();
$client->service()->updatePaidToDate(-1 * $refunded_invoice['amount'])->save();
}
else{
//if we are refunding and no payments have been tagged, then we need to decrement the client->paid_to_date by the total refund amount.
$client = $this->payment->client->fresh();
$client->service()->updatePaidToDate(-1 * $this->total_refund)->save();
}
return $this;
}

View File

@ -1400,7 +1400,7 @@ $LANG = array(
'more_options' => 'More options',
'credit_card' => 'Credit Card',
'bank_transfer' => 'Bank Transfer',
'no_transaction_reference' => 'We did not recieve a payment transaction reference from the gateway.',
'no_transaction_reference' => 'We did not receive a payment transaction reference from the gateway.',
'use_bank_on_file' => 'Use Bank on File',
'auto_bill_email_message' => 'This invoice will automatically be billed to the payment method on file on the due date.',
'bitcoin' => 'Bitcoin',
@ -4334,7 +4334,8 @@ $LANG = array(
'clone_to_expense' => 'Clone to expense',
'checkout' => 'Checkout',
'acss' => 'Pre-authorized debit payments',
'invalid_amount' => 'Invalid amount. Number/Decimal values only.'
'invalid_amount' => 'Invalid amount. Number/Decimal values only.',
'client_payment_failure_body' => 'Payment for Invoice :invoice for amount :amount failed.',
);
return $LANG;

View File

@ -0,0 +1,103 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Feature\Payments;
use App\Models\Payment;
use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutEvents;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Validation\ValidationException;
use Tests\MockAccountData;
use Tests\MockUnitData;
use Tests\TestCase;
/**
* @test
*/
class UnappliedPaymentDeleteTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
use MockUnitData;
use WithoutEvents;
public function setUp() :void
{
parent::setUp();
$this->faker = \Faker\Factory::create();
$this->makeTestData();
$this->withoutExceptionHandling();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
public function testUnappliedPaymentDelete()
{
$data = [
'amount' => 1000,
'client_id' => $this->client->hashed_id,
'invoices' => [
],
'date' => '2020/12/12',
];
$response = null;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message);
}
if ($response){
$arr = $response->json();
$response->assertStatus(200);
$payment_id = $arr['data']['id'];
$payment = Payment::with('client')->find($this->decodePrimaryKey($payment_id));
$this->assertEquals(1000, $payment->amount);
$this->assertEquals(1000, $payment->client->paid_to_date);
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->delete('/api/v1/payments/'. $payment_id);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message);
}
$response->assertStatus(200);
$this->assertEquals(0, $this->client->fresh()->paid_to_date);
}
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Feature\Payments;
use App\Models\Payment;
use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutEvents;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Validation\ValidationException;
use Tests\MockAccountData;
use Tests\MockUnitData;
use Tests\TestCase;
/**
* @test
*/
class UnappliedPaymentRefundTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
use MockUnitData;
use WithoutEvents;
public function setUp() :void
{
parent::setUp();
$this->faker = \Faker\Factory::create();
$this->makeTestData();
$this->withoutExceptionHandling();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
public function testUnappliedPaymentRefund()
{
$data = [
'amount' => 1000,
'client_id' => $this->client->hashed_id,
'invoices' => [
],
'date' => '2020/12/12',
];
$response = null;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message);
}
if ($response){
$arr = $response->json();
$response->assertStatus(200);
$this->assertEquals(1000, $this->client->fresh()->paid_to_date);
$payment_id = $arr['data']['id'];
$this->assertEquals(1000, $arr['data']['amount']);
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();
$data = [
'id' => $this->encodePrimaryKey($payment->id),
'amount' => 500,
'date' => '2020/12/12',
];
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/refund', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message);
}
$response->assertStatus(200);
$this->assertEquals(500, $this->client->fresh()->paid_to_date);
}
}
}