mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Payment Filters
This commit is contained in:
parent
1b84ccbf29
commit
75efdfeb0a
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
@ -41,6 +42,70 @@ class PaymentFilters extends QueryFilters
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter based on client status.
|
||||
*
|
||||
* Statuses we need to handle
|
||||
* - all
|
||||
* - pending
|
||||
* - cancelled
|
||||
* - failed
|
||||
* - completed
|
||||
* - partially refunded
|
||||
* - refunded
|
||||
*
|
||||
* @param string client_status The payment status as seen by the client
|
||||
* @return Builder
|
||||
*/
|
||||
public function client_status(string $value = ''): Builder
|
||||
{
|
||||
if (strlen($value) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$status_parameters = explode(',', $value);
|
||||
|
||||
if (in_array('all', $status_parameters)) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$this->builder->where(function ($query) use ($status_parameters) {
|
||||
$payment_filters = [];
|
||||
|
||||
if (in_array('pending', $status_parameters)) {
|
||||
$payment_filters[] = Payment::STATUS_PENDING;
|
||||
}
|
||||
|
||||
if (in_array('cancelled', $status_parameters)) {
|
||||
$payment_filters[] = Payment::STATUS_CANCELLED;
|
||||
}
|
||||
|
||||
if (in_array('failed', $status_parameters)) {
|
||||
$payment_filters[] = Payment::STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (in_array('completed', $status_parameters)) {
|
||||
$payment_filters[] = Payment::STATUS_COMPLETED;
|
||||
}
|
||||
|
||||
if (in_array('partially_refunded', $status_parameters)) {
|
||||
$payment_filters[] = Payment::STATUS_PARTIALLY_REFUNDED;
|
||||
}
|
||||
|
||||
if (in_array('refunded', $status_parameters)) {
|
||||
$payment_filters[] = Payment::STATUS_REFUNDED;
|
||||
}
|
||||
|
||||
if (count($payment_filters) >0) {
|
||||
$query->whereIn('status_id', $payment_filters);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of payments that can be matched to bank transactions
|
||||
*/
|
||||
|
@ -62,6 +62,16 @@ class PaymentTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testPatymentGetClientStatus()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/payments?client_status=completed');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testGetPaymentMatchList()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
|
Loading…
x
Reference in New Issue
Block a user