mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 02:14:29 -04:00
Delete a payment from the API
This commit is contained in:
parent
b3346011bc
commit
42f3cffca8
@ -51,8 +51,8 @@ class ClientApiController extends BaseAPIController
|
||||
public function index()
|
||||
{
|
||||
$clients = Client::scope()
|
||||
->with($this->getIncluded())
|
||||
->orderBy('created_at', 'desc')->withTrashed();
|
||||
->with($this->getIncluded())
|
||||
->orderBy('created_at', 'desc')->withTrashed();
|
||||
|
||||
// Filter by email
|
||||
if (Input::has('email')) {
|
||||
@ -100,8 +100,8 @@ class ClientApiController extends BaseAPIController
|
||||
$client = $this->clientRepo->save($request->input());
|
||||
|
||||
$client = Client::scope($client->public_id)
|
||||
->with('country', 'contacts', 'industry', 'size', 'currency')
|
||||
->first();
|
||||
->with('country', 'contacts', 'industry', 'size', 'currency')
|
||||
->first();
|
||||
|
||||
$transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($client, $transformer, ENTITY_CLIENT);
|
||||
@ -156,4 +156,7 @@ class ClientApiController extends BaseAPIController
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use App\Ninja\Mailers\ContactMailer;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Request;
|
||||
use Input;
|
||||
use Utils;
|
||||
use Response;
|
||||
@ -87,18 +87,31 @@ class PaymentApiController extends BaseAPIController
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function update($publicId)
|
||||
|
||||
public function update(Request $request, $publicId)
|
||||
{
|
||||
$data = Input::all();
|
||||
$data['public_id'] = $publicId;
|
||||
$invoice = Invoice::scope($data['invoice_id'])->with('client')->first();
|
||||
|
||||
$error = false;
|
||||
$payment = $this->paymentRepo->save($data);
|
||||
|
||||
if ($request->action == ACTION_ARCHIVE) {
|
||||
$payment = Payment::scope($publicId)->firstOrFail();
|
||||
$this->paymentRepo->archive($payment);
|
||||
|
||||
$invoice = Invoice::scope($data['invoice_id'])->with('client')->first();
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
$this->paymentRepo->save($data);
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->first();
|
||||
|
||||
$invoice = Invoice::scope($data['invoice_id'])->with('client', 'invoice_items', 'invitations','payments')->first();
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
return $this->response($data);
|
||||
@ -165,11 +178,44 @@ class PaymentApiController extends BaseAPIController
|
||||
*/
|
||||
$invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->first();
|
||||
|
||||
|
||||
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Delete(
|
||||
* path="/payments/{payment_id}",
|
||||
* summary="Delete a payment",
|
||||
* tags={"payment"},
|
||||
* @SWG\Parameter(
|
||||
* in="body",
|
||||
* name="body",
|
||||
* @SWG\Schema(ref="#/definitions/Payment")
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Delete payment",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Payment"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
|
||||
public function destroy($publicId)
|
||||
{
|
||||
$payment = Payment::scope($publicId)->withTrashed()->first();
|
||||
$invoice = Invoice::scope($payment->invoice->public_id)->first();
|
||||
|
||||
$this->paymentRepo->delete($payment);
|
||||
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Payment', 'invoice_id', 'id');
|
||||
return $this->hasMany('App\Models\Payment', 'invoice_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function recurring_invoice()
|
||||
|
Loading…
x
Reference in New Issue
Block a user