Payment Filters

This commit is contained in:
David Bomba 2023-02-21 10:44:54 +11:00
parent 1b84ccbf29
commit 75efdfeb0a
2 changed files with 75 additions and 0 deletions

View File

@ -11,6 +11,7 @@
namespace App\Filters; namespace App\Filters;
use App\Models\Payment;
use Illuminate\Database\Eloquent\Builder; 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 * Returns a list of payments that can be matched to bank transactions
*/ */

View File

@ -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() public function testGetPaymentMatchList()
{ {
$response = $this->withHeaders([ $response = $this->withHeaders([