mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 04:37:38 -04:00
Payment Tests
This commit is contained in:
parent
aa0b9ed976
commit
9717424ce1
@ -509,7 +509,8 @@ class PaymentController extends BaseController
|
|||||||
|
|
||||||
$payments->each(function ($payment, $key) use ($action) {
|
$payments->each(function ($payment, $key) use ($action) {
|
||||||
if (auth()->user()->can('edit', $payment)) {
|
if (auth()->user()->can('edit', $payment)) {
|
||||||
$this->payment_repo->{$action}($payment);
|
$this->performAction($payment, $action, true);
|
||||||
|
// $this->payment_repo->{$action}($payment);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -587,30 +588,31 @@ class PaymentController extends BaseController
|
|||||||
* @param Payment $payment
|
* @param Payment $payment
|
||||||
* @param $action
|
* @param $action
|
||||||
*/
|
*/
|
||||||
public function action(ActionPaymentRequest $request, Payment $payment, $action)
|
public function performAction(Payment $payment, $action, $bulk = false)
|
||||||
{
|
{
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'clone_to_invoice':
|
case 'restore':
|
||||||
//$payment = CloneInvoiceFactory::create($payment, auth()->user()->id);
|
$this->payment_repo->restore($payment);
|
||||||
//return $this->itemResponse($payment);
|
|
||||||
break;
|
if (! $bulk) {
|
||||||
case 'clone_to_quote':
|
return $this->listResponse($payment);
|
||||||
//$quote = CloneInvoiceToQuoteFactory::create($payment, auth()->user()->id);
|
}
|
||||||
// todo build the quote transformer and return response here
|
|
||||||
break;
|
|
||||||
case 'history':
|
|
||||||
// code...
|
|
||||||
break;
|
|
||||||
case 'delivery_note':
|
|
||||||
// code...
|
|
||||||
break;
|
|
||||||
case 'mark_paid':
|
|
||||||
// code...
|
|
||||||
break;
|
break;
|
||||||
case 'archive':
|
case 'archive':
|
||||||
|
$this->payment_repo->archive($payment);
|
||||||
|
|
||||||
|
if (! $bulk) {
|
||||||
|
return $this->listResponse($payment);
|
||||||
|
}
|
||||||
// code...
|
// code...
|
||||||
break;
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
|
$this->payment_repo->delete($payment);
|
||||||
|
|
||||||
|
if (! $bulk) {
|
||||||
|
return $this->listResponse($payment);
|
||||||
|
}
|
||||||
// code...
|
// code...
|
||||||
break;
|
break;
|
||||||
case 'email':
|
case 'email':
|
||||||
|
@ -1302,4 +1302,87 @@ $contact = ClientContact::factory()->create([
|
|||||||
$this->assertEquals(1, $payment->invoices()->count());
|
$this->assertEquals(1, $payment->invoices()->count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPaymentActionArchive()
|
||||||
|
{
|
||||||
|
$this->invoice = null;
|
||||||
|
|
||||||
|
$client = ClientFactory::create($this->company->id, $this->user->id);
|
||||||
|
$client->save();
|
||||||
|
|
||||||
|
$this->invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
|
||||||
|
$this->invoice->client_id = $client->id;
|
||||||
|
|
||||||
|
$this->invoice->line_items = $this->buildLineItems();
|
||||||
|
$this->invoice->uses_inclusive_taxes = false;
|
||||||
|
|
||||||
|
$this->invoice->save();
|
||||||
|
|
||||||
|
$this->invoice_calc = new InvoiceSum($this->invoice);
|
||||||
|
$this->invoice_calc->build();
|
||||||
|
|
||||||
|
$this->invoice = $this->invoice_calc->getInvoice();
|
||||||
|
$this->invoice->save();
|
||||||
|
$this->invoice->service()->markSent()->save();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'amount' => 20.0,
|
||||||
|
'client_id' => $this->encodePrimaryKey($client->id),
|
||||||
|
'invoices' => [
|
||||||
|
[
|
||||||
|
'invoice_id' => $this->encodePrimaryKey($this->invoice->id),
|
||||||
|
'amount' => 10,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'date' => '2019/12/12',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/payments/', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$payment_id = $arr['data']['id'];
|
||||||
|
|
||||||
|
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'ids' => [$this->encodePrimaryKey($payment->id)],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/payments/bulk?action=archive', $data);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertGreaterThan(0, $arr['data'][0]['archived_at']);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/payments/bulk?action=restore', $data);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals(0, $arr['data'][0]['archived_at']);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/payments/bulk?action=delete', $data);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
info(print_r($arr,1));
|
||||||
|
$this->assertEquals(1, $arr['data'][0]['is_deleted']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user